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.
dnsmasq
is Android's DHCP/DNS server. You can configure it somewhat throughdnsmasq.conf
e.g. to permanently assign a static IP address to tethered clients, or through some hacks e.g. to permanently change hotspot tethering IP address or to change the default hotspot DHCP IP address range. – Irfan Latif Jun 06 '20 at 20:55