How to Install and configure DHCP on Rocky Linux – Testing with Client IP

In this blog we will go through on How to Install and configure DHCP on Rocky Linux and other RHEL derivatives such as Red Hat Enterprise Linux, CentOS Stream or Alma Linux.

Introduction

Dynamic Host setup Protocol, or DHCP IP is used to automatically assign IP addresses and other network setup parameter. It makes network administration simpler by doing away with the need for manual IP address setup. By assigning the IP address to each device dynamically rather than manually, DHCP streamlines the process of configuring a network. You may utilize this highly scalable technology on networks that have a variety of devices. Even non-technical individuals may set up modest business or residential networks using DHCP. Thus, understanding how to configure DHCP is helpful for maintaining the network and resolving connection problems. We will go through how to configure DHCP on Rocky Linux 9 (an operating system based on RHEL) in this article.

Pre-requisite

We will need two machines running with Rocky Linux 8 or 9. One for DHCP Server with static IP configured and other for the client machines for testing automatic IP assignment after successful bring up of DHCP Server.

DHCP Server : 192.168.5.3

You may use any other RHEL derivatives such as RHEL, CentOS Stream or Alma Linux. If you nee support to Install OS refer How to Install Rocky Linux

DHCP Packages Installation

Make sure the system is running on the latest version

If the above actions has upgraded the kernel packages make sure you reboot the system.

You are now ready to install the DHCP packages

Configuration

Once the packages is installed its now time to modify the default DHCP configuration files. Run the below commadn to open the file using any editor of your choice

Replace the default content of the file with the below content. Make sure you change the subnet details of your environment

Save and Close the file once you finish editing

We will now go through each of those above values to understand better for you to use as per your network environment

  • default-lease-time : The value specifies how long the DHCP server will lease an address to a client. In this case, the default-lease-time value is 3600 seconds or 1 hour. The max-lease-time is the maximum duration that the IP will be leased to a client. In our case, this is set to 86400 seconds or 24 hours.
  •  subnet : In this setup, 192.168.5.0, is the subnet and 255.255.255.0 is the subnet mask. The IP address range starts from 192.168.5.2 right through 192.168.5.253.
  •  option routers : defines the default gateway. In this case, 192.168.5.1.
  •  option subnet-mask : determines the subnet-mask assignment to each client or host. In this case, 255.255.255.0.
  • domain-name-servers : specifies the DNS servers. In this case 192.168.5.1.

Configure the Firewall services for DHCP

Now we can restart the DHCP services and will enable the service to be persistent across the reboot

This was one of the method of setting and configuring the DHCP server. Let us look another method of setting DHCP using the dnsmasq

DHCP server Using dnsmasq

DNS caching, DHCP, DNS forwarding, and other services are all offered by the open-source Dnsmasq DHCP server and DNS forwarder. For small-scale installations in a small network, this tool serves as the DHCP. Let us install the packages

Now the package is installed let us open the default configuration file for further configuration

Replace the default content of the file with the below lines. Chose the interface as per your environment in the file below

Once you’re done setting up Dnsmasq, test its configuration to make sure your changes are valid:

If the configuration is correct you see something like this

Finally restart the service followed by the enabling it

Test DHCP Server using Client

We will now check the DHCP IP assignment on a client within our own LAN. Let us start with installing the dhcp-client

We can now use dhclient command to request for an IP address from the DHCP Server

You will see the expected output as below

You can verify this by going back to the dhcp server and search the client machine ip address in /var/log/message file

Conclusion

This concludes our discussion of the easy methods for installing and configuring DHCP on Rocky Linux 9. For a change, we have included the dnsmasq method for configuring DHCP, as it also supports a DHCP server. Additionally, we advise you to update the configuration file with the information you now possess. If not, you might encounter a problem while trying to activate the dhcpd.service on the computer. For more info you may also refer to the official Website ISC DHCP

Leave a comment