In this post, we will talk about how to configure a DHCP server on Rocky Linux 8 / Alma Linux 8 / CentOS 8. This tutorial can help you with some Linux administrative tasks.
What is DHCP?
Dynamic Host Configuration Protocol stands for DHCP. In short, we are talking about a network protocol that allows us to assign IP addresses automatically under the parameters and time that we define.
This is significant because in large networks, DHCP sends the parameters necessary for the connection to the network to be established. In addition to this, it assigns an IP address so that we do not have to do this manually.
In this post, we are going to configure a DHCP server that can do this by itself. For this, we will use a Rocky Linux 8 system, but it will also be compatible with Alma Linux 8 and other derivatives of the RHEL family.
Let’s get started.
Configuring a static IP address on the server
In this first step, it is necessary that the Rocky Linux 8 server has a fixed or static IP address.
If your server has a static IP address, then you can skip all the following steps. Otherwise, first find out the IP address of the server by running
ip a
There you will see all the network interfaces and their information. What matters is the line starting with inet because the IP address will follow. For example:
inet 192.168.1.10
Next, we have to edit a configuration file for the network interface that we want to make have a static IP address. To do this run:
sudo nano /etc/sysconfig/network-scripts/ifcfg-[network-interface]
And start modifying the following values:
TYPE="Ethernet" BOOTPROTO="none" NAME="eth0" IPADDR=192.168.1.15 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 BROADCAST=192.168.255.255 DEVICE="eth0" ONBOOT="yes"
Each of the values is very descriptive. You can adapt it to your needs. If you want to use a DNS server, you can add the lines.
DNS1=[DNS_SERVER] DNS2=[DNS_SERVER]]
Save the changes and close the editor. Apply the changes by running.
sudo nmcli connection reload
And restarting the network interface
nmcli with down [network_interface] nmcli with up [network_interface]
Remember that you have to modify the command with your network interface.
Configuring the DHCP server on Rocky Linux 8 / Alma Linux 8 / CentOS 8
In this step, we have to install the dhcp-server package, which is the package with which we can install a DHCP server.
sudo dnf install dhcp-server
The package installs quite fast and easy and its configuration file is /etc/dhcp/dhcpd.conf which we have to edit after backing it up.
sudo cp /etc/dhcp/dhcpd.conf /etc/dhcpp/dhcpd.conf.bak
Now yes, edit it
sudo nano /etc/dhcp/dhcpd.conf
And add the following
default-lease-time 900; max-lease-time 10800; ddns-update-style none; authoritative; subnet 192.168.20.0 netmask 255.255.255.0 { range 192.168.20.10 192.168.20.200; option routers 192.168.20.1; option subnet-mask 255.255.255.0; option domain-name-servers 192.168.20.1; }
Let’s explain the file:
- default-lease-time: default time the server will reserve an address.
- max-lease-time: Maximum time the server will reserve the address.
- ddns-update-style: Specifies whether the DHCP server will update the computer’s DNS name.
- authoritative: This allows the server to send DHCPNACK messages to clients that send a DHCPREQUEST with an invalid IP proposal.
- In subnet, we define the characteristics of the network we are going to manage. Things like range, DNS, net mask and others are defined here.
Save the changes and close the editor.
All that’s left is to open the UDP port 67, start the service and make the clients connect to our server
sudo firewall-cmd --permanent --add-port=67/udp sudo systemctl enable -now dhcpd
That’s all.
DHCP server on Rocky Linux 8
– Conclusion
Thanks to this post, you learned how to configure a DHCP server. This type of protocol is vital in a production server. I hope you liked it and that it will be useful for you.