How to Setup DHCP Server in Rocky Linux 8

Introduction

Dynamic Host Configuration Protocol (DHCP) is an important network service that automatically assigns IP addresses and other network details (gateway, DNS, subnet mask) to client devices. This removes the need to manually configure IP addresses on each system.

In this guide, we will learn how to install and configure a DHCP server in Rocky Linux 8, its use cases, how it works, and some basic interview tips for Linux administrators.

Why Use a Linux-Based DHCP Server?

– Centralized IP address management
– Automatic IP assignment to clients
– Reduces manual configuration errors
– Saves time in large networks
– Easy to manage and flexible compared to router-based DHCP

How DHCP Works

DHCP works in a four-step process, also called DORA:
1. Discover: The client broadcasts a DHCP discover message to find a server.
2. Offer: The DHCP server replies with an IP address offer.
3. Request: The client requests the offered IP address.
4. Acknowledge: The server confirms the lease and assigns the IP.

Server Information

Package Name: dhcp-server
Configuration File: /etc/dhcp/dhcpd.conf
Port: 67/UDP (for server), 68/UDP (for client)
Service Name: dhcpd

Step 1: Install DHCP Server

Run the following command:

sudo dnf install dhcp-server -y

Step 2: Configure DHCP Server

The configuration file is located at:

/etc/dhcp/dhcpd.conf

Example configuration:


option domain-name "example.com";
option domain-name-servers 8.8.8.8, 8.8.4.4;
default-lease-time 600;
max-lease-time 7200;
authoritative;

subnet 192.168.1.0 netmask 255.255.255.0 {
  range 192.168.1.100 192.168.1.200;
  option routers 192.168.1.1;
}

Step 3: Enable and Start DHCP Service


sudo systemctl enable dhcpd
sudo systemctl start dhcpd
sudo systemctl status dhcpd

Step 4: Configure Firewall

Allow DHCP service in the firewall:


sudo firewall-cmd --add-service=dhcp --permanent
sudo firewall-cmd --reload

Verification

– Connect a client machine in the same network
– Run ip addr to see if the IP is assigned automatically

Best Practices for DHCP Server

– Always use **authoritative** mode for primary DHCP server
– Avoid overlapping IP ranges
– Reserve IPs for important servers (using MAC binding)
– Keep logs for troubleshooting: /var/log/messages

Interview Tips on DHCP

– Explain the DORA process clearly
– Be able to write a sample dhcpd.conf configuration
– Know how to troubleshoot using logs and systemctl
– Understand difference between DHCP and static IP

Conclusion

A Linux-based DHCP server in Rocky Linux 8 is powerful, scalable, and cost-effective for managing IP addresses in medium to large networks. With proper configuration and best practices, it makes network administration much easier.

Leave a Reply

Your email address will not be published. Required fields are marked *