How to configure a DHCP server in Rocky Linux

Jack Wallen shows you how to set up Rocky Linux 9 as a DHCP server for your local area network.

Close-up macro shot: person connects to the RJ45 internet connector on the LAN router switch.  Information communication network with data cable connected to the port with blinking lights.  Blue background
Image: Gorodenkoff/Adobe Stock

Rocky Linux has become one of the de facto standard replacements for CentOS. Not only is it a direct replacement for RHEL, but maintainer Gregory Kurtzer has made it clear that Rocky Linux will always be available and will never be owned by a company that can bring the distro down.

And for anyone who has used RHEL or CentOS, Rocky Linux will be instantly familiar and can serve you and your business with ease.

SEE: 40+ open source and Linux terms you need to know (TechRepublic Premium)

Let’s take a look at one way Rocky Linux can serve you as a DHCP server. I will guide you through the process of installing and configuring the DHCP server on this open source operating system. It shouldn’t take you more than a few minutes to get it up and running.

What you will need to implement the DHCP server

All you will need is a running instance of Rocky Linux and a user with sudo privileges. Clever? Let’s get to work.

How to install DHCP server software

Rocky Linux does not come with DHCP server installed so we will deal with that now. Login to your Rocky Linux instance, open a terminal window and issue the command:

sudo dnf install dhcp-server -y

Once it’s installed, you can now move on to setup.

How to configure the DHCP server in Rocky Linux

Before we start configuring the DHCP server, you’ll need to know the name of the interface you’ll be using. To discover that name, issue the command:

ip a

You should see at least two listings, one for the loopback, which will use the address, and the other for your LAN-facing network device. For example, mine is enp0s3.

Next, open the DHCP server configuration file with the command:

sudo nano /etc/dhcp/dhcpd.conf

The section you need to focus on will look like this:

default-lease-time 900;
max-lease-time 10800;


subnet netmask {
option routers;
option subnet-mask;
option domain-name-servers;

You will need to make sure to configure this section according to your network topology. After configuring this section, save and close the file.

How to open the firewall

Now we need to open the firewall for the DHCP server. First, add the rule for the firewall with:

sudo firewall-cmd --add-port=67/udp --permanent

Now reload the firewall to apply the new rule with:

sudo firewall-cmd --reload

How to start and enable the DHCP service

With everything fixed, you can now start and enable the service with a single command:

sudo systemctl enable --now

At this point, your Rocky Linux server is capable of serving DHCP addresses. However, one thing to keep in mind is that you want to make sure that this DHCP server’s settings do not conflict with any other devices that are handing out network addresses. Such a conflict would cause problems on your LAN, so either disable any other devices that do so, or set the IP address range for the Rocky Linux DHCP server beyond that of any other devices that dole out addresses.

And that’s all there is to it. You now have a working DHCP server, served by a powerful operating system. Enjoy those IP addresses.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube to get the latest tech tips for business professionals from Jack Wallen.

Leave a Comment