Android's dhcp server sucks kinda bad

I have a bit of a special use-case: I mostly use my android phone (google pixel 5a) as a router.

When travelling my laptop & other devices are just paired to my phone & it has a keyboard and a camera to be able to type or scan into wifi networks. It also has LTE, although I try to avoid that when possible.

I also carry around a GLInet portable router with me, although I haven't gotten around to configuring it in such a way that it's not always dead.

A couple hiccups with using my phone as my primary router:

DNS queries pulling from DHCP

Once upon a time, android just used dnsmasq for both it's DNS & DHCP. there are a bunch of old stackexchange posts outlining this relation and how modifying /etc/dnsmasq.conf (after running an adb remount) would do just about anything you'de want.

These days though, it looks like android ships it's own DHCP server implementation (ugh).

https://android.googlesource.com/platform/packages/modules/NetworkStack/+/8ba012e20f814ec45e592422fd6362fc40c4e588/src/android/net/dhcp/DhcpLeaseRepository.java

strace -p $(pgrep dnsmasq) -f & sleep 0.2; pkill -SIGHUP dnsmasq

https://medium.com/@IamCOD3X/understanding-and-resolving-selinux-denials-on-android-ca3cee3719b6

for some reason reads on /tmp/* dirs/files would fail even with the proper permissioning. grr selinux(?)

Pointing addn-hosts=/data/misc/dhcp/hosts seems to work, though

dhcp-leasefile=/data/misc/dhcp/leases does not though. probably because it's not running a dhcp server

SIGHUP seems to refresh the listings

also:

--hostsdir=<path>
    Read all the hosts files contained in the directory. New or changed files are read automatically and modified and deleted files have removed records automatically deleted.

unfortunately, my version of dnsmasq doesn't support the directory flags :(

looks like we're stuck with a host file & SIGHUP

IDhcpEventCallbacks > startwithcallbacks :eyes:

makeDhcpServer

where does the dhcpserver get created???

Self-directed DNS

I want to connect to local devices via name from my phone on my wlan

https://source.android.com/docs/core/ota/modular-system/dns-resolver

adb server binding interface


https://man.archlinux.org/man/dnsmasq.8

https://linux.die.net/man/5/dhcpd.leases

https://serverfault.com/a/786141

https://android.stackexchange.com/questions/215856/how-to-ping-a-local-network-host-by-hostname/215878#215878

https://android.googlesource.com/platform/packages/modules/NetworkStack/+/8ba012e20f814ec45e592422fd6362fc40c4e588/src/android/net/dhcp/DhcpServingParams.java

https://android.stackexchange.com/questions/236023/how-do-i-force-a-new-dhcp-ip-address-on-my-android

https://android.stackexchange.com/questions/201024/how-to-use-wi-fi-and-hotspot-at-the-same-time-on-android/202335#202335

https://android.stackexchange.com/questions/232041/hosting-a-hotspot-without-signaling-metered-connection#comment305627_232041

https://android.stackexchange.com/a/214072

https://jpmens.net/2013/10/21/tracking-dhcp-leases-with-dnsmasq/

https://medium.com/moqume/poor-mans-device-discovery-dns-492a95ea8c8b

https://ncrmnt.org/tag/dnsmasq/

https://ncrmnt.org/2012/06/27/making-android-hotspot-mode-usable/

https://ncrmnt.org/2013/04/10/android-and-dnsmasq-making-a-better-dnsmasq-wrapper/

https://github.com/CPScript/Termux-Hotspot