OSETC TECH

CentOS 7/RHEL7: How To Setup DHCP Client For Your System

How Do I set up DHCP client for one network interface to get IP Address from a DHcP server under CentOS 7 or RHEL 7 linux? How Do I modify the BOOTPROTO setting from Static or “Nome” to “DHcP” so that the network interface will get the ipaddress via a DHCP server. you will see that how to setup your centos 7 system as a DHCP Client.

​You firstly need to find which network interface you want to setup its as DHCP client, then edit its configuration file and changing the value of BOOTPROTO from “Static” or “None” To “DHCP“. Let’s start to setup DHcP Client through the following steps.

CentOS 7 Setup DHCP client


Step1# issue the following command to find the network interface name that you would like to set its as DHcP client, type:

ifconfig

or

ip addr

outputs:

[root@devops network-scripts]# ip addr

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

       valid_lft forever preferred_lft forever

    inet6 ::1/128 scope host 

       valid_lft forever preferred_lft forever

2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

    link/ether 08:00:27:ea:92:ea brd ff:ff:ff:ff:ff:ff

    inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic enp0s3

       valid_lft 69691sec preferred_lft 69691sec

    inet 10.0.2.16/24 brd 10.0.2.255 scope global secondary enp0s3:0

       valid_lft forever preferred_lft forever

    inet 10.0.2.17/24 brd 10.0.2.255 scope global secondary enp0s3:1

       valid_lft forever preferred_lft forever

    inet6 fe80::a00:27ff:feea:92ea/64 scope link 

       valid_lft forever preferred_lft forever

In the below steps ,we will set “enp0s3” network interface as DHCP client.

Step2# backup existing static netowrk interface configruation file, issue the following command:

cp /etc/sysconfig/network-scripts/ifcfg-enp0s3 /etc/sysconfig/network-scripts/ifcfg-enp0s3.bak

Step3# edit “/etc/sysconfig/network-scripts/ifcfg-enp0s3” configuration file via “vim” command:

vim /etc/sysconfig/network-scripts/ifcfg-enp0s3

The following content is current configuration:

HWADDR=08:00:27:32:D1:01

TYPE=Ethernet

BOOTPROTO=static

NAME=enp0s3

IPADDR=10.0.2.15

NETMASK=255.255.255.0

DEFROUTE=yes

PEERDNS=yes

PEERROUTES=yes

IPV4_FAILURE_FATAL=no

IPV6INIT=yes

IPV6_AUTOCONF=yes

IPV6_DEFROUTE=yes

IPV6_PEERDNS=yes

IPV6_PEERROUTES=yes

IPV6_FAILURE_FATAL=no

UUID=8d307f87-e025-46cc-87d8-4c4235375768

ONBOOT=no

Replace the above content with the following configuration:

HWADDR=08:00:27:32:D1:01

TYPE=Ethernet

BOOTPROTO=dhcp #=====>change this, removing Ip address and netmask

DEFROUTE=yes

PEERDNS=yes

PEERROUTES=yes

IPV4_FAILURE_FATAL=no

IPV6INIT=yes

IPV6_AUTOCONF=yes

IPV6_DEFROUTE=yes

IPV6_PEERDNS=yes

IPV6_PEERROUTES=yes

IPV6_FAILURE_FATAL=no

NAME=enp0s3

UUID=8d307f87-e025-46cc-87d8-4c4235375768

ONBOOT=no

Save and close above configuration file.

Step4# restart network service by running the following command so that the changes can take effect,type:

systemctl restart network.service