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.


Note: Adding / removing IP address requires root access.


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 an additional fixed IP address (within same subnet obviously):

~# ip address add dev wlan0

* Replace add with del to delete.

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


The problem with above approach is that the added IP is not permanent. Once you switch OFF the hotspot, IP will get cleared. So you can use an init trigger to set IP address whenever hotspot is turned ON. 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.
  • Service uses Magisk's SELinux context assuming that the device is rooted with Magisk.


dnsmasq starts listening on all IP addresses which are set on WiFi interface before dnsmasq is started. But with both above methods there is no way to make sure that IP is added after netd sets up the interface and before dnsmasq starts. So the added IP address may conflict 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).

To address this problem:

  • Reserve the manually added IP address by editing dnsmasq.conf. See How can I permanently assign a static IP address to Wi-Fi or USB tether clients?
  • Or modify DHCP IP range, but it's hard coded. You can replace dnsmasq with a shell script to achieve this. See How to change the default hotspot DHCP IP address range?
  • Or replace /system/bin/dnsmasq with a shell script which adds IP address before executing original dnsmasq binary. Rename dnsmasq to dnsmasq.bin and create script: /system/bin/dnsmasq:

    # set fixed IP address on Wi-Fi interface
    ip address add dev wlan0
    # execute original binary
    exec dnsmasq.bin $*
    • Set ownership, permission and SELinux context on both files. See this answer for details.
    • Additionally you may add listen-address= (5) to dnsmasq.conf.
    • Use ss or netstat to make sure that DHCP server is listening on reserved IP address (or on all IP addresses i.e. so that to avoid IP address collision.

NOTE that in order to modify .rc, dnsmasq or dnsmasq.conf files, /vendor and /system partitions need to be mounted R/W which requires dm-verity disabled. Otherwise you may use bind mounts (used by Magisk modules). On non-SAR devices /init.rc can also be edited to modify /init.rc file in ramdisk by unpacking boot.img.

  • 1
    I was able to set this up on a MotoG3 turbo with LineageOS 17.1 android-10.
    – kocj
    Feb 5 '21 at 16:35

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.