Set up DHCP Server on CentOS 6

Part 4 of setting up a Linux home lab environment with VirtualBox. Check this blog post for more info.

Dynamic Host Configuration Protocol (DHCP) is a network protocol that automatically assigns TCP/IP information to client machines. Each DHCP client connects to the centrally located DHCP server, which returns the network configuration (including the IP address, gateway, and DNS servers) of that client.

DHCP is useful for automatic configuration of client network interfaces.


Software used in this article:

  1. CentOS 6.7
  2. DHCP 4.1.1

Intall and Configure a DHCP Server

Install DHCP package:

# yum install -y dhcp

Open /etc/dhcp/dhcpd.conf for editing and add the following:

log-facility local6;

# This is our only DHCP server

ddns-updates off;
ddns-update-style none;

default-lease-time 3600; #1h
max-lease-time 86400; #1 day
update-static-leases on;
one-lease-per-client on;

option dhcp-server-identifier dhcp.hl.local;

# DNS config
option domain-name "hl.local";
option domain-name-servers dns.hl.local;
option ntp-servers ntp.hl.local;
option smtp-server smtp.hl.local;

# Define a LAN subnet with the following items:
#   - Netmask to use
#   - The IP range to distribute to clients
#   - The broadcast address to use
subnet netmask {
  option subnet-mask;
  option broadcast-address;

Configure DHCP command line options. Open /etc/sysconfig/dhcpd and specify a network interface to listen on:

# eth0 - VirtualBox NAT
# eth1 - VirtualBox host-only LAN network

Enabled DHCP service on boot:

# chkconfig dhcpd on

Start the service:

# /etc/init.d/dhcpd restart

Iptables will be configured via Puppet. The line below is used for the time being only:

# iptables -A INPUT -p udp -m state --state NEW --dport 67 -j ACCEPT

Check DHCP leases when a client is connected:

# less /var/lib/dhcpd/dhcpd.leases


Check logs:

# tail /var/log/messages

Leave a Reply

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