RedHat 6.x / CentOS 6.x: Configure DHCP client

0

Setting Up a CentOS / Red Hat Linux DHCP Client

First backup your existing network configuration. I assume for all below that the interface is eth0, if this is not the case on your system then edit accordingly.

cp /etc/sysconfig/network-scripts/ifcfg-eth0 /root/ifcfg-eth0.bak

Do not store the backup in the original directory, it will cause some issues.
Then we edit the file

vi /etc/sysconfig/network-scripts/ifcfg-eth0

Following is a sample DHCP configuration:

DEVICE="eth0"
BOOTPROTO="dhcp"
HWADDR="7E:E2:2F:FC:64:FC"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="10489fa0-ea13-40c6-b3e9-19ae328c7162"

This would be a sample static configuration:

DEVICE="eth0"
BOOTPROTO="static"
HWADDR="7E:E2:2F:FC:64:FC"
IPADDR=192.168.1.2
NETMASK=255.255.255.0
DNS=192.168.1.1
GATEWAY=192.168.1.1
ONBOOT="yes"
TYPE="Ethernet"
UUID="10489fa0-ea13-40c6-b3e9-19ae328c7162"
NM_CONTROLLED="no"

Leave vi with Shift+ZZ

Just for completeness the DNS is set in the /etc/resolv.conf

vi /etc/resolv.conf

insert

nameserver 192.168.1.1

and restart the network service:

 service network restart

Please note that you need a configuration file for each device that you want to configure.

Leave a Reply