Setting up DHCP server & clients on RedHat/Debian machines



Check my infrastructure here.

Background

I am planning to upgrade the network infrastructure, and want to make the process as painless as possible. First, I start by changing all the servers to get their network infrastructure from Machine A, the "DHCP Server". Instead of having cryptic names like Machine A or Machine B, I am assigning functional names to the machines. The IP addresses of the machines remain unchanged.

Old Hostname New Hostname Purpose
Machine A router.dundermifflin.com Main Router
Machine B dns0.dundermifflin.com Primary DNS and NTP
Machine C web0.dundermifflin.com Primary Web Server
Machine D web1.dundermifflin.com Secondary Web Server
Machine E nfs.dundermifflin.com File Server
Machine F dns1.dundermifflin.com Secondary DNS

All machines (Machines B-F) would take DNS Servers, NTP, IP address, gateway, hostname from the DHCP server AKA Machine A. This would make it easier for me in the future when I will configure DNS and NTP servers, I just have to change the config on Machine A and all other machines would honor the change.


DHCP Server Setup

Install ISC DHCP on Machine A.

yum install dhcp-server

Next, I changed the hostname for Machine A manually, by editing the /etc/hostname file.

[root@machinea ~]# cat /etc/hostname
router.dundermifflin.com
[root@machinea ~]#
[root@machinea ~]# hostnamectl
Static hostname: router.dundermifflin.com
Icon name: computer-vm
Chassis: vm 🖴
Machine ID: dab5052ba9464481a04710cb8fd86e43
Boot ID: 81decf11f01446c3b36c5de25ed44cd7
Virtualization: vmware
Operating System: Rocky Linux 9.2 (Blue Onyx)
CPE OS Name: cpe:/o:rocky:rocky:9::baseos
Kernel: Linux 5.14.0-284.25.1.el9_2.x86_64
Architecture: x86-64
Hardware Vendor: VMware, Inc.
Hardware Model: VMware7,1
Firmware Version: VMW71.00V.21100432.B64.2301110304

Now, let's configure the DHCP server.
Before I start configuring, there are a few things to note. There are some configs which should be common between all the machines aka "global" and some that are specific to the machine. For example, all machines should have the same DNS, NTP servers and lease time. However, the gateway is different for DMZ and LAN machines. Keeping this in mind, let's move on to the configuration.

I'm setting the DHCP lease time to be 10 minutes, which means, all the DHCP Clients would update configuration from DHCP server every 10 minutes. For now, I am setting 128.138.240.1, 128.138.130.30 as the DNS servers. I will change this to Machine B and Machine F once I configure B & F as DNS servers. I'm also setting NTP servers to be 132.163.97.1, 132.163.96.1 for now. I will change this to Machine A once I configure Machine A as an NTP server.
/etc/dhcp/dhcpd.conf:

default-lease-time 600; #the lease-time is in seconds
max-lease-time 600;
option domain-name-servers 128.138.240.1, 128.138.130.30; #Temporary DNS Servers
option ntp-servers 132.163.97.1, 132.163.96.1; # Temporary NTP Servers

Let's get those LAN and DMZ subnets up and running! Currently, I'm configuring 100 usable IP addresses for each subnet, but we can always expand as the organization grows. Additionally, I am designating Machine A as the default gateway since it serves as the router for traffic between these machines. Specifically, the LAN subnet is linked to Machine A with the IP address 10.21.32.1, while the DMZ subnet is connected to Machine A using the IP address 100.64.26.1.

#LAN
subnet 10.21.32.0 netmask 255.255.255.0 {
  range 10.21.32.100 10.21.32.199;
  option routers 10.21.32.1;
}

#DMZ
subnet 100.64.26.0 netmask 255.255.255.0 {
  range 100.64.26.100 100.64.26.199;
  option routers 100.64.26.1;
}

I'm now setting the DHCP server to first send an ICMP echo request to the IP address it is currently trying to dynamically allocate and wait 100 ms for a reply. This is just an added safety mechanism I'm implementing so that the DHCP server does not allocate an IP address that is currently in use. If a response is heard, the server must not respond and the lease time mustbe abandoned for another 10 minutes.

ping-check true; # Enable ping check globally
ping-timeout-ms 100; # Set the ping timeout to 100 milliseconds
abandon-lease-time 600; # Set the abandon-lease-time to 10 minutes (600 seconds)


Client Configuration

Now, let's configure Machines B-F to obtain their network configuration and hostname from Machine A using DHCP.

Interface and DHCP Configuration on Clients

Debian Clients:

1. Use the "systemctl status networking" service to manage interfaces: This command allows you to check the status of the networking service on Debian systems. It's essential for managing network interfaces and their configurations.

2. Update the "/etc/network/interfaces" file to use DHCP configuration: The "/etc/network/interfaces" file contains network interface configurations on Debian systems. By changing the configuration from static to DHCP, the interface will now obtain its network settings dynamically from the DHCP server.

From:

allow-hotplug ens192
iface ens192 inet static
address 100.64.42.6 netmask 255.255.255.0 gateway 100.64.42.1

To:

allow-hotplug ens192
iface ens192 inet dhcp

Redhat Clients:

1. Use "systemctl status NetworkManager" to manage interfaces: Similar to Debian, this command checks the status of the NetworkManager service on Redhat systems. NetworkManager is a daemon that manages network connections and devices.

2. Update the "/etc/NetworkManager/system-connections/ens192.nmconnection" file to use automatic configuration: This file contains configuration settings for the specified network connection. By changing the method to "auto," the interface will automatically obtain its network settings via DHCP.

From:

[ipv4]
method=manual
address1=100.64.42.6/24,100.64.42.1

To:

[ipv4]
method=auto


Updating Hostnames on Clients

1. Remove the "/etc/hostname" file to ensure dynamically assigned hostnames are used: This file typically contains the static hostname of the system. By removing it, the system will use the hostname assigned by the DHCP server.

2. Comment out the line in "/etc/dhcp/dhclient.conf" that sets the host-name: This line instructs the DHCP client to send its current hostname to the DHCP server. By commenting it out, the client will not send its hostname, allowing the DHCP server to assign one dynamically.

#send host-name = gethostname();


NTP Servers and DNS Configuration on Clients

Comment out the line in "/etc/chrony/chrony.conf" to pick up NTP servers from DHCP:

The "2.pool.ntp.org" line typically specifies a default NTP server. By commenting it out, the client will use the NTP servers provided by the DHCP server instead.

#2.pool.ntp.org


The "/etc/resolv.conf" file contains DNS resolver configuration. NetworkManager automatically updates this file with DNS server information obtained from DHCP, ensuring that the client uses the correct DNS servers specified by the DHCP server.

Conclusion

In the realm of network infrastructure, simplicity reigns supreme. By setting up an ISC DHCP server on Machine A and configuring clients accordingly, we've taken a significant step towards efficient network management.

With DHCP, the process of assigning IP addresses, DNS servers, and other network parameters becomes a breeze. By automating these tasks, we free up valuable time and resources for other endeavors.

Let's appreciate the beauty of automation. Here's to networks that run smoothly and effortlessly, allowing us to focus on what truly matters! Cheers.


View Project on GitHub