08 June 2013

How to setup CentOS to work with external DHCP

Last week I had to setup a CentOS 5.5 machine that relied on external DHCP for IP configuration. The default network configuration was:

[root@nhsrv1 /]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=(mac omitted)
ONBOOT=yes
TYPE=Ethernet

Unfortunately the other machines in the network were not able to ping it over host name, but only by IP address. After quick investigation, the solution was found – the last line had to be added to the ifcfg-eth0:

[root@nhsrv1 /]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=(mac omitted)
ONBOOT=yes
TYPE=Ethernet
DHCP_HOSTNAME=nhsrv1
and then restart the configuration:

[root@nhsrv1 /]# /etc/init.d/network restart

Apparently some DHCP servers require the client to specify a hostname before receiving an IP address. And here is the official CentOS page about DHCP_HOSTNAME.

The above is also valid for CentOS 6.

No comments: