CentOS 7: Install dhcpd and run DHCP server

This article will describe running DHCP server.

 

1 Install dhcpd

Install dhcpd with yum.

$ sudo yum install -y dhcp

2 /etc/dhcp/dhcpd.conf

Define domain name, DHCP server IP address and gateway IP address.

Mapping MAC address 52:54:00:61:e4:e7 to IP address 192.168.11.128.

$ cat /etc/dhcp/dhcpd.conf
subnet 192.168.11.0 netmask 255.255.255.0 {
  option domain-name "my.net";
  option domain-name-servers 192.168.11.70, 192.168.11.1;
  option routers 192.168.11.1;
}

host debian-8 {
  hardware ethernet 52:54:00:61:e4:e7;
  fixed-address 192.168.11.128;
}

3 firewalld

Open port 67/udp with using service file in /usr/lib/firewalld/services/dhcp.xml.

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

4 Run dhcpd

Run dhcpd with systemctl.

$ sudo systemctl enable dhcpd
$ sudo systemctl restart dhcpd

5 Execution result

Checking IP address on MAC address 52:54:00:61:e4:e7 machine.

$ ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.11.128  netmask 255.255.255.0  broadcast
192.168.11.255
        inet6 fe80::5054:ff:fe61:e4e7  prefixlen 64  scopeid
0x20<link>
        ether 52:54:00:61:e4:e7  txqueuelen 1000  (Ethernet)
        RX packets 212  bytes 25859 (25.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 150  bytes 20382 (19.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

$ cat /etc/resolv.conf
# Generated by NetworkManager
search my.net
nameserver 192.168.11.70
nameserver 192.168.11.1