Take the 2-minute tour ×
Android Enthusiasts Stack Exchange is a question and answer site for enthusiasts and power users of the Android operating system. It's 100% free, no registration required.

When connecting my pc to android wifi hotspot, It assigned a 192.168.42.x address to my pc. I really need to change this as it conflicts with one of our work subnets - is this possible?

share|improve this question
    
My mobile is rooted. I don't mind changing system files if required. –  sam Jun 4 '13 at 5:20
add comment

2 Answers

Unfortunately, there is no way to change the IP address range for the builtin tethering support, even in CyanogenMod. The Wi-Fi hotspot IP is hardcoded in android.net.wifi.WifiStateMachine.startTethering(); the USB tethering IP is hardcoded in com.android.server.connectivity.Tethering.

However, if your phone is rooted, you can try using third-party apps for tethering which have the option to change the IP address range. E.g., when the builtin USB tethering was broken in CyanogenMod alphas for Samsung Galaxy W, I used Wired Tether for Root Users, which has such option. For Wi-Fi tethering you can try the Wireless Tether for Root Users app from the same authors, which also has the option to change the IP address range.

share|improve this answer
    
+1 for the info. My device is rooted, but Wireless Tether for Root Users app is not working on my mobile. There should be some way to change the IP range on the rooted phone, C'Mon Man!, Android is an open OS after all. –  sam Jun 4 '13 at 5:18
add comment

The Android builtin wifi tethering is designed to use 192.168.43.1/24 as the server, with netd handling the tethering, using dnsmasq. First DNS range is 192.168.42.1-254 and and 2nd DNS range is 192.168.43.1-254.

Netd is not easy to change. It requires a socket to communicate with it, and that socket is taken when android starts tethering. But going through the source files for Tethering.java (I used Froyo) we see:

// usb client will be provided 192.168.42.129
private static final String USB_NEAR_IFACE_ADDR      = "192.168.42.129";
private static final String USB_NETMASK              = "255.255.255.0";

// FYI - the default wifi is 192.168.43.1 and 255.255.255.0

private String[] mDhcpRange;
private static final String DHCP_DEFAULT_RANGE1_START = "192.168.42.2";
private static final String DHCP_DEFAULT_RANGE1_STOP  = "192.168.42.254";
private static final String DHCP_DEFAULT_RANGE2_START = "192.168.43.2";
private static final String DHCP_DEFAULT_RANGE2_STOP  = "192.168.43.254";

And Later on we see those ranges used, AS BACKUPS.

    mDhcpRange = context.getResources().getStringArray(
            com.android.internal.R.array.config_tether_dhcp_range);
    if ((mDhcpRange.length == 0) || (mDhcpRange.length % 2 ==1)) {
        mDhcpRange = new String[4];
        mDhcpRange[0] = DHCP_DEFAULT_RANGE1_START;
        mDhcpRange[1] = DHCP_DEFAULT_RANGE1_STOP;
        mDhcpRange[2] = DHCP_DEFAULT_RANGE2_START;
        mDhcpRange[3] = DHCP_DEFAULT_RANGE2_STOP;
    }

The main source for the dhcp ranges is not the hardcoded 42 and 43, but read from array.config_tether_dhcp_range, an internal string array. But it is currently empty.

You could edit the android framework. On my phone, it is /system/framework/framework-res.apk. There are a ton of tutorials online for editing framework-res.apk, from simple strings to full theming. Find one for your phone and android version.

Main thing you want to change is the /res/values/arrays.xml

Look for <array name="config_tether_dhcp_range" />

Change to:

<string-array name="config_tether_dhcp_range">
     <item>192.168.x.y</item>
     <item>192.168.x.z</item>
</string-array>

compile/zip/sign as needed (follow a tutorial), then reinstall.

If you want more than one range, just copy the two items over and over. You always need to provide a start and a stop for each range. Try to keep it in the same /24, ie 192.168.50.5 and 192.168.50.99 or whatever. You can confirm it is working with busybox ps | grep dnsmasq or if you don't have busybox ps dnsmasq then use the pid in cat /proc/pid/cmdline. You should get (or similar):

/system/bin/dnsmasq --no-daemon --no-poll -no-resolv --dhcp-range=192.168.50.5,192.168.50.99,1h

FWIW, my WIFI tethering uses the default dnsmasq ranges, yet my computer was assigned 192.168.43.147/24 and gateway 192.168.43.1/24. Not sure why yours defaulted to a 42.x address.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.