Install and Configure DHCP Server on CentOS 7 / RHEL 7

Sep 20, 2015 Linux

DHCP (Dynamic Host Configuration Protocol) is a network protocol used for dynamically assigning IP addresses for computers attached to the network. Standard port used for DHCP service: 67(UDP).

In this tutorial we will launch dhcp server on CentOS 7 / RHEL 7 and define example subnets.

Steps:

1. Install dhcp service

[root@router ~]# yum install dhcp

2. Edit configuration file

Edit/modify dhcp configuration file (/etc/dhcp/dhcpd.conf) to look like below example:

[root@router ~]# vim /etc/dhcp/dhcpd.conf 
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#
subnet 192.168.2.0 netmask 255.255.255.0 {
        option routers                  192.168.2.1;
        option subnet-mask              255.255.255.0;
        option domain-name-servers       8.8.8.8, 8.8.4.4;
        range 192.168.2.20 192.168.2.100;
        default-lease-time 3600; 
        max-lease-time 7200; 

        host pinky {
           hardware ethernet 00:24:81:a3:41:66;
           fixed-address 192.168.2.2;
        }

        host bigfoot {
           hardware ethernet 00:24:81:a3:41:64;
           fixed-address 192.168.2.3;
        }

}

subnet 192.168.3.0 netmask 255.255.255.0 {
        authoritative;
        option routers                  192.168.3.1;
        option subnet-mask              255.255.255.0;
        option domain-name-servers      8.8.8.8, 8.8.4.4;
        range 192.168.3.10 192.168.3.100;
        default-lease-time 3600; 
        max-lease-time 7200; 
}

Above example shows dhcpd configuration for two subnets:

Subnet 1 (LAN based on enp2s0 interface):
Network address: 192.168.2.0/24
Netmask: /24 (255.255.255.0)
Gateway/router: 192.168.2.1
DHCP range: 192.168.2.{20-100}
DHCP static reservation: pinky (192.168.2.2), bigfoot (192.168.2.3)
DNS servers for DHCP clients: 8.8.8.8, 8.8.4.4 (Google primary and secondary DNS)
DHCP default IP lease time: 3600s
DHCP maximum IP lease time: 7200s

Subnet 2 (WLAN based on wlp0s20u1u2 interface via hostapd):
Network address: 192.168.3.0/24
Netmask: /24 (255.255.255.0)
Gateway/router: 192.168.3.1
DHCP range: 192.168.3.{10-100}
DHCP static reservation: none
DNS servers for DHCP clients: 8.8.8.8, 8.8.4.4 (Google primary and secondary DNS)
DHCP default IP lease time: 3600s
DHCP maximum IP lease time: 7200s

Gateway/router IPs associated with network interfaces:

[root@router ~]# ip a
...
3: enp2s0:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether fc:aa:14:2b:5a:b8 brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.1/24 brd 192.168.2.255 scope global enp2s0
       valid_lft forever preferred_lft forever
    inet6 fe80::feaa:14ff:fe2b:5ab8/64 scope link 
       valid_lft forever preferred_lft forever
4: wlp0s20u1u2:  mtu 1500 qdisc mq state UP qlen 1000
    link/ether a8:54:b2:42:8e:4c brd ff:ff:ff:ff:ff:ff
    inet 192.168.3.1/24 scope global wlp0s20u1u2
       valid_lft forever preferred_lft forever
    inet6 fe80::aa54:b2ff:fe42:8e4c/64 scope link 
       valid_lft forever preferred_lft forever
...

3. Launch dhcpd service

Run dhcpd service:

[root@router ~]# systemctl start dhcpd

Enable dhcpd service (to make it persistent after reboot):

[root@router ~]# systemctl enable dhcpd

Verify, if dhcpd service is running properly:

[root@router ~]# systemctl status dhcpd
dhcpd.service - DHCPv4 Server Daemon
   Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; disabled)
   Active: active (running) since Sun 2015-09-20 18:16:13 CEST; 1min 33s ago
     Docs: man:dhcpd(8)
           man:dhcpd.conf(5)
 Main PID: 26902 (dhcpd)
   Status: "Dispatching packets..."
   CGroup: /system.slice/dhcpd.service
           └─26902 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid
...
6 thoughts on “Install and Configure DHCP Server on CentOS 7 / RHEL 7”
  1. Hello,
    I am getting the error massage when i start dhcpd service.

    hardware ethernet 00:0c:29:99:d2:53
    fixed-address 192.168.10.10;
    }

    [root@fwl ~]# cat /etc/dhcp/dhcpd.conf
    #
    # DHCP Server Configuration file.
    # see /usr/share/doc/dhcp*/dhcpd.conf.example
    # see dhcpd.conf(5) man page

    subnet 192.168.10.0 netmask 255.255.255.0 {
    option routers 192.168.10.1;
    option subnet-mask 255.255.255.0;
    option domain-name-servers 192.168.10.10, 8.8.8.8;
    range 192.168.10.100 192.168.10.200;
    default-lease-time 3600;
    max-lease-time 7200;

    host fwl.tech.com {
    hardware ethernet 00:0c:29:99:d2:53
    fixed-address 192.168.10.10;
    }

    [root@fwl ~]# vi /etc/dhcp/dhcpd.conf
    [root@fwl ~]# systemctl enable dhcpd
    [root@fwl ~]# systemctl start dhcpd
    Job for dhcpd.service failed because the control process exited with error code. See “systemctl status dhcpd.service” and “journalctl -xe” for details.
    [root@fwl ~]# cat /etc/dhcp/dhc

  2. host fwl.tech.com {
    hardware ethernet 00:0c:29:99:d2:53; (Add semicolon )
    fixed-address 192.168.10.10;

    then restart service:
    systemctl restart dhcpd

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.