15
  • Does the dhcp client on Linux write any logs?
  • If not, can logs be enabled and how?
  • If it writes logs, where can they be found?
  • How does a typical log of a dhcp client look like when obtaining IP and nameservers from a DHCP server?
  • Where can I find the source code of the DHCP client?

In case there are relevant differences between Linuxes: I am interested in Debian 8.1 (default minimal installation amd64).

  • 1
    You'll need to be more specific than "the dhcp client on Linux". There are plenty of different dhcp clients for Linux and they all log different ways. There's probably a default one for Debian 8.1 though I can't remember what it is. – qasdfdsaq Jul 24 '15 at 10:58
  • Internet Systems Consortium DHCP Client 4.3.1 Copyright 2004-2014 Internet Systems Consortium. All rights reserved. For info, please visit isc.org/software/dhcp – Gustave Jul 24 '15 at 12:43
7

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
| improve this answer | |
  • 2
    On Debian 8.1 journalctl works, on ubuntu-14.04.2-server the entries are in /var/log/syslog. Thanks. But: there are only very few entries, for example only the IP adress is logged, the DNS servers are not. Is it possible to configure more verbose output? – Gustave Jul 28 '15 at 16:01
4

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)

| improve this answer | |
-3

Please find the answer inline.

  • Does the dhcp client on Linux write any logs?


    Yes, it does.

  • If not, can logs be enabled and how?


 1. Edit dhcpd.conf and add this line
  log-facility local7;

 2. Edit syslog.conf and append 
  local7.* /var/log/dhcpd.log

  • If it writes logs, where can they be found?

    /var/log/dhcpd.log


  • How does a typical log of a dhcp client look like when obtaining IP and nameservers from a DHCP server?


galaxy dhcpd: DHCPDISCOVER from 00:0d:62:d7:a0:12 via eth0
galaxy dhcpd: DHCPOFFER on 192.168.1.5 to 00:0d:62:d7:a0:12 via eth0
galaxy dhcpd: DHCPREQUEST for 192.168.1.5 (192.168.1.1) from 00:0d:62:d7:a0:12 via eth0
galaxy dhcpd: DHCPACK on 192.168.1.5 to 00:0d:62:d7:a0:12 via eth0

  • Where can I find the source code of the DHCP client?


    Link 1
    Link 2

| improve this answer | |
  • 2
    The OP is talking about DHCP client. DHCPD is DHCP server daemon. – Larssend Jul 24 '15 at 9:26
  • There seems to be no file named dhcpd.conf on my system. There is a file /etc/dhcp/dhclient.conf. There is no file syslog.conf, but a file /etc/rsyslog.conf. I made the configuration changes to those files, restarted rsyslog, shut down eth0, switched it on again. But no log file appears. I get some DHCP messages on the console. Even after a restart of the machine I get no log messages. – Gustave Jul 24 '15 at 12:13

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.