Install & Configure DHCP Server on RHEL 8 - cfloquetprojects/homelab GitHub Wiki

Introduction

A staple of many enterprises today is the use of Red Hat Enterprise Linux (RHEL), with the latest iteration of this OS being RHEL 8, which we will be working with today.

I've already created a Red Hat Developer Account, which is not only free, but includes up to 16 different licenses for personal use, which is more than enough for us to get by in our lab environment.

The purpose of this lab will be installing and configuring a DHCP server on RHEL 8 using dhcpd as a means of managing the IPv4 addresses of our clients and servers.

The scope of this document will not include configuration steps for setting up DHCPv6 servers, although those instructions are readily available PDF by Red Hat linked here.

Next we will be configuring Rsyslog as our method of sending and ingesting logs from other nodes on our network. This is a highly configurable, "rocket" fast system for log processing which will allow us to parse logs of nearly all sources and formats.

Pre-Flight Check

As a matter of principle, unfortunately RHEL does require us to authenticate to our developer account before being able to fetch supported packages or updates out of the box.

This can be easily done with the following commands, leveraging subscription-manager as root enter the following commands:

# subscription-manager register
*enter developer account credentials*
# subscription-manager attach --auto
# subscription-manager status

Installing dhcp-server on RHEL 8:

The first step of this process is an easy one, with us only needing to grab one package to make our DHCP server work pretty much out of the box:

$ sudo yum -y install dhcp-server

Next we need to configure our dhcpd.conf file within /etc/dhcp/dhcpd.conf to allow for our server to provide ip addresses to clients within our subnet (dhcp relay coming later):

💣 NOTE: Without the authoritative statement, the dhcpd service does not answer DHCPREQUEST messages with DHCPNAK if a client asks for an address that is outside of the pool.#

$ sudo vi /etc/dhcp/dhcpd.conf
<..>
default-lease-time 86400; # set our default lease time to one day (86400s)
authoritative; # apply authoriative statement to all of our subnets
subnet 192.0.2.0 netmask 255.255.255.0 {
range 192.0.2.20 192.0.2.100; # define subnet pool range
option domain-name-servers 192.0.2.1, 1.1.1.1; # define dns servers
option routers 192.0.2.1;
option broadcast-address 192.0.2.255;
max-lease-time 172800;
}

We can add an option to create DHCP reservations based on a clients MAC address by inserting the following at the bottom of dhcpd.conf:

$ vi /etc/dhcp/dhcpd.conf
<...>
host insertHostname {
hardware ethernet AA:BB:CC:DD:EE:FF;
fixed-address 1.2.3.4;
}

In order for the DHCP reservations to actually take effect, we need to create a dhcpd.leases file within /etc/dhcp/ to store information pertaining to our reservations, in a similar way as dhcpd.conf:

$ vi /etc/dhcp/dhcpd.leases

lease 1.2.3.4 {
  binding state active;
  reserved;
  hardware ethernet AA:BB:CC:DD:EE:FF;
}

I've since written a simple bash script that can take the hostname, MAC address, and desired IPv4 address of a new DHCP reservation and automatically at the necessary fields into the correct files. Check it out here.

Now let's copy the provided dhcpd.service file to our /etc/systemd/system/ folder to run it on boot:

$ sudo cp /usr/lib/systemd/system/dhcpd.service /etc/systemd/system/

We also need to make a minor change to the .service file to define the interfaces we want to be listening to DHCP requests:

$ vi /etc/systemd/system/dhcpd.service
<..>
ExecStart=/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid $DHCPDARGS **nameOfInterface**

Now we should be able to add some simple firewall rules and enable/restart our dhcpd service:

$ sudo firewall-cmd --add-service=dhcpd --permanent
$ systemctl daemon-reload
$ systemctl enable dhcpd
$ systemctl restart dhcpd

Testing Client DHCP Requests

Now that our DHCP Server configuration is complete we can test obtaining leases from a client using dhclient:

$ sudo dhclient -r
$ sudo dhclient
$ hostname -I
⚠️ **GitHub.com Fallback** ⚠️