CentOS eth0 DHCP troubleshooting

1. ifconfig eth0
Code:

  /sbin/ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:0C:76:E2:71:C5
          inet addr:192.168.1.xxx  Bcast:192.168.1.xxx  Mask:255.255.255.0
          inet6 addr: fe80::xxx:76ff:fee2:71c5/64 Scope:Link
          UP BROADCAST NOTRAILERS RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:593541 errors:0 dropped:0 overruns:0 frame:0
          TX packets:386699 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:88323609 (84.2 Mb)  TX bytes:487001350 (464.4 Mb)
          Interrupt:10 Base address:0xcf00

2. dhclient eth0
Code:

/sbin/dhclient eth0
Internet Systems Consortium DHCP Client V3.0.5-RedHat
Copyright 2004-2006 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/

/sbin/dhclient-script: configuration for eth0 not found. Continuing with defaults.
/etc/sysconfig/network-scripts/network-functions: line 78: eth0: No such file or directory
SIOCSIFADDR: No such device
eth0: unknown interface: No such device
eth0: unknown interface: No such device
Failed to get interface index: No such device

3. ethtool eth0 („ethtool“ is generally preferred over „mii-tool“):
Code:

/usr/sbin/ethtool eth0
Settings for eth0:
        Supported ports: [ TP MII ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
        Advertised auto-negotiation: Yes
        Speed: 100Mb/s
        Duplex: Full
        Port: MII
        PHYAD: 32
        Transceiver: internal
        Auto-negotiation: on
        Supports Wake-on: pumbg
        Wake-on: d
        Current message level: 0x00000007 (7)
        Link detected: yes

4. less /var/log/messages
<= Cut/paste any messages related to the failed DHCP request(s)

… and, most importantly …

5. dhcpcd -r
Code:

/sbin/dhcpcd -r
****  /sbin/dhcpcd: already running
****  /sbin/dhcpcd: if not then delete /var/run//dhcpcd-eth0.pid file

Enable firewall port 67:68

$IPTABLES  -I INPUT -i $LAN_IFACE -p udp --dport 67:68 --sport \      67:68 -j ACCEPT


iptables -L

Interesting

https://www.centos.org/forums/viewtopic.php?t=8653

even more interestingg
https://superuser.com/questions/944687/how-to-see-what-dhcp-client-does


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 prein


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)

http://web.mit.edu/rhel-doc/5/RHEL-5-manual/Deployment_Guide-en-US/s1-dhcp-configuring-client.html

https://www.tecmint.com/install-dhcp-server-client-on-centos-ubuntu/
Jan D.
Jan D.

"The only real security that a man will have in this world is a reserve of knowledge, experience, and ability."

Articles: 675

Leave a Reply

Vaše e-mailová adresa nebude zveřejněna. Vyžadované informace jsou označeny *