๐Ÿงช DHCP Lab

๐Ÿ“Œ Objective

Understand how DHCP works in real network environment and how to debug common failure scenarios using a structured top-to-bottom approach.


โš™๏ธ Environment

  • Virtualization: VirtualBox
  • OS: Ubuntu Server (1 DHCP Server VM & 2 Client VMs)
  • Network mode: Internal Network + NAT (enp0s3 ignored for DHCP lab)

๐Ÿ› ๏ธ Network Setup

Interfaces

DHCP Server

  • enp0s8 -> 192.168.10.10/24 (Lab network)
  • enp0s3 -> NAT

Clients

  • enp0s8 -> DHCP assigned IPs
  • enp0s3 -> NAT (not used)

โš™๏ธ Network Configuration (Netplan)

Both server and clients are configured using Netplan, which defines interface behavior before DHCP starts.

๐Ÿ–ฅ๏ธ Client VM Netplan

sudo nano /etc/netplan/01-netcfg.yaml

Client Config

Meaning:

  • enp0s3 -> NAT IP automatically assigned
  • enp0s8 -> requests IP from DHCP server

๐Ÿ–ฅ๏ธ DHCP Server VM Netplan

sudo nano /etc/netplan/01-netcfg.yaml

Server Config

Meaning:

  • enp0s8 is STATIC (required for DHCP sever stability)
  • enp0s3 remains NAT
  • DHCP server must always have fixed IP in lab network

โš™๏ธ DHCP Server Configuration

sudo nano /etc/dhcp/dhcpd.conf

DHCP_Config


โš™๏ธ DHCP Server Interface Binding

Before DHCP can operate, it must bind to the correct interface:

sudo nano /etc/default/isc-dhcp-server

Network_interface


โœ… Validation Flow

Step 1 - Start DHCP Service

sudo systemctl start isc-dhcp-server

Check status:

sudo systemctl status isc-dhcp-server

DHCP_Status


Step 2 - Request IP

sudo dhclient -v enp0s8

DHCP_Request

Verify IP assignment:

ip a show enp0s8

Client_IP


Step 3 - Connectivity test

ping 192.168.10.100

Ping


๐Ÿงช Challenge 1 - DHCP Service Fails to Start (Wrong Interface Binding)

Edit config to create a subnet mismatch:

sudo nano /etc/default/isc-dhcp-server

INTERFACEv4="enp0s3"

Expected outcome:

  • DHCP service fails to start
  • Client stuck in DHCPDISCOVER
  • No IP assignment

๐Ÿ”ฅ Debugging

Step 1 - Check service:

systemctl status isc-dhcp-server

DHCP_Failure


Step 2 - Check logs:

sudo journalctl -u isc-dhcp-server

Error: No subnet declaration for enp0s3 (10.0.2.15)

Check Logs


๐Ÿง  Root Cause

  • DHCP is bound to enp0s3 (NAT)
  • No matching subnet config exists for that interface
  • Service cannot start

โœ… Remediation

Bind DHCP to correct interface:

sudo nano /etc/default/isc-dhcp-server

INTERFACEv4="enp0s8"

Restart the DHCP service:

sudo systemctl restart isc-dhcp-server

๐Ÿงช Challenge 2 - Pool Exhaustion

Edit dhcpd.conf to reduce the pool to a single IP:

sudo nano /etc/dhcp/dhcpd.conf

subnet 192.168.10.0 netmask 255.255.255.0 {
  range 192.168.10.100 192.168.10.100;
}

Expected outcome:

  • Client A -> gets IP
  • Client B -> stuck in DHCPDICOVER

Client2_DHCP_Offer


๐Ÿ”ฅ Debugging

Step 1 - Check service

systemctl status isc-dhcp-server

Interpretation

  • DHCP Service is running โœ…
  • DHCP is receiving requests โœ…
  • DHCP is refusing allocation โ—

DHCP_Status


Step 2 - Check logs

sudo journlctl -u isc-dhcp-server

Result:

  • repeated no free leases

Bug2


Step 3 - Check lease file

cat /var/lib/dhcp/dhcpd.leases

Result:

  • pool fully assigned
  • single active lease

Lease


๐Ÿง  Root Cause

  • Pool size = 1
  • Lease already assigned
  • No available IPs

DHCP is functioning correctly, but the IP pool is exhausted.


โœ… Remediation

Expand pool:

sudo nano /etc/dhcp/dhcpd.conf

range 192.168.10.100 192.168.10.200;

Restart the service:

sudo systemctl restart isc-dhcp-server

Client2_IP


๐Ÿง  Key lessons

  • Interface binding is critical
  • DHCP must match subnet to interface
  • Logs reveal root cause quickly

๐Ÿ”ฅ Debugging hierarchy

  1. Check service
  2. Check logs
  3. Check traffic
  4. Check leases
  5. Validate client