How to Install a DHCP Server in CentOS, RHEL and Fedora

DHCP (Dynamic Host Configuration Protocol) is a network protocol that automatically assigns IP addresses and network configuration parameters to devices on a network. It eliminates manual IP configuration, reducing administrative overhead and preventing address conflicts. This article guides you through installing and configuring a DHCP server on CentOS, RHEL, and Fedora systems.

Install DHCP Server Package

First, install the DHCP server package using the package manager. For newer versions, use dnf, while older versions use yum

# For CentOS 8+/RHEL 8+/Fedora
sudo dnf install dhcp-server

# For CentOS 7/RHEL 7
sudo yum install dhcp

Configure DHCP Server

After installation, configure the DHCP server by editing the main configuration file

sudo vi /etc/dhcp/dhcpd.conf

Basic DHCP Configuration

Configure the DHCP settings including IP address range, subnet mask, gateway, and DNS servers

# Global settings
default-lease-time 600;
max-lease-time 7200;
authoritative;

# Subnet configuration
subnet 192.168.1.0 netmask 255.255.255.0 {
    range 192.168.1.10 192.168.1.50;
    option subnet-mask 255.255.255.0;
    option routers 192.168.1.1;
    option domain-name-servers 8.8.8.8, 8.8.4.4;
    option domain-name "example.com";
    option broadcast-address 192.168.1.255;
}

Advanced Configuration Options

Add static IP reservations for specific devices based on MAC addresses

# Static IP reservation
host printer {
    hardware ethernet 00:11:22:33:44:55;
    fixed-address 192.168.1.100;
}

# Multiple subnet configuration
subnet 192.168.2.0 netmask 255.255.255.0 {
    range 192.168.2.10 192.168.2.50;
    option routers 192.168.2.1;
    option domain-name-servers 192.168.1.1;
}

Start and Enable DHCP Server

Start the DHCP service and enable it to start automatically at boot time

# Start the DHCP server
sudo systemctl start dhcpd

# Enable automatic startup at boot
sudo systemctl enable dhcpd

# Check service status
sudo systemctl status dhcpd

Firewall Configuration

Configure the firewall to allow DHCP traffic

# Open DHCP port in firewall
sudo firewall-cmd --permanent --add-service=dhcp
sudo firewall-cmd --reload

# Verify firewall rules
sudo firewall-cmd --list-services

Client Configuration

Configure network interfaces on client machines to use DHCP. Edit the network interface configuration file

sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0

Set the interface to use DHCP

DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes

Restart the network service to apply changes

sudo systemctl restart network
# or for newer systems
sudo systemctl restart NetworkManager

Monitoring and Troubleshooting

Monitor DHCP server activity and troubleshoot issues using log files and status commands

# View DHCP server logs
sudo tail -f /var/log/messages | grep dhcp

# Check active leases
sudo cat /var/lib/dhcpd/dhcpd.leases

# Test configuration syntax
sudo dhcpd -t -cf /etc/dhcp/dhcpd.conf

Common Configuration Issues

Issue Cause Solution
Service fails to start Configuration syntax error Check syntax with dhcpd -t
Clients not getting IPs Firewall blocking DHCP Open port 67/UDP in firewall
IP conflicts Overlapping static assignments Review range and static reservations

Security Considerations

  • DHCP Snooping Enable on network switches to prevent rogue DHCP servers

  • MAC Address Filtering Restrict DHCP assignments to known MAC addresses

  • Network Segmentation Isolate DHCP traffic using VLANs

  • Regular Monitoring Monitor lease assignments and detect anomalies

Conclusion

Installing and configuring a DHCP server on CentOS, RHEL, and Fedora streamlines network management by automating IP address assignment. Proper configuration with security measures ensures reliable network operations. Regular monitoring and maintenance help prevent common issues and maintain optimal performance.

Updated on: 2026-03-17T09:01:38+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements