DHCP Server

Anass Assim - Oct 18 - - Dev Community

1- Network Setup :

We assume the following network configuration:

  • Server (Debian 1) - Internal Network: 192.168.1.1/24
  • Failover (Debian 2) - Internal Network: 192.168.1.2/24
  • Relay (Debian 3) - 2 Interfaces (Internal Network):
    • IP in the Client Network: 192.168.1.3/24
    • IP in the Server Network: 192.168.2.1/24
  • Client (Debian 4) - Internal Network: 192.168.2.10/24

We will assign the IPs to the machines through the file /etc/network/interfaces :

  • Server :

Image description

  • Failover :

Image description

  • Relay :

Image description

  • Client:

Image description


2- Installing Necessary Packages :

  • Server :
apt update
apt install isc-dhcp-server
Enter fullscreen mode Exit fullscreen mode
  • Failover :
apt update
apt install isc-dhcp-server
Enter fullscreen mode Exit fullscreen mode
  • Relay :
apt update
apt install isc-dhcp-relay
Enter fullscreen mode Exit fullscreen mode
  • Client :

No packages need to be installed on the client, but it is advisable to update the repository.

apt update
Enter fullscreen mode Exit fullscreen mode

3-Connectivity Check :

  • To check connectivity between the client and server, we usually ping from the client to the server or vice versa.

Image description

  • Now, edit the network configuration file on the client, located at /etc/network/interfaces, and configure the enp0s3 interface in DHCP mode.

Image description


3- Server Machine Configuration :

a- /etc/default/isc-dhcp-server :

  • Edit the file /etc/default/isc-dhcp-server to configure the interface that will listen for client requests, which in this case will be enp0s3.

Image description

b- /etc/dhcp/dhcpd.conf :

  • Now, configure the DHCP service on the server:

Image description

Now we need to restart the DHCP service:

systemctl restart isc-dhcp-server
systemctl status isc-dhcp-server
Enter fullscreen mode Exit fullscreen mode

The service should now be active.


4-Failover Machine Configuration :

a- /etc/default/isc-dhcp-server

  • Just like on the server, we need to edit the file /etc/default/isc-dhcp-server to configure the interface that will listen for client requests, which in this case will be enp0s3.

Image description

b- /etc/dhcp/dhcpd.conf

  • Now, configure the DHCP service on the Failover:

Image description

  • Now we need to restart the DHCP service:
systemctl restart isc-dhcp-server
systemctl status isc-dhcp-server
Enter fullscreen mode Exit fullscreen mode

The service should now be active.


5-Relay Machine Configuration :

*a- Enable Forwarding: *

Edit the file /proc/sys/net/ipv4/ip_forward to allow packet forwarding between network interfaces:

echo '1' > /proc/sys/net/ipv4/ip_forward
Enter fullscreen mode Exit fullscreen mode

b- Client Network:

To make this change persistent after a reboot, edit the file /etc/sysctl.conf and add the following line:

echo "net.ipv4.ip_forward=1" > /etc/sysctl.conf
Enter fullscreen mode Exit fullscreen mode

c- /etc/default/isc-dhcp-relay

In this file, we need to add the IP of the server and the Failover, and set the two interfaces that connect to the client and the server. By default, these are usually “enp0s3” and “enp0s8” in VirtualBox.

Image description


6- DHCP Verification:

Part 1: Server Check

We have finished configuring all machines (Server, RELAY, FAILOVER). Now it's time to check if the DHCP works correctly and if the client can obtain a dynamic IP from the server.

Image description

Part 2: Failover Check

After verifying that the client can obtain a dynamic IP from the server and everything works correctly, we can turn off the server or stop the isc-dhcp-server service to check if the client can obtain a dynamic IP from the Failover machine.

systemctl stop isc-dhcp-server # On the Server Machine
Enter fullscreen mode Exit fullscreen mode

Image description

. . . . .
Terabox Video Player