Learn How to Install and Configure DHCP Server on CentOS 7

In this tutorial we are going to learn how to install and configure DHCP Server on CentOS 7 Linux. At the end of this tutorial you should be able to configure your CentOS 7 server as a DHCP server and issue dynamic IP Address to the client Computers on your network.

Following are the steps we are going to follow.

  • Install dhcp on CentOS 7 using yum command
  • Configure CentOS dhcp Server
  • Start and enable the dhcpd service.
Step One

Install DHCP Server on CentOS 7

To setup dhcp server on CentOS 7, we need to install dhcp package. we can install dhcp on CentOS 7 using yum install command.

yum install dhcp

Install and Configure DHCP Server on CentOS 7 Linux
Step Two

Configure DHCP Server

CentOS 7 dhcp main configuration file is /etc/dhcp/dhcpd.conf file, which is empty by default. We need to add dhcp server configuration to the dhcpd.conf file before we start the service.

For this example we are going to configure dhcp server for the 192.168.0.0/24 network.

So open the /etc/dhcp/dhcpd.conf file with a text editor and add following configuration.

subnet 192.168.0.0 netmask 255.255.255.0 {

range 192.168.0.200 192.168.0.230;

option routers 192.168.0.1;

option domain-name-servers 8.8.8.8, 8.8.4.4;

default-lease-time 600;

max-lease-time 7200;

}

As per the above configuration,

  • range 192.168.0.200 192.168.0.230 tells the dhcp server to assign ip address between 192.168.0.200 and 192.168.0.230 to the clients.
  • option routers 192.168.0.1 - dhcp clients will use 192.168.0.1 as their default gateway.
  • option domain-name-servers 8.8.8.8, 8.8.4.4 - clients will use 8.8.8.8 and 8.8.4.4 as their dns name servers.
  • Default-lease-time and max-lease-time specify the ip lease time in seconds.
Step Three

Start the DHCP Server

Now we need to start the dhcpd service (dhcp daemon) using systemctl command.

systemctl start dhcpd

Also enable the dhcp server to start at system reboot

systemctl enable dhcpd.service

Once you start the dhcp service, clients on your network will get the IP addresses within the range we specified.

Assign Fixed IP Addresses for the specific host

CentOS 7 dhcp server can also assign fixed IP Addresses to the client's based on the Ethernet hardware address using host block.
Example

subnet 192.168.0.0 netmask 255.255.255.0 {

range 192.168.0.200 192.168.0.230;

option routers 192.168.0.1;

option domain-name-servers 8.8.8.8, 8.8.4.4;

option domain-name "internal.example.org";

default-lease-time 600;

max-lease-time 7200;

 

host host1 {

hardware ethernet 08:00:27:f1:ba:f8;

fixed-address 192.168.0.60;

}

}

As per the above example, host with mac address 08:00:27:f1:ba:f8 will get the ip address 192.168.0.60. The Server will identify the host using the mac address of the network interface rather than the hostname of the client.

For more advanced configuration options you can refer to the man page of the dhcpd.conf file.

man 5 dhcpd.conf

In CentOS 7, There also sample dhcpd.conf file inside the /usr/share/doc/dhcp-4.2.5 folder (name of the folder dhcp-4.2.5 could be different depends on the dhcp server version).

Summary :

In this tutorial we learned how to install and configure dhcp server on Linux CentOS 7.
First, we installed dhcp on CentOS 7 using yum command

Then we add the configuration to the /etc/dhcp/dhcpd.conf file and start the centos dhcp service.