Install And Configure DHCP Server in Linux/CentOS
linux dhcp server

Install And Configure DHCP Server in Linux/CentOS

In this tutorial, we learn about the Linux DHCP Server step by step. As we all know, every computer requires an IP address to connect to the network, In small networks, it is not a problem to assign manually IP address to every computer,

but when working with tens or hundreds of network devices, one has to be very careful, in order not to make mistakes. To make things easier, we could delegate this task to the DHCP server.

What DHCP does is essentially provide IP addresses to all network devices. In fact, not only can it provide IP addresses, but also parameters, such as default gateway, DNS server, etc.

How DHCP Server Works

when the DHCP client boots up, it sends a DHCP to discover a message to all the network-connected machines. By this means, it tries to find an available DHCP server.
If there are one (or more) DHCP servers in the network, it will answer back with a DHCP offer message. When the client receives one of these DHCP offer messages,

it will send back a DHCP request to the server. The server, in turn, replies with a DHCP acknowledge message, and the address is assigned.

Bellow Image Explain About the DORA ( Discover, Offer, Request, Acknowledge)

Check IP Address in DHCP Server

First, provide a Static IP address to the DHCP server. Check Static IP Address in your computer follow bellow Image. we have set 192.168.43.74 IP in DHCP server

Install DHCP Package:

Before installing the package of the DHCP server, check the status of the DHCP package in the system. You can check the package with the help of below-given command.

[root@simi ~ ]# dnf  list --installed |grep dhcp-server
Check DHCP Package Install Or NOT
Displaying Install DHCP Package In CentOS 8

If DHCP package is not installed in your system then now you have to install DHCP package

dnf install dhcp-server
Install DHCP Package

After successfully installing the DHCP package on your server. Now you open the DHCP server main configuration file /etc/dhcp/dhcpd.conf file remains empty, Now we can write the configuration code of dhcp in the file or overwrite the file form.

The easiest way to configure a new DHCP server is probably to overwrite the default (empty) configuration file with /usr/share/doc/dhcp-server/dhcp.conf.example files.

[root@simi ~]# cp /usr/share/doc/dhcp-server/dhcp.conf.exampe /etc/dhcp/dhcpd.conf
Over Write Configure File From /usr/share/doc/dhcp-server/dhcp.conf.exampe

This is the main configuration file of the server. This file needs to be edited to create a DHCP server. You can use any text editor to edit the server’s main configuration file.

Edit Server configuration file

 [root@simi ~]# vim /etc/dhcp/dhcpd.conf
 DHCP Main Configuration File.

after successfully configure configuration file then save and exit

Option domain-name: Enter the domain name of your server.

option domain-name-servers: Enter the DNS Server name OR IP of your server.

Lease time: the DHCP server will reserve the IP address for at least 600 seconds (default-lease-time) and at max 7200 seconds (max-lease-time) for Particulter Device, Other common values would be 86400 (one day), 604800 (one week), and 2592000 (30 days).

Start, Enable and check the DHCP Server Services

After successfully editing the DHCP server main configuration file, start its service and also check the status of the service.

systemctl start dhcpd
systemctl enable dhcpd
systemctl status dhcpd

Firewall setting

If the firewall services are running in your system then allow DHCP service uses port number 67

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

Configure DHCP Client

After successfully configuring the DHCP server, follow the below steps to get the IP address in the client machine

First Install DHCP-client packages if the package is not installed (generally installed by default).

[root@simi ~]#dnf install dhcp-client -y

To change the network connection type nmtui command in Terminal the Bellow screen displayed.

[root@simi ~]#nmtui

Clicking on the Edit a connection with the help of the keyboard Navigation Key and Press Enter.

Click ON enp0s3 and Hit Enter

NOTE enp0s3 is the name of your system’s network card, it may have a different name in your system

Select Automatic as shown in the screen below

With the help of keyboard click on ok option

Check IP Address Get from DHCP Server

In this way, the client PC will get the IP address from the DHCP server with the help of a command line.

addr show enp0s3
nmcli connection modify enp0s3 ipv4.mathod auto
nmcli connection down enp0s3
nmcli connection enp0s3

Configure DHCP Client on Windows computer.

In this process, we will talk about how to receive IP Addresses from the DHCP server in the Windows client computer.

Open the network settings and select Internet Protocol Version 4 (RCP/IPv4) and Click On Properties Button

Check mark In Obtain IP Address Automatically and Click On OK.

Now Got The IP Address From DHCP Server.

Rate this post