Hello and welcome guys, In this new and exciting tutorial/article we will learn step by step how to configure DHCP Server in Linux (Red Hat/ CentOS). We will do configuration by using configuration file.  This is used for enterprise network to reduce manual  IP configuration efforts (for instance it will take hours and hours to do ip configuration on 1000 systems).




What is DHCP Server

DHCP stands for Dynamic Host Configuration Protocol.
Network/Server/System Administrator designs and implements DHCP server to centrally manage and automate the process of assigning Internet Protocol (IP) in company/organization. DHCP has ability to assign IP automatically for the system as well as Subnet Mask, Gateway and DNS (if you have configured),
when system boots it gets the IP from DHCP. DHCP uses DORA process in backend. DHCP uses the concept of lease time or we can say the amount of time that given an IP address is valid for computer. The lease time may vary depending on the user to require internet connection with a specific location. It is useful in education sector or other environment where users change frequently.

DORA Stand for Discover Offer Request Acknowledgement.

DHCP Discover

When a client is configure with obtain automatic IP address, then the client PC searches for DHCP server. The UDP is broadcasted to discover the DHCP server.

Available IP address in the pool offered by DHCP Server and the Client PC waiting for the IP address.

DHCP Request

In the response of the offer, Client will request IP address.

DHCP Acknowledge

In the response to the request, DHCP server will respond with IP address, subnet mask, Gateway and DNS info along with the acknowledgement.

DHCP PORTS

DHCP client is running on the client machine. It begins broadcasting requests for configuration information. By default, these requests are listening on UDP port # 68. The server responds to client on UDP port # 67.

Installation of DHCP Server on CentOS / Red Hat 7

For installation of DHCP server by using command yum. Syntax yum install dhcp

[root@faraz ~]# yum install dhcp*

Loaded plugins: fastestmirror, langpacks, priorities

base                                                                        | 3.6 kB  00:00:00
epel/x86_64/metalink                                                        | 4.0 kB  00:00:00
epel                                                                        | 4.3 kB  00:00:00
extras                                                                      | 3.4 kB  00:00:00
updates                                                                     | 3.4 kB  00:00:00

(1/4): epel/x86_64/updateinfo                                               | 523 kB  00:00:02
(2/4): extras/7/x86_64/primary_db                                           | 101 kB  00:00:03
(3/4): epel/x86_64/primary_db                                               | 3.9 MB  00:00:08
(4/4): updates/7/x86_64/primary_db                                          | 3.2 MB  00:00:22

After installation you need to configure a static IP address for DHCP server in the DHCP range for the listening interface. (e.g. enp0s3 for latest version, eth0 for older versions)

Configure Server Interface (Network Interface Card) for DHCP

Open the file /etc/sysconfig/network-scripts/ifcfg-enp0s3 with insertion mode through vim tool and make the changes as per requirement. Here we go…..;

[root@faraz ~]# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3

TYPE=Ethernet
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.56.10
NETMASK=255.255.255.0

DHCP Configuration

Now we are going to configure our DHCP server, for configuration we need to go to the file which is in /etc/dhcp/dhcpd.conf. In this file we need to add some parameters for DHCP server configuration by defining IP range, route, domain name server, default and max lease time within subnet and netmask parameters.




[root@faraz ~]# vi /etc/dhcp/dhcpd.conf

# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#

subnet 192.168.56.0 netmask 255.255.255.0
{
range 192.168.56.50 192.168.56.100;
# DNS server IP or additional DNS server IP
#       option domain-name-servers 8.8.8.8, 8.8.4.4 (remove the [#] hash sign if you have domain server)
#Domin name
#       option domain-name shahid-academy.com
option broadcast-address 192.168.56.255;
#Gateway IP
option routers 192.168.56.1;
 
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
}

Reserve IP address with MAC

You can also reserve the IP address for printer or system/ Pc with MAC address in this regard add some parameter which is define in below example;

host myPC
{
hardware ethernet 00:00:00:00:00:00;
fixed-address 192.168.56.90;
}

Add rule for Firewall

If your system’s firewall in running position then you have two choices one is stop the service of firewall by using systemctl stop firewalld and the second one is to define the rule for the firewall by using below condition;

[root@faraz ~]# firewall-cmd --permanent --add-service=dhcp
[root@faraz ~]# firewall-cmd --reload

Service

Start the service by using command systemctl. Syntax systemctl start service – daemon – name

[root@faraz ~]# systemctl start dhcpd

You can start the service at the boot time by using enable option. Syntax systemctl enable service – daemon – name

[root@faraz ~]# systemctl enable dhcpd

Verification of DHCP Server Configuration

Finally you can verify whether you DHCP server configure accurately or not by using dhcpd configtest.

[root@faraz ~]# dhcpd configtest

 

In this tutorial/ article we have learnt how to configure DHCP server with reservation by adding firewall rule if firewall is running. I hope you like it and learn this practical knowledge. Let us know about your suggestions and problem through comment and subscribe our newsletter. Keep learning with us… 🙂

 

Thanks

SUBSCRIBE OUR NEWSLETTER
I agree to have my personal information transfered to MailChimp ( more information )
Join us by subscribing to our newsletter and learn IT subjects for free
We hate spam. Your email address will not be sold or shared with anyone else.