How to see what DHCP client does?
Solution 1:
ISC's DHCP client is usually called dhclient
in most Linux distributions. From man dhclient
:
The client normally prints no output during its startup sequence. It can be made to emit verbose messages displaying the startup sequence events until it has acquired an address by supplying the -v command line argument. In either case, the client logs messages using the syslog(3) facility.
There are two possible ways to read your system log. On most systems that use systemd, you have to use journalctl
, whereas cat /var/log/syslog
is valid for systems that still employ a traditional init system.
Therefore, if your system is using systemd's logging facility, you can use journalctl | grep -Ei 'dhcp'
to get DHCP client logs. Otherwise, enter cat /var/log/syslog | grep -Ei 'dhcp'
.
Here is what my DHCP client log typically looks like:
Jul 20 14:17:39 trueclient1 NetworkManager[2622]: <info> (wlan1): canceled DHCP transaction, DHCP client pid 3325
Jul 20 14:17:42 trueclient1 NetworkManager[2622]: <info> Activation (wlan1) Beginning DHCPv4 transaction (timeout in 45 seconds)
Jul 20 14:17:42 trueclient1 dhclient: Internet Systems Consortium DHCP Client 4.2.2
Jul 20 14:17:42 trueclient1 dhclient: For info, please visit https://www.isc.org/software/dhcp/
Jul 20 14:17:42 trueclient1 NetworkManager[2622]: <info> (wlan1): DHCPv4 state changed nbi -> preinit
Jul 20 14:17:42 trueclient1 dhclient: DHCPREQUEST on wlan1 to 255.255.255.255 port 67
Jul 20 14:17:42 trueclient1 dhclient: DHCPACK from 10.8.8.1
Jul 20 14:17:42 trueclient1 NetworkManager[2622]: <info> (wlan1): DHCPv4 state changed preinit -> reboot
Solution 2:
A hacky (but effective) way to debug dhclient on many Linux platforms is to enable bash tracing in /sbin/dhclient-script.
dhclient runs that script on most OS variants I've checked (RedHat, Debian, etc).
Simply adding -x
to the shebang (first line) in that script should enable tracing each line to console, eg:
#!/bin/bash -x
Then you can run, for example
dhclient -r #release lease
dhclient #re-acquire lease
And you should see lots of output, not only from dhclient-script, but from all the included .d
scripts in /etc/dhcp*.
The trace output should allow you to figure out what's happening and what decisions the code is making (reference the script itself when looking at the output).
You can usually deduce the inputs (eg parameters including IP, GATEWAY, etc) the script received from this output, but if not, you can temporarily add something like this to the script just before the exit:
env | logger -t dhclient-debugging
Then check your log after running dhclient (/var/log/messages or /var/log/syslog)