DEV Community

Cover image for Setting up a DHCP server

Posted on • Updated on

Setting up a DHCP server


  • DHCP or (Dynamic Host Configuration Protocol) is a networking protocol that is used to provide dynamic IP addresses to clients on a network.
  • In Linux servers, the DHCP service allows for automatic and centralized management of IP addresses.
  • It is most used in Private networks (best for LAN use cases). It provides IP addresses to the clients connected the network.
  • It uses UDP 👉 UDP:67 used by the server and UDP:68 for the client

The process of IP leasing

There are 4 steps:

  1. DHCP Discover (client to server)
  2. DHCP Offer (server to client)
  3. DHCP Request (client to server)
  4. DHCP ACK (server to client)

DHCP IP leasing

Setting up DHCP

First, we need to install the DHCP package,

yum -y install dhcp-*
Enter fullscreen mode Exit fullscreen mode

After installation is complete, we can open the configuration file,

vi /etc/dhcp/dhcp.conf
Enter fullscreen mode Exit fullscreen mode

We will be able to see the following contents,

conf file

Adding the following to the file,

# The subnet that will be used
subnet netmask {
        range; # IP addresses range
        option domain-name-servers; # DNS server address
        option routers; # This is the default gateway
        max-lease-time 7200; # The lease time in seconds

# Declaring the name for the reservation of IP as 'Client'
host Client {
        hardware ethernet 00:0C:29:90:B0:97; # MAC of the host
        fixed-address; # Providing this IP to the host
Enter fullscreen mode Exit fullscreen mode

Starting and enabling the DHCP daemon,

systemctl start dhcpd
systemctl enable dhcpd
Enter fullscreen mode Exit fullscreen mode

Adding DHCP to the firewall,

firewall-cmd --permanent --add-service=dhcp
firewall-cmd --reload
Enter fullscreen mode Exit fullscreen mode

Finally, on the client end, we have to set the IPv4 settings to automatic,

Client pc IPv4

We can confirm this from the Windows PC,


The above simple DHCP configuration in the Linux system was able to provide an IP address for the Windows client PC

👉 Troubleshooting if it still shows the previous IP address

Using ipconfig /release on the Windows CMD,


Then renewing it using ipconfig /renew


Top comments (0)