I am connecting to my WiFi network from adb shell using the following command:

iw dev wlan1 connect -w WiFi-AP

There is a DHCP server running on the AP as well, but whenever I try to get IP address using dhclient -v wlan1, I get the following error:

sh: dhclient: not found

Is there a way to install dhclient on Android 8.1, or is there any other way to request IP address from the DHCP server over a wlan interface?

  • Android used dhcpcd up to Lollipop (or KitKat?). Now the client runs as a service inside Java runtime. No native tool available. You can build a static DHCP client binary from source. – Irfan Latif Jul 16 '19 at 12:37
  • @IrfanLatif: Any pointers on how to start with that would be highly appreciated. – M Asad Jul 18 '19 at 9:52
  • Building dhcpcd isn't that much complicated, but it won't be of any use. Linux distributions have simpler network configuration, usually use main routing table and /etc/resolv.conf for DNS. Android has a dynamic routing policy, containing scores of rules and routes, continuously updated by netd with network changes. Plus Android's Bionic libc doesn't use /etc/resolv.conf. So even if dhcpcd gets you an IP and DNS nameserver from DHCP server, you still have to manually configure routing, NATing, forwarding etc. – Irfan Latif Jul 18 '19 at 13:23
  • @IrfanLatif: I have tried to use udhcpc from busybox and when I use it, it returns an IP address from DHCP, but doesn't assign it to the interface. Using some bash scripting, I can extract IP and assign manually to the interface. Did you mean the same by manually configuring? – M Asad Jul 18 '19 at 13:54
  • By manual configuration I mean IP address + rule + route + DNS + iptables rules (if any required). If this WiFi is the only network you are connecting to, then route auto added to main table may work. – Irfan Latif Jul 18 '19 at 14:03

Your Answer

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

Browse other questions tagged or ask your own question.