IP address is by default and there is no option to change it permanently. Is it possible to change it without root access?

My phone is Huawei Android 5.1.


Before Android Pie, tethering IP ( was hard-coded (1, 2). But now it's randomized on each session(3). You can use Android's builtin ip command to set a fixed IP address but it requires root access:

~# ip address add dev wlan0

* Replace add with del to delete.

Make sure the name of your Wi-Fi interface (wlan0 usually). Check with ip link or ls /sys/class/net.

Now there comes two problems:

  • You can set whatever IP address you want to use (within same subnet obviously). But it should not contradict with IP leased to another host (saved in /data/misc/dhcp/dnsmasq.leases) by DHCP server (dnsmasq up to Pie) from DHCP range ( to by default) (4). Since the range is hard coded, you either need to replace /system/bin/dnsmasq with a shell script to change --dhcp-range= (5) option before starting DHCP server. Or use /etc/dnsmasq.conf to assign fixed IP's only (6).
  • Also the IP change is not permanent. Once you switch of hotspot, IP will get cleared.

A simple solution to both of the above problems is to occupy the desired IP soon after tethering is turned ON. We can use an init trigger to achieve this. Add these lines to (/vendor)/etc/init/hostapd.android.rc file (or any .rc file under /etc/init/):

on property:init.svc.hostapd=running
    exec - -- /system/bin/sleep 2
    exec u:r:magisk:s0 -- /system/bin/ip address add dev wlan0

* hostapd is the system service which manages access points.

  • your answer is good .. but it needs more simplification and more details for those who is not familiar with the files and tools .... – mina nageh Jun 14 at 11:45
  • Well simply execute ip address add dev wlan0 in a terminal app or adb shell, and ignore the rest of complexities. – Irfan Latif Jun 14 at 12:15
  • i read about an app that can do so .... does it have problems ? i mean this or that app – mina nageh Jun 14 at 12:19
  • I never used that app, so can't comment. But the app is no more maintained, last commit was on Jul 21, 2013. – Irfan Latif Jun 14 at 13:19
  • ok no problem.. – mina nageh Jun 14 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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