Step by step Linux DHCP server configuration in Redhat / Centos / Fedora

In this article we will cover a very interesting and important topic, i.e. H. The Linux DHCP server configuration. Linux DHCP Server stands for Dynamic Host Configuration Protocol is used to dynamically OR automatically provide the IP address to client computers. The port number of the DHCP server is 67 and the port number of the DHCP client is 68.

Centos / Fedora” src=”data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″ data-src=”” alt=”Step by step Linux DHCP server configuration in Redhat / Centos / Fedora” width=”783″ height=”438″ data-srcset=” 783w,×430.png 768w” data-sizes=”(max-width: 783px) 100vw, 783px”>

Step by step Linux DHCP server configuration in Redhat / Centos / Fedora

Where should we use DHCP servers?

Suppose we have a small office with three computers and a router. The router’s IP address is and we are assigned the IP address so that three computers are left. In this case, we can manually assign IP addresses to each computer. Imagine working on an extensive setup with thousands of client computers, multiple network printers and so many other network devices. In such situations, it is simply impossible to manually assign IP addresses. In such a situation, we need a Linux DHCP server. The DHCP server dynamically or automatically assigns the IP address to all systems and devices.

How does the DHCP server work? OR What is DORA Process?

  1. If a new system is connected to the network, the first step is to look for a DHCP server in the network and if it does not find an IP address, the system sends a DHCP detection message to all devices that are connected to the network. This process is called broadcasting.
  2. When the DHCP server receives the DHCP detection message from the client computer, the DHCP server offers all connected devices an IP address (e.g. and sends this via broadcast.
  3. When the client computer now receives the IP address, it sends a request on the network that it accepts the IP address.
  4. The DHCP server then confirms the IP address that the client computer can now use. This is how Linux DHCP Server works. This whole process is called DORA (Discover Offer Request Acknowledgment).

Like other services such as BIND DNS Server and NFS Server, DHCP is also a server and client type. So here, too, we need a server and a client to configure the DHCP server. Details on DHCP servers and clients are listed below:

DHCP Server Details:

Server Name: dhcpserverIP address : address :

DHCP Client Details:

Host Name: client1MAC address :

Important parameters of the Linux DHCP server

  • Domain name option: Mention the domain name e.g .:
  • Domain name server option: Mention DNS servers e.g:, (Note: You can also specify the fully qualified domain name (FQDN).
  • Default lease time: The default time in seconds to when the DHCP server assigns an IP to the client computer.
  • max-lease-time: The maximum time in seconds until the DHCP server assigns an IP to the client computer.
  • subnet: Mention the subnet’s IP address e.g .:
  • Network mask: Mention the subnet mask e.g .:
  • Offer: Mention the IP range that is dynamically assigned to client computers by the Linux DHCP server. e.g .: to
  • Router option: Mention the gateway IP address e.g .:
  • Broadcast address option: Mention your broadcast address e.g .:
  • Hardware Ethernet: Mention your MAC access OR your physical address e.g .: 00: 0C: 29: F7: BE: 27
  • Hostname option: Your system’s hostname OR computer name e.g .: dhcpserver

Follow the steps below to gradually configure the Linux DHCP server in Redhat / Centos / Fedora:

Step: 1 Prepare your server before configuring the DHCP server

Before we start configuring the DHCP server, we need to prepare our server for it.

First assign a static IP address to your server. See the following command.

[[email protected] ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0   # Set Static IP Address

Give your server a correct host name. Here is my server’s hostname dhcpserver,

[[email protected] ~]# hostname   # Checking Hostname

Step: 2 Install the required packages

Install the necessary packages and dependencies for Linux DHCP Server.

[[email protected] ~]# yum -y install dhcp*  # Install Linux DHCP Server Package
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base:
 * extras:
 * updates:
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package dhcp.x86_64 12:4.1.1-53.P1.el6.centos will be installed
---> Package dhcp-common.x86_64 12:4.1.1-38.P1.el6.centos will be updated
--> Processing Dependency: dhcp-common = 12:4.1.1-38.P1.el6.centos for package: 12:dhclient-4.1.1-38.P1.el6.centos.x86_64
---> Package dhcp-common.x86_64 12:4.1.1-53.P1.el6.centos will be an update
---> Package dhcp-devel.x86_64 12:4.1.1-53.P1.el6.centos will be installed
--> Running transaction check
---> Package dhclient.x86_64 12:4.1.1-38.P1.el6.centos will be updated
---> Package dhclient.x86_64 12:4.1.1-53.P1.el6.centos will be an update
--> Finished Dependency Resolution

Dependencies Resolved

 Package                              Arch                            Version                                             Repository                     Size
 dhcp                                 x86_64                          12:4.1.1-53.P1.el6.centos                           base                          823 k
 dhcp-devel                           x86_64                          12:4.1.1-53.P1.el6.centos                           base                          158 k
 dhcp-common                          x86_64                          12:4.1.1-53.P1.el6.centos                           base                          144 k
Updating for dependencies:
 dhclient                             x86_64                          12:4.1.1-53.P1.el6.centos                           base                          322 k

Transaction Summary
Install       2 Package(s)
Upgrade       2 Package(s)

Total download size: 1.4 M
Downloading Packages:
(1/4): dhclient-4.1.1-53.P1.el6.centos.x86_64.rpm                                                                                      | 322 kB     00:00     
(2/4): dhcp-4.1.1-53.P1.el6.centos.x86_64.rpm                                                                                          | 823 kB     00:00     
(3/4): dhcp-common-4.1.1-53.P1.el6.centos.x86_64.rpm                                                                                   | 144 kB     00:00     
(4/4): dhcp-devel-4.1.1-53.P1.el6.centos.x86_64.rpm                                                                                    | 158 kB     00:00     
Total                                                                                                                         954 kB/s | 1.4 MB     00:01     
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Importing GPG key 0xC105B9DE:
 Userid : CentOS-6 Key (CentOS 6 Official Signing Key) 
 Package: centos-release-6-5.el6.centos.11.1.x86_64 (@anaconda-CentOS-201311272149.x86_64/6.5)
 From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating   : 12:dhcp-common-4.1.1-53.P1.el6.centos.x86_64                                                                                               1/6 
  Installing : 12:dhcp-4.1.1-53.P1.el6.centos.x86_64                                                                                                      2/6 
  Installing : 12:dhcp-devel-4.1.1-53.P1.el6.centos.x86_64                                                                                                3/6 
  Updating   : 12:dhclient-4.1.1-53.P1.el6.centos.x86_64                                                                                                  4/6 
  Cleanup    : 12:dhclient-4.1.1-38.P1.el6.centos.x86_64                                                                                                  5/6 
  Cleanup    : 12:dhcp-common-4.1.1-38.P1.el6.centos.x86_64                                                                                               6/6 
  Verifying  : 12:dhcp-common-4.1.1-53.P1.el6.centos.x86_64                                                                                               1/6 
  Verifying  : 12:dhcp-devel-4.1.1-53.P1.el6.centos.x86_64                                                                                                2/6 
  Verifying  : 12:dhcp-4.1.1-53.P1.el6.centos.x86_64                                                                                                      3/6 
  Verifying  : 12:dhclient-4.1.1-53.P1.el6.centos.x86_64                                                                                                  4/6 
  Verifying  : 12:dhcp-common-4.1.1-38.P1.el6.centos.x86_64                                                                                               5/6 
  Verifying  : 12:dhclient-4.1.1-38.P1.el6.centos.x86_64                                                                                                  6/6 

  dhcp.x86_64 12:4.1.1-53.P1.el6.centos                                      dhcp-devel.x86_64 12:4.1.1-53.P1.el6.centos                                     

  dhcp-common.x86_64 12:4.1.1-53.P1.el6.centos                                                                                                                

Dependency Updated:
  dhclient.x86_64 12:4.1.1-53.P1.el6.centos                                                                                                                   


You can use the following command to check whether packages have been installed correctly or not.

[[email protected] ~]# rpm -qa | grep dhcp   # Confirm the Installed DHCP Server Package

After installation, check the installation directory of the Linux DHCP server and the path of all configuration files. We can do this with the following command.

[[email protected] ~]# rpm -ql dhcp   # Check the Path of Installation Directories and Configuration Files
/etc/dhcp   # Installation Directory
/etc/dhcp/dhcpd.conf   # Main Configuration file of DHCP Server
/usr/sbin/dhcpd   # Binary Files
/var/lib/dhcpd/dhcpd.leases   # Linux DHCP Server Lease File

So the installation directory of DHCP Server is / etc / dhcp and is the main configuration file of Linux DHCP Server dhcpd.conf, By default, the dhcpd.conf file looks like this. As you can see below, there is a message for us that we can copy the sample file dhcpd.conf / usr / share / doc / dhcp * Directory.

[[email protected] ~]# cat /etc/dhcp/dhcpd.conf    
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample
#   see 'man 5 dhcpd.conf'

Step: 3 Prepare the configuration file

So let’s go ahead and copy that dhcpd.conf.sample File as dhcpd.conf, The system prompts to overwrite because we already have the file dhcpd.conf in the path / etc / dhcp. So just come in Yes and press Enter to continue copying.

[[email protected] ~]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf 
cp: overwrite `/etc/dhcp/dhcpd.conf'? yes

Step: 4 Configure the Linux DHCP server

Now let’s configure the Linux DHCP server. Just edit that / etc / dhcp / dhcpd / conf File with your favorite text editor.

The configurations shown below are global variables and apply to all subnets that we declare in the dhcpd.conf file. Simply edit the configuration file and make the changes according to your scenario.

option domain-name "";   
option domain-name-servers,;

default-lease-time 600;
max-lease-time 7200;

# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.

Then declare a subnet according to your network scenario. Here I take the IP address from 192.168.0 and subnet as

Example output:

subnet netmask {
  range;   # IP Address Range
  option domain-name-servers,;   # DNS Servers
  option domain-name "";   # Domain Name
  option routers;   # Gateway Address
  option broadcast-address;
  default-lease-time 600;
  max-lease-time 7200;

Where :

The range applies to the permissible IP address range, i. H. to, The DHCP server assigns an IP address to the client computers in this area. And other settings are common, such as the domain name, the router address, i.e. H. The gateway address, the DNS server, etc., which I have already explained above.

After making any necessary changes to the dhcpd.conf configuration file, the Linux DHCP server service is started with the following command.

[[email protected] ~]# /etc/init.d/dhcpd start   # Start the DHCP Server Service
Starting dhcpd:                                            [  OK  ]

Configure the DHCP service to start at system startup.

[[email protected] ~]# chkconfig --level 35 dhcpd on   # Start DHCP Service at Startup

[[email protected] ~]# chkconfig --list dhcpd   # Confirm the Startup Configuration
dhcpd           0:off   1:off   2:off   3:on      4:off   5:on      6:off

DHCP client side configuration

Configure the Ethernet connection from the client to get the IP address from the DHCP server. Simply edit the ifcfg-ethX store and adjust BOOTPROTO = dhcp (Highlighted in red). See the following sample output.

Note: Replace X with your ethernet connection number

[[email protected] ~]# nano /etc/sysconfig/network-scripts/ifcfg-eth1  # Configure Ethernet Connection


Then restart the network service with the following command.

[[email protected] ~]# /etc/init.d/network restart  # Restart the Network Service

After the restart, the network service system receives the IP address from the Linux DHCP server. To confirm the same, we can use ifconfig Command to check the IP address. See the following command.

[[email protected] ~]# ifconfig eth1
eth1      Link encap:Ethernet  HWaddr 00:0C:29:F7:BE:27  
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::20c:29ff:fef7:be27/64 Scope:Link
          RX packets:39 errors:0 dropped:0 overruns:0 frame:0
          TX packets:121 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:5184 (5.0 KiB)  TX bytes:7917 (7.7 KiB)

As soon as the client receives an IP address from the DHCP server, you can see all client information such as the assigned IP address, MAC address and the name of the client computer /var/lib/dhcpd.leases Server.

Note : Leasing information for IP addresses is stored in /var/lib/dhcpd.leases File. By default, it is supplied with the installation of the DHCP server package. If this is not the case, you have to create it manually, otherwise you will not be able to start the DHCP service.

[[email protected] ~]# cat /var/lib/dhcpd/dhcpd.leases   # Checking the dhcpd.leases file
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-4.1.1-P1

server-duid "00010001 275v2610014)Aj256";

lease {
  starts 0 2017/05/28 12:02:32;
  ends 0 2017/05/28 12:12:32;
  cltt 0 2017/05/28 12:02:32;
  binding state active;
  next binding state free;
  hardware ethernet 00:0c:29:f7:be:27;
  client-hostname "client1";

Extended functions in Linux DHCP Server

Another useful feature that you can configure in Linux DHCP Server is to reserve the IP address for a specific user using their MAC address (physical address). Usually, the DHCP server gives the client an IP address for a certain time. When you restart the system, DHCP may assign a different IP address.

The advantage of IP reservation is that the IP address never changes. In this case, suppose you have a network printer that is configured in so many client systems. If your IP address changes frequently, users cannot use the printer. To avoid this, you need to reserve an IP address for this printer in Linux DHCP Server.

Here I have reserved an IP address for one of my client computers, i. H. client1, See the following sample output.

### host declaration ###

host client1 {
        option host-name "client1";   # Hostname of the Client Computer
        hardware ethernet 00:0c:29:f7:be:27;   # MAC Address of the Client Computer
        fixed-address;   # IP Address You want to assign to that Client

After making the necessary changes, restart the DHCP service for the changes to take effect.

[[email protected] ~]# /etc/init.d/dhcpd restart   # Restart the DHCP Service
Shutting down dhcpd:                                       [  OK  ]
Starting dhcpd:                                            [  OK  ]

Then restart the network service from the DHCP client and you will receive the reserved IP address. See the following sample output.

[[email protected] ~]# ifconfig eth1
eth1      Link encap:Ethernet  HWaddr 00:0C:29:F7:BE:27  
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::20c:29ff:fef7:be27/64 Scope:Link
          RX packets:56 errors:0 dropped:0 overruns:0 frame:0
          TX packets:174 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:8534 (8.3 KiB)  TX bytes:11943 (11.6 KiB)

Here I mentioned my dhcpd.conf configured file for your reference.

# Configure Global Variables which are common for all Declared Subnets & will applied to all Subnets

option domain-name "";
option domain-name-servers,;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;

# Declare a Subnet with IP Range

subnet netmask {
  option domain-name-servers,;
  option domain-name "";
  option routers;
  option broadcast-address;
  default-lease-time 600;
  max-lease-time 7200;

# Host Declaration for IP Address Reservation

host client1 {
        option host-name "client1"; 
        hardware ethernet 00:0c:29:f7:be:27;

Read also – How to configure vsftpd Linux FTP server in Redhat / Centos / Fedora

That’s all. In this article we have explained step by step Linux DHCP server configuration In Redhat / Centos / Fedora. I hope you like this article. If you like this article, just share it. If you have any questions about this article, please comment.