29.8 C
Texas
angeloma
Senior Writer and partner

How to configure DHCP Server on RockyLinux 8 / AlmaLinux OS 8 / CentOS 8?

Hello friends. A DHCP server can solve a lot of problems in an internal network, that’s why it’s good to know how to configure it on a server. That’s why today I will show you how to configure a DHCP server on Rocky Linux 8 / AlmaLinux OS 8 / CentOS 8.

What is DHCP?

DHCP (Dynamic Host Configuration Protocol) is a client-server network protocol that automatically assigns IP addresses within a set range. The DHCP server assigns IP addresses as they become free or unused by other members of the network. To achieve its goal a DHCP server can assign IP addresses as follows: Manual or static assignment: assigns an IP address to a specific machine. Automatic assignment: assigns an IP address to a client machine the first time it makes the request to the DHCP server and until the client releases it. And the third way to assign an IP address by a DHCP server is dynamic assignment.

So, let’s start.

Configuring DHCP Server on Rocky Linux 8 / AlmaLinux OS 8 / CentOS 8

Before we start we need to make sure that the server is fully up to date. So, connect to it and update it.

- Advertisement -
sudo dnf update

Set a static IP address on Rocky Linux 8 / AlmaLinux OS 8 / CentOS 8

The DHCP server must have a static IP address. This is important for the host to be able to do the process well. So, this is our first step.

If you need to know How to set a static IP address on Rocky Linux 8 / AlmaLinux OS 8 / CentOS 8 then you can do it through the post we have prepared for you.

After that, you can continue

Configuring the DHCP server

The package that gives us the ability to deploy the server is dhcp-server So we have to install it

sudo dnf install dhcp-server

The package is fairly lightweight so the installation can be done quickly.

Now we have to edit the server configuration file. The file in question is /etc/dhcp/dhcpd.conf but before editing it create a backup

sudo cp /etc/dhcp/dhcpd.conf /etc/dhcpp/dhcpd.confl.bak

Now proceed to edit it with your favorite text editor. I use nano but you can use vi or vim.

sudo nano /etc/dhcp/dhcpd.conf

Now 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;

}

Remember that all these values have to be modified. In this case, I will use some example values.

Thanks to the default-lease-time option we will be able to define how long the DHCP server will reserve an address. While the max-lease-time option will define the maximum. In this case, I have set 900 seconds or 15 minutes for default-lease-time and 10800 minutes or 3 hours for max-lease-time.

Now comes the vital part of the subnet configuration.

In this case, the subnet to configure is 192.168.20.0 and the mask is 255.255.255.0. With the range option you define the range of IP addresses to assign. And with the option router option you can define the default gateway. The subnet mask assignment to each host is defined by the option subnet-mask option. Finally, option domain-name-servers defines the DNS servers to assign to each host.

Finally, when you are done editing the file, save your changes and close the editor.

Now enable and start the option domain-name-servers service.

sudo systemctl start dhcpd
sudo systemctl enable dhcpd

You can check the status of the service,

sudo systemctl status dhcpd

In order for the dhcp service to work properly, you need to open UDP port 67 on your firewall.

Now you just need to configure the network on your client computers for this configuration.

Conclusion

A DHCP server is a simple thing to do, however, it is good to have knowledge about your network to do it correctly.

So, enjoy it!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article