Install DHCP Server on Rocky Linux

This article is going to take you through on how to Install DHCP Server on Rocky Linux. The DHCP Server is a network server that distributes IP addresses, default gateways, and other network information to client devices automatically. The Dynamic Host Configuration Protocol is used by the DHCP server to respond to broadcast queries from clients.

How to Install DHCP Server on Rocky Linux

Install DHCP Server on Rocky Linux

  • Update your packages.
sudo dnf update
  • Then run the command below to install DHCP Server.
sudo dnf install dhcp-server

Sample output

Last metadata expiration check: 0:05:54 ago on Fri 22 Apr 2022 06:20:22 PM EAT.
Dependencies resolved.
=================================================================
 Package            Arch     Version              Repo      Size
=================================================================
Installing:
 dhcp-server        x86_64   12:4.3.6-45.el8      baseos   529 k
Installing dependencies:
 bind-export-libs   x86_64   32:9.11.26-6.el8     baseos   1.1 M
 dhcp-common        noarch   12:4.3.6-45.el8      baseos   206 k
 dhcp-libs          x86_64   12:4.3.6-45.el8      baseos   147 k

Transaction Summary
=================================================================
Install  4 Packages

Total download size: 2.0 M
Installed size: 4.6 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): dhcp-libs-4.3.6-45.el8.x8  91 kB/s | 147 kB     00:01    
(2/4): dhcp-common-4.3.6-45.el8. 121 kB/s | 206 kB     00:01    
(3/4): dhcp-server-4.3.6-45.el8. 428 kB/s | 529 kB     00:01    
(4/4): bind-export-libs-9.11.26- 249 kB/s | 1.1 MB     00:04    
-----------------------------------------------------------------
Total                            364 kB/s | 2.0 MB     00:05     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                         1/1 
  Installing       : dhcp-libs-12:4.3.6-45.el8.x86_64        1/4 
  Installing       : dhcp-common-12:4.3.6-45.el8.noarch      2/4 
  Installing       : bind-export-libs-32:9.11.26-6.el8.x86   3/4 
  Running scriptlet: bind-export-libs-32:9.11.26-6.el8.x86   3/4 
  Running scriptlet: dhcp-server-12:4.3.6-45.el8.x86_64      4/4 
  Installing       : dhcp-server-12:4.3.6-45.el8.x86_64      4/4 
  Running scriptlet: dhcp-server-12:4.3.6-45.el8.x86_64      4/4 
  Verifying        : bind-export-libs-32:9.11.26-6.el8.x86   1/4 
  Verifying        : dhcp-common-12:4.3.6-45.el8.noarch      2/4 
  Verifying        : dhcp-libs-12:4.3.6-45.el8.x86_64        3/4 
  Verifying        : dhcp-server-12:4.3.6-45.el8.x86_64      4/4 

Installed:
  bind-export-libs-32:9.11.26-6.el8.x86_64                       
  dhcp-common-12:4.3.6-45.el8.noarch                             
  dhcp-libs-12:4.3.6-45.el8.x86_64                               
  dhcp-server-12:4.3.6-45.el8.x86_64                             

Complete!

Configure DHCP Server on Rocky Linux

  • After the installation DHCP server will create an empty configuration file called /etc/dhcp/dhcpd.conf.
  • A sample file is located in /usr/share/doc/dhcp-server/dhcpd.conf.example.
  • Before you can proceed, check the network for the interface that you want to use for DHCP server.
ip a

Sample output

1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens160:  mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:8a:47:48 brd ff:ff:ff:ff:ff:ff
    inet 192.168.171.128/24 brd 192.168.171.255 scope global dynamic noprefixroute ens160
       valid_lft 965sec preferred_lft 965sec
    inet6 fe80::20c:29ff:fe8a:4748/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: virbr0:  mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:3b:56:a3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic:  mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:3b:56:a3 brd ff:ff:ff:ff:ff:ff

From the sample output above, we will use ens160 interface for our DHCP server.

  • Next, create the config file using the command below.
sudo nano /etc/dhcp/dhcpd.conf

Then set configuration according to your network as shown in the example below.

option domain-name "itnixpro.com";
option domain-name-servers ns1.itnixpro.com;

default-lease-time 3600;
max-lease-time 43200;

authoritative;

subnet 192.168.171.0 netmask 255.255.255.0 {
  range 192.168.171.150 192.168.171.254;
  option domain-name-servers 192.168.171.1, 8.8.8.8;
  option domain-name "itnixpro.com";
  option routers 192.168.171.1;
}
  • Read more on the sample configuration file.
  • Save and exit the configuration file.
  • Next, allow DHCP server on firewall.
firewall-cmd --add-port=67/udp --permanent
firewall-cmd --reload
  • Start DHCP server.
sudo systemctl start dhcpd
  • Enable DHCP server to start on system boot.
sudo systemctl enable dhcpd
  • If your configuration is ok, DHCP server should be running. Check status using the command below.
sudo systemctl status dhcpd

Sample output

● dhcpd.service - DHCPv4 Server Daemon
   Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-04-22 22:25:04 EAT; 34s ago
     Docs: man:dhcpd(8)
           man:dhcpd.conf(5)
 Main PID: 4039 (dhcpd)
   Status: "Dispatching packets..."
    Tasks: 1 (limit: 23385)
   Memory: 8.7M
   CGroup: /system.slice/dhcpd.service
           └─4039 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid

Apr 22 22:25:04 localhost.localdomain dhcpd[4039]: ** Ignoring requests on virbr0.  If this is not what
Apr 22 22:25:04 localhost.localdomain dhcpd[4039]:    you want, please write a subnet declaration
Apr 22 22:25:04 localhost.localdomain dhcpd[4039]:    in your dhcpd.conf file for the network segment
Apr 22 22:25:04 localhost.localdomain dhcpd[4039]:    to which interface virbr0 is attached. **
Apr 22 22:25:04 localhost.localdomain dhcpd[4039]: 
Apr 22 22:25:04 localhost.localdomain dhcpd[4039]: Listening on LPF/ens160/00:0c:29:8a:47:48/192.168.171.0/24
Apr 22 22:25:04 localhost.localdomain dhcpd[4039]: Sending on   LPF/ens160/00:0c:29:8a:47:48/192.168.171.0/24
Apr 22 22:25:04 localhost.localdomain dhcpd[4039]: Sending on   Socket/fallback/fallback-net
Apr 22 22:25:04 localhost.localdomain dhcpd[4039]: Server starting service.
Apr 22 22:25:04 localhost.localdomain systemd[1]: Started DHCPv4 Server Daemon.
  • You have made it to the end of our article. Cheers! You have learned how to Install DHCP Server on Rocky Linux.

Read more about DHCP

See how configure DHCP client on Ubuntu systems;

Install and Configure DHCP client on Rocky Linux

How to Configure DHCP Client on Ubuntu

Other Tutorials

Install Garuda Linux on VirtualBox

Install Docker CE on Ubuntu 22.04

Install NFS Server on Debian 11

System administrator | Software Developer | DevOps

Leave a Comment