DHCP Server Setup on Linux
Overview
Note: The NetFoundry zLAN firewall does not manage DHCP services. Customers must install and configure their own DHCP server using standard Linux tools. This guide provides step-by-step instructions for installing and setting up a DHCP server with
isc-dhcp-server
.
What is DHCP?
DHCP (Dynamic Host Configuration Protocol) automatically assigns IP addresses and network configuration to devices on your network. A DHCP server manages a pool of IP addresses and hands them out to clients as they join the network.
Installing DHCP Server
- Ubuntu/Debian
- RedHat/CentOS/Rocky/AlmaLinux
sudo apt update
sudo apt install isc-dhcp-server
sudo dnf install dhcp-server
Configuring DHCP Server
Main Configuration File
- Ubuntu/Debian:
/etc/dhcp/dhcpd.conf
- Red Hat/CentOS:
/etc/dhcp/dhcpd.conf
Edit the configuration file to define your DHCP settings:
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;
option domain-name-servers 8.8.8.8, 8.8.4.4;
option domain-name "example.local";
default-lease-time 600;
max-lease-time 7200;
}
subnet
: The network served by DHCPrange
: The pool of IP addresses to assignoption routers
: Default gatewayoption domain-name-servers
: DNS serversoption domain-name
: Local domain namedefault-lease-time
: Lease duration in secondsmax-lease-time
: Maximum lease duration
Specify Interfaces
Edit /etc/default/isc-dhcp-server
(Ubuntu/Debian) or /etc/sysconfig/dhcpd
(Red Hat/CentOS) to specify which network interface(s) DHCP should listen on:
Ubuntu/Debian:
INTERFACESv4="eth0"
Red Hat/CentOS:
DHCPDARGS="eth0"
Starting and Enabling DHCP Server
Ubuntu/Debian
sudo systemctl enable isc-dhcp-server
sudo systemctl start isc-dhcp-server
Red Hat/CentOS
sudo systemctl enable dhcpd
sudo systemctl start dhcpd
Verifying DHCP Server
- Check service status:
sudo systemctl status isc-dhcp-server # Ubuntu/Debian
sudo systemctl status dhcpd # Red Hat/CentOS - View logs:
sudo journalctl -u isc-dhcp-server # Ubuntu/Debian
sudo journalctl -u dhcpd # Red Hat/CentOS - Test DHCP assignment:
- Connect a client device to the network and verify it receives an IP address from the configured range.
Summary of Commands
Action | Command Example |
---|---|
Install DHCP server | sudo apt install isc-dhcp-server / sudo dnf install dhcp-server |
Edit config | sudo nano /etc/dhcp/dhcpd.conf |
Specify interface | Edit /etc/default/isc-dhcp-server or /etc/sysconfig/dhcpd |
Enable service | sudo systemctl enable isc-dhcp-server / sudo systemctl enable dhcpd |
Start service | sudo systemctl start isc-dhcp-server / sudo systemctl start dhcpd |
Check status | sudo systemctl status isc-dhcp-server / sudo systemctl status dhcpd |
View logs | sudo journalctl -u isc-dhcp-server / sudo journalctl -u dhcpd |
Opening DHCP Ports in the Firewall UI
Important: The NetFoundry zLAN firewall manages all firewall functions. Do not use
ufw
orfirewall-cmd
to open ports. Use the Add/Remove Rule UI in the Console to allow traffic.
To allow DHCP traffic (UDP port 67), add a rule using the UI as described in the Adding & Removing Rules guide:
- Type: Custom
- Protocol: UDP
- Direction: INBOUND
- Action: Allow
- Port Range: 67-67
- Source: (as needed, e.g., 0.0.0.0/0)
- Destination: (your DHCP server IP or subnet)
Repeat for each interface where DHCP traffic should be allowed.
Troubleshooting Tips
- Ensure the DHCP server is listening on the correct interface.
- Check for syntax errors in
/etc/dhcp/dhcpd.conf
:sudo dhcpd -t
- Ensure the required ports are open in zfw for DHCP and any dynamic routing protocols in use.
- Review logs for errors or denied requests.
- Confirm that no other DHCP server is running on the same network.