The DHCP protocol

  1. Quick summary
  2. Step 1 — DHCPDISCOVER — The client calls for help on the LAN
  3. Step 2 — DHCPOFFER — The server proposes an IP
  4. Step 3 — DHCPREQUEST — The client confirms the IP it chose
  5. Step 4 — DHCPACK — The server confirms officially (unicast)
  6. Step 5 — Lease renewal — Renewing before expiry
  7. Step 6 — DHCP Relay — when the server is on another subnet
  8. Step 7 — Debugging DHCP failures — cannot get an IP
  9. Step 8 — Conflict A — Manual first: the server protects itself with an ICMP ping-check
  10. Step 9 — Conflict B — Manual later: a Linux netplan static address with no DAD → ARP cache flap
  11. Step 10 — ARP Probe vs Gratuitous ARP + DHCPDECLINE → APIPA fallback
  12. Common misconceptions
  13. Lab 1 — Set up VMware + 3 VMs on VMnet1 host-only
  14. Lab 2 — Install and configure a minimal DHCP Server
  15. Lab 3 — Capture DORA and analyze the fields with tcpdump
  16. Lab 4 — Case A: Manual set first (Client2 static → Client1 DHCP)
  17. Lab 5 — Case B: Manual set later + the surprise of cloned VMs sharing a machine-id
  18. Lab 6 — Compare Case A vs Case B + Report
  19. Review questions
  20. Flashcards
  21. Related articles

Estimated time: 35 minutes.

Quick summary

Step 1 — DHCPDISCOVER — The client calls for help on the LAN

The client has just booted and has only a MAC address. It must broadcast because it has no IP yet — this is the mandatory starting point. Without the Discover, nothing else happens.

RFC 2131 §4.3.1 requires the client to broadcast DHCPDISCOVER with src IP = 0.0.0.0 (INADDR_ANY) while it has no address — this is the INIT state of the DHCP state machine.

It cannot unicast because it has no valid src IP, and it cannot send directly to the server because it does not know the server's IP. This is the mandatory starting point of the whole DORA flow.

When it breaks: If you do not see the Discover in tcpdump, the interface is not UP or dhclient is not running.

If you see the Discover but no Offer, the DHCP server is not listening on that interface or a firewall blocks UDP 67. These are two completely different failure modes that need different debugging.

# Capture DHCP traffic on a Linux VM
sudo tcpdump -i eth0 -n 'udp port 67 or udp port 68'

# Or with a Wireshark filter:
# udp.port == 67 || udp.port == 68

# Force the client to send a Discover right now (Debian/Ubuntu):
sudo dhclient -v eth0

Observe with:

sudo tcpdump -i any port 67 or port 68 -n — look for src=0.0.0.0 dst=255.255.255.255 on the Discover. Run sudo dhclient -v eth0 in another terminal at the same time to trigger DORA. journalctl -u dhclient -f shows the log in real time.

Step 2 — DHCPOFFER — The server proposes an IP

On receiving the Discover, the DHCP server picks a free IP in its pool (the range line in /etc/dhcp/dhcpd.conf) and sends a DHCPOFFER back to the client,

together with options such as the gateway (option routers), DNS (option domain-name-servers) and the lease duration (default-lease-time).

The server temporarily holds this IP while waiting for the client to confirm.

This is the step where the server decides what the client will get — so when you do not see an Offer, the first thing to check is whether the pool still has free IPs, via /var/lib/dhcp/dhcpd.leases.

When it breaks: An exhausted pool is the most common reason a server sends no Offer. Every cloned dev VM that does not release its lease → after a few months the .50-.200 pool is completely full.

Sign: dhcpd.leases has hundreds of entries, many already expired but not yet reaped by the server.

# View the DHCP pool configuration (isc-dhcp-server)
cat /etc/dhcp/dhcpd.conf

# View the server's current leases
cat /var/lib/dhcp/dhcpd.leases

# Example pool configuration:
# subnet 192.168.1.0 netmask 255.255.255.0 {
#   range 192.168.1.50 192.168.1.200;
#   option routers 192.168.1.1;
#   option domain-name-servers 8.8.8.8;
#   default-lease-time 86400;
# }

Observe with:

cat /var/lib/dhcp/dhcpd.leases | grep -c 'lease' — count the leases. grep 'binding state active' /var/lib/dhcp/dhcpd.leases | wc -l — count the active leases. Compare with the pool size to see how many IPs are still free.

Symptoms when it breaks:

How to fix:

  1. Count the active leases and compare with the pool size to confirm the pool is exhausted

grep -c 'binding state active' /var/lib/dhcp/dhcpd.leases
  1. Find leases that have expired but not been reaped (usually from cloned VMs that never released them)

awk '/lease/{ip=$2} /binding state active/{print ip}' /var/lib/dhcp/dhcpd.leases | sort -u | wc -l
  1. Restart dhcpd to force it to reap expired leases (short term), or widen the pool range in dhcpd.conf

sudo systemctl restart isc-dhcp-server && sudo journalctl -u isc-dhcp-server -n 20

Script it: Cron: */15 * * * * /usr/local/bin/dhcp-pool-monitor.sh 151. Adjust POOL_SIZE to match the range in dhcpd.conf.

#!/bin/bash
# Monitor DHCP pool usage, alert when more than 80% is full
# Run from cron every 15 minutes
LEASE_FILE="/var/lib/dhcp/dhcpd.leases"
POOL_SIZE=${1:-151}  # range .50-.200
ACTIVE=$(grep -c 'binding state active' "$LEASE_FILE" 2>/dev/null || echo 0)
PCT=$(( ACTIVE * 100 / POOL_SIZE ))
echo "[$(date '+%Y-%m-%d %H:%M')] DHCP pool: $ACTIVE/$POOL_SIZE leases active ($PCT%)"
if [ "$PCT" -gt 80 ]; then
  logger -t dhcp-monitor "WARN: DHCP pool ${PCT}% full ($ACTIVE/$POOL_SIZE)"
  echo "WARN: Pool ${PCT}% full — consider expanding range in dhcpd.conf"
fi

Step 3 — DHCPREQUEST — The client confirms the IP it chose

The client broadcasts the Request so that every DHCP server on the LAN knows which server it chose. The servers that were not chosen release the IPs they had reserved.

This is the 'public announcement' step that avoids IP conflicts.

RFC 2131 §4.3.2 requires a DHCPREQUEST following an Offer to be sent as a broadcast (not unicast to the chosen server),

together with the Server Identifier option (option 54) so that the other DHCP servers know which server was chosen.

The servers that were not chosen receive the Request and release the IP they were holding — this mechanism prevents IP leaks when there are several servers on the LAN.

When it breaks: If Wireshark shows Discover → Offer → Request but no Ack: the IP the client chose may already be in conflict (another machine is using it) or the server state is inconsistent after a restart.

The server will send a DHCPNAK — look for a DHCPNAK packet type in the capture.

# View the interface's current IP (after DORA completes)
ip addr show eth0

# View the DHCP lease the client is holding (NetworkManager)
nmcli device show eth0 | grep -E 'IP4|DHCP'

# View the client's lease file
cat /var/lib/dhcp/dhclient.leases

Observe with:

sudo tcpdump -i any port 67 or port 68 -n -vv | grep -E 'DHCP|Discover|Offer|Request|ACK|NAK' — filter out the DORA steps. Look at the 'DHCP-Message Option 53' field in the verbose output to tell each message type apart.

Step 4 — DHCPACK — The server confirms officially (unicast)

DHCPACK is the server's official confirmation: the IP the client chose is recorded as a lease, together with network parameters such as the gateway, DNS and the lease duration.

Only after receiving the ACK does the client actually assign the IP to the interface, create the default route and write the nameserver.

So checking the outcome of DORA has to cover three places: ip addr (IP), ip route (gateway) and /etc/resolv.conf (DNS) — having an IP does not necessarily mean you can reach the network.

When it breaks: You received an ACK but ip addr shows no IP: dhclient crashed after receiving the ACK (check journalctl -u dhclient).

Or the gateway in the ACK is on the wrong subnet → ip route cannot create a default route → you have an IP but cannot reach the internet.

# Verify the IP assigned after DORA
ip addr show eth0
ip route  # Is there a gateway yet?
cat /etc/resolv.conf  # Is DNS configured yet?

# Ping the gateway to verify connectivity
ping -c 1 $(ip route | awk '/default/ {print $3}')

Observe with:

ip addr show eth0 | grep 'inet ' — you must see the IP with the 'dynamic' flag. ip route show default — there must be a default route through the gateway. cat /etc/resolv.conf — there must be a nameserver. Ping all 3 levels: the gateway, 8.8.8.8, google.com.

Step 5 — Lease renewal — Renewing before expiry

No renewal = the IP is reclaimed = the network connection drops abruptly. T1 and T2 are buffers that prevent service interruption.

Understanding this mechanism helps you debug 'the network drops by itself after a few hours/days'.

RFC 2131 §4.4.5 defines T1 (50% of the lease) and T2 (87.5% of the lease) as 2 renewal checkpoints before the IP is reclaimed.

If renewal fails at both T1 and T2, then at 100% of the lease the client must release the IP and start over from the INIT state.

A network that drops suddenly after a few hours is usually caused by a lease expiring while the DHCP server was unreachable — knowing T1/T2 helps you debug at the right moment.

When it breaks: A VM is suspended overnight and then woken up: the lease expired while it slept.

On wake, the client tries to rebind with its old IP, but the server has reclaimed it and given it to another machine → DHCPNAK → DORA again. Sign: the network drops for 2-5 seconds on wake from sleep.

# View the remaining lease time (dhclient)
sudo dhclient -v -r eth0  # Release
sudo dhclient -v eth0     # Renew (DORA again)

# View lease details
cat /var/lib/dhcp/dhclient.leases | grep -A10 'lease'

# Check the expiry time
ip -details addr show eth0

Observe with:

journalctl -u dhclient --since '1 hour ago' | grep -E 'DHCP|bound|renew|expire' — view the renewal history. cat /var/lib/dhcp/dhclient.leases | grep -A5 'expire' — view the expiry time of the current lease.

Step 6 — DHCP Relay — when the server is on another subnet

DHCPDISCOVER is a broadcast, so it can only travel within a single broadcast domain — routers do not forward broadcasts to other subnets.

When the DHCP server sits on a different subnet/VLAN, you need a relay agent (isc-dhcp-relay on Linux or ip helper-address on a Cisco router) that receives the client's broadcast and forwards it as unicast to the DHCP server's IP.

That is why, on the server, DHCP packets arrive from the relay's IP rather than the client's. Every new VLAN needs relay configuration, otherwise none of the machines in that VLAN can get an IP.

When it breaks: You add a new VLAN but forget to configure ip helper-address on the router → none of the VMs in the new VLAN can get an IP.

Debug: first ping from the router to the DHCP server, then check the relay config. A common mistake: SERVERS in the relay config points to the wrong server IP.

# Configure the relay agent (isc-dhcp-relay)
sudo apt install isc-dhcp-relay

# /etc/default/isc-dhcp-relay
# SERVERS="10.0.0.1"  # DHCP server IP
# INTERFACES="eth0 eth1"  # Interfaces to relay

# Verify the relay is running
sudo systemctl status isc-dhcp-relay

# Cisco router (ip helper-address)
# interface GigabitEthernet0/1
#   ip helper-address 10.0.0.1

Observe with:

sudo tcpdump -i eth0 port 67 -n on the relay agent — see the DHCP packets arriving at the interface and the relay forwarding them on. On the DHCP server: sudo tcpdump -i any port 67 -n to see whether it receives packets from the relay agent IP (the src will be the relay's IP, not the client's IP).

Symptoms when it breaks:

How to fix:

  1. Check whether INTERFACES in the relay config includes the new VLAN interface

cat /etc/default/isc-dhcp-relay | grep INTERFACES
  1. Add the VLAN interface to the relay and restart

sed -i 's/INTERFACES="/INTERFACES="eth0.20 /' /etc/default/isc-dhcp-relay && sudo systemctl restart isc-dhcp-relay

Step 7 — Debugging DHCP failures — cannot get an IP

The practical goal of the DHCP lab: being able to debug when something goes wrong. Know the DORA flow → know which step the error is in. No Offer → the server is dead or the pool is exhausted.

An Offer but no Ack → a conflict or a wrong server configuration.

When it breaks: Debug checklist, in order: (1) Is the interface UP? → ip link. (2) Is the Discover going out? → tcpdump. (3) Does an Offer come back? → if not, it is a server/pool problem.

(4) Does an Ack come back? → if not, it is a NAK/conflict. (5) Is the IP applied? → ip addr. Skipping any step means debugging blind.

# 1. Check whether the interface is UP (L1/L2)
ip link show eth0

# 2. Force DORA and look at the verbose output
sudo dhclient -v eth0 2>&1

# 3. Capture to see which step fails
sudo tcpdump -i eth0 -n -vv 'udp port 67 or udp port 68'

# 4. If there is no Offer: check that the DHCP server is running
# sudo systemctl status isc-dhcp-server

# 5. Fallback: set a temporary static IP
sudo ip addr add 192.168.1.99/24 dev eth0
sudo ip route add default via 192.168.1.1

Observe with:

journalctl -u dhclient -f — the DHCP client's real-time log, showing each DORA step and clear error messages. Combine it with sudo tcpdump -i any port 67 or port 68 -n in another terminal to see the packet level at the same time.

Step 8 — Conflict A — Manual first: the server protects itself with an ICMP ping-check

ISC dhcpd with the option `ping-check true` sends an ICMP echo to the IP it is about to hand out before the OFFER.

If there is a reply (a machine is already using that IP) → the server abandons the IP and tries the next one in the pool.

Reference: RFC 2131 §4.3.1 (the server MAY probe before the OFFER).

This mechanism only works when dhcpd has CAP_NET_RAW (running as root) — details in the When it breaks item right below.

When it breaks: A silent failure if dhcpd runs as the non-root user dhcpd (the default systemd unit on Ubuntu 24.04) — the process loses CAP_NET_RAW → it cannot send the ICMP echo → ping-check is silently disabled altogether.

The server still hands out an IP that a statically configured machine is occupying → two machines with the same IP → ARP flapping in production.

Verify: grep CapEff /proc/$(pidof dhcpd)/status must be 000001ffffffffff; if it is 0000000000000800 → it is running as user dhcpd → you need a systemd drop-in.

# === Server setup ===
# 1. Enable ping-check in dhcpd.conf
sudo tee /etc/dhcp/dhcpd.conf >/dev/null <<'EOF'
default-lease-time 120;
max-lease-time 300;
authoritative;
ping-check true;
ping-timeout 1;
subnet 192.168.81.0 netmask 255.255.255.0 {
  range 192.168.81.200 192.168.81.201;
  option routers 192.168.81.2;
  option domain-name-servers 8.8.8.8, 1.1.1.1;
}
EOF

# 2. systemd drop-in so dhcpd runs as ROOT (CAP_NET_RAW)
sudo mkdir -p /etc/systemd/system/isc-dhcp-server.service.d
sudo tee /etc/systemd/system/isc-dhcp-server.service.d/override.conf >/dev/null <<'EOF'
[Service]
ExecStart=
ExecStart=/usr/sbin/dhcpd -f -4 -pf /run/dhcp-server/dhcpd.pid \
  -cf /etc/dhcp/dhcpd.conf ens33
EOF
sudo chown root:root /var/lib/dhcp /var/lib/dhcp/dhcpd.leases
sudo systemctl daemon-reload
sudo systemctl restart isc-dhcp-server

# 3. Verify CapEff (MUST be 000001ffffffffff)
grep CapEff /proc/$(pidof dhcpd | awk '{print $1}')/status

# === Trigger the scenario ===
# Client2 manual .200 → server wipes the lease → Client1 fresh DISCOVER
# (detailed commands are the same as steps 1–4 of Lab 4)

Observe with:

Server log: `journalctl -u isc-dhcp-server | grep -E 'DHCP|ICMP|aban'` shows the sequence: `DHCPDISCOVER from <MAC>` → `ICMP Echo reply while lease 192.168.81.200 valid` → `Abandoning IP address 192.168.81.200: pinged before offer` → `DHCPOFFER on 192.168.81.201`. The full pcap filter `bootp or icmp`: DISCOVER → ICMP echo (server→.200) → ICMP reply (Client2→server) → OFFER .201 → REQUEST → ACK.

Symptoms when it breaks:

How to fix:

  1. Verify dhcpd's CapEff

grep CapEff /proc/$(pidof dhcpd | awk '{print $1}')/status
  1. If Uid != 0: create a systemd drop-in that runs it as root

sudo systemctl edit isc-dhcp-server  # paste [Service] ExecStart= + ExecStart=/usr/sbin/dhcpd -f -4 -pf /run/dhcp-server/dhcpd.pid -cf /etc/dhcp/dhcpd.conf ens33
  1. Reload + restart + verify

sudo systemctl daemon-reload && sudo systemctl restart isc-dhcp-server && grep CapEff /proc/$(pidof dhcpd | awk '{print $1}')/status

Step 9 — Conflict B — Manual later: a Linux netplan static address with no DAD → ARP cache flap

When Client1 already holds a DHCP lease for IP X and Client2 sets a static address of the same IP X:

the DHCP server does not detect it (it already ACKed Client1 and does not re-check). systemd-networkd assigns the static address immediately —

by default it does NOT run IPv4 Address Conflict Detection for static IPs (DuplicateAddressDetection= defaults to none for IPv4 outside link-local),

and because the address did not come from DHCP there is no DHCPDECLINE either, and NO clear warning is logged.

Both machines claim the IP → every ARP request gets 2 replies from 2 different MACs.

Reference: RFC 5227 §2.1.1 (DAD is recommended but Linux does not enforce it).

When it breaks: Production consequences: TCP sessions break because reply traffic sometimes goes to machine A and sometimes to machine B; the L2 switch keeps updating its CAM table → CPU spikes + packet loss.

It is hard to debug because there is no error message; all you see is 'the network is flaky'.

Practical prevention (NOT a client-side fix): DHCP snooping + Dynamic ARP Inspection (DAI) on the switch + IPAM that tracks static IPs.

# === Prerequisite ===
# Client1 holds the DHCP IP .201 (via DHCPACK). The server no longer intervenes.

# === Create the conflict ===
# Client2: create a netplan static .201 (SAME IP as Client1)
sudo tee /etc/netplan/50-cloud-init.yaml >/dev/null <<'EOF'
network:
  version: 2
  renderer: networkd
  ethernets:
    ens33:
      dhcp4: no
      addresses: [192.168.81.201/24]
      routes:
        - {to: default, via: 192.168.81.2}
EOF
sudo chmod 600 /etc/netplan/50-cloud-init.yaml
sudo netplan apply
ip -br a show ens33   # Expected: ens33 ... 192.168.81.201/24

# === Observe the ARP flap ===
# On the server (.128), an arping loop will show 2 different MACs replying
for i in 1 2 3 4 5 6; do
  sudo arping -c 2 -w 1 -I ens33 192.168.81.201
  sleep 1
done

# Tcpdump to see the packet level:
sudo tcpdump -i ens33 -n -e arp host 192.168.81.201

# === Client-side mitigation (NOT enough for production) ===
echo 'net.ipv4.conf.all.arp_ignore=1' | sudo tee -a /etc/sysctl.d/99-arp.conf
echo 'net.ipv4.conf.all.arp_announce=2' | sudo tee -a /etc/sysctl.d/99-arp.conf
sudo sysctl --system

Observe with:

The arping output alternates between 2 MACs: `Unicast reply from 192.168.81.201 [00:0C:29:C4:F1:BE]` (Client1) and `[00:0C:29:4C:8B:DA]` (Client2). The pcap filter `arp.dst.proto_ipv4 == 192.168.81.201` clearly shows 2 different source MACs claiming it. The DHCP server log STILL has no warning at all (because it does not know about the conflict). `journalctl -k --since '2 min ago' | grep -iE 'ipv4|arp'` sometimes (not always) shows `IPv4: ... sent an invalid ARP reply`, depending on the kernel version.

Symptoms when it breaks:

How to fix:

  1. Restart networkd to force the netplan to apply

sudo systemctl restart systemd-networkd && sleep 2 && ip -br a show ens33
  1. Production-grade fix: enable DHCP snooping + DAI on the switch (Cisco IOS example)

switch(config)# ip dhcp snooping
switch(config)# ip dhcp snooping vlan 10
switch(config)# ip arp inspection vlan 10
switch(config-if)# ip dhcp snooping trust   # on the uplink port to the DHCP server

Step 10 — ARP Probe vs Gratuitous ARP + DHCPDECLINE → APIPA fallback

Besides the server's ping-check (step 8), the client has its own self-protection mechanism — ARP Probe (RFC 5227): before assigning an IP,

it sends an ARP Request with Sender IP = 0.0.0.0 to ask 'is anyone using this IP?'.

If there is a reply → it refuses to assign the IP and sends a DHCPDECLINE → the server abandons that IP.

After the DECLINE, dhcpcd falls back to APIPA 169.254.0.0/16 (RFC 3927 link-local).

Keep this clearly distinct from Gratuitous ARP (Sender IP = Target IP) — the same opcode 1, but with opposite purposes.

When it breaks: systemd-networkd runs IPv4 ACD (ARP Probe) only for addresses obtained from DHCP, and sends a DHCPDECLINE when it sees a duplicate only if SendDecline=yes is set in [DHCPv4] —

the default is no, so by default it just assigns the IP and creates a real conflict (Lab 4 turns this option on).

For statically configured IPs, networkd does not probe and sends nothing. dhcpcd, by contrast, probes + DECLINEs out of the box per the RFC.

This is why Case B (a static IP duplicating an issued IP) shows ARP flapping with NO DECLINE in tcpdump — students easily conclude 'the lab failed', when in fact client behavior simply differs.

# === ARP Probe — the client checks the IP before assigning it ===
# On Client2, set a manual IP that has not been issued (e.g. 192.168.81.105)
sudo ip addr add 192.168.81.105/24 dev ens33

# On the server, tcpdump to capture ARP
sudo tcpdump -i ens33 arp -n
# Expected packet:
#   ARP, Request who-has 192.168.81.105 tell 0.0.0.0  ← ARP Probe!
# Sender IP = 0.0.0.0 is characteristic of RFC 5227 — it does NOT pollute ARP caches

# === Gratuitous ARP — announcing an IP ===
# On the Server, simulate a claim on .106 (already issued to Client1)
sudo arping -I ens37 -c 5 -s 192.168.81.106 192.168.81.106
# Tcpdump shows:
#   ARP, Request who-has 192.168.81.106 tell 192.168.81.106  ← Gratuitous
# Sender IP = Target IP — updates every machine's ARP cache: .106 → new MAC

# === DHCPDECLINE → APIPA (dhcpcd only) ===
# Setup: Client2 already has static .100, the server hands .100 to Client1
sudo systemctl stop systemd-networkd systemd-networkd.socket
sudo rm -f /run/systemd/netif/leases/*
sudo ip addr flush dev ens33
sudo ip link set ens33 down && sleep 1 && sudo ip link set ens33 up && sleep 1
sudo dhcpcd -1 -t 20 ens33

# dhcpcd stdout:
#   ens33: offered 192.168.81.100
#   ens33: probing address 192.168.81.100
#   ens33: DAD detected 00:0c:29:4c:8b:da using 192.168.81.100
#   ens33: 192.168.81.100 declined
#   ens33: probing for an IPv4LL address
#   ens33: leased 169.254.X.Y for infinity   ← APIPA fallback

# Server log:
#   DHCPDECLINE of 192.168.81.100 from <MAC C1>: abandoned

Observe with:

Useful Wireshark filters: `arp.opcode == 1 && arp.src.proto_ipv4 == 0.0.0.0` (ARP Probe only), `arp.src.proto_ipv4 == arp.dst.proto_ipv4` (Gratuitous only). DHCPDECLINE: filter `bootp.option.dhcp == 4`. The APIPA address is visible via `ip addr show ens33` as an IP in the `169.254.x.x` range — with no default route.

Symptoms when it breaks:

How to fix:

  1. Install dhcpcd if it is missing

# Needs internet: install while the VM is still on NAT (Lab 1) or temporarily attach a NAT adapter
sudo apt install -y dhcpcd-base
  1. Production fix: enable strict DAD on every DHCP client + DHCP snooping on the switch

echo 'net.ipv4.conf.all.arp_ignore=1\nnet.ipv4.conf.all.arp_announce=2\nnet.ipv4.conf.all.arp_accept=0' | sudo tee /etc/sysctl.d/99-dad-strict.conf && sudo sysctl --system

Common misconceptions

Right: RFC 2131 §4.1 specifies that the ACK is unicast by default, to the MAC address + the IP just allocated to the client;

it is broadcast only when the client sets the BROADCAST flag (bit B) in the DHCPREQUEST.

Most modern clients do not set this flag.

Debugging in Wireshark with a broadcast filter will miss the unicast DHCP ACK — leading to the wrong conclusion that 'there is no ACK'.

Use a broader filter: udp port 67 or udp port 68 to capture both unicast and broadcast.

Right: An Offer is only a proposal; the server has not yet committed it to the lease database.

The IP is officially assigned only after the client sends a Request and receives an ACK (RFC 2131 §4.3.1).

If the client crashes after the Offer but before the Request, the server reclaims the IP after a timeout.

A misunderstanding here sends DHCP debugging in the wrong direction: you see the Offer in tcpdump, assume the IP was issued, and never investigate why the Request or ACK is missing.

DORA must complete all 4 steps.

Right: The DHCPDISCOVER broadcast does not cross routers — each subnet needs its own DHCP server,

or a Relay Agent configured with ip helper-address pointing to the central server (RFC 2131 §4.1.2).

Add a new VLAN without configuring a relay agent → none of the VMs in that VLAN can get an IP, and they show 169.254.x.x (APIPA).

It is a silent failure with no clear error message — you only see the Discover broadcast with no Offer.

Right: The client has 2 chances to renew before losing its IP: T1=50% of the lease (unicast renew) and T2=87.5% of the lease (broadcast rebind), per RFC 2131 §4.4.5.

It loses its IP only when 100% of the lease expires without any DHCP server responding at either T1 or T2.

Panicking when you see the log 'T1 renewal failed' is wrong — the client still has a chance to rebind at T2.

Only alert when T2 rebinds keep failing; that is the sign of a real problem in the DHCP infrastructure.

Right: RFC 2131 §4.3.2 specifies that the DHCPREQUEST must still be broadcast with the Server Identifier option —

so that ALL DHCP servers on the LAN learn the outcome and release the IPs they were holding.

A unicast DHCPREQUEST is used only for renewal (the T1 phase), not the first one after an Offer.

A misunderstanding here leaves you unable to explain why having several DHCP servers on a LAN is still safe — the broadcast Request announces the choice publicly to everyone, which prevents IP leaks from servers that were not chosen.

Right: On Ubuntu 24.04, ISC dhcpd runs by default as the non-root user dhcpd (systemd unit) → the process loses CAP_NET_RAW → it cannot send the ICMP echo → ping-check is silently disabled.

Verification is mandatory: grep CapEff /proc/$(pidof dhcpd)/status MUST be 000001ffffffffff when running as root.

If the value is lower (the exact value depends on the kernel/unit/cap-bound) → it is running as user dhcpd without CAP_NET_RAW → you need a systemd drop-in override of ExecStart= to run it as root (see walkthrough step 8).

Students testing scenario Case A (manual FIRST) sometimes see the IP still handed out correctly (thanks to random pool order) and think ping-check works — it is actually failing silently.

In production: you see 2 machines with the same IP and cannot understand why the server 'ignores' the ping-check setting you enabled.

Right: systemd-networkd uses a raw AF_PACKET socket (L2) to receive DHCP — it bypasses iptables INPUT entirely because iptables only handles packets that have passed the netfilter NF_INET hook (L3+).

You must use the nftables netdev/ingress hook with priority -300 (running at L2 before AF_PACKET) or disable the rogue DHCP at its source (Virtual Network Editor → VMnet8 → uncheck Use local DHCP service).

In the default VMware Workstation lab: the VMnet8 NAT has its own DHCP at .254 that muscles into the OFFER race with the lab's DHCP server.

If you only block with iptables → the client still receives an IP from the VMware DHCP → the whole lab fails and you cannot understand why the filter 'does not work'.

The right command: nft -f - <<NFT\ntable netdev dhcpfilter { chain ingress { type filter hook ingress device "ens33" priority -300; ip saddr != 192.168.81.128 udp sport 67 counter drop } }\nNFT.

Right: networkd caches the lease at /run/systemd/netif/leases/ → on restart it performs INIT-REBOOT (sending a DHCPREQUEST for the old IP) rather than a DISCOVER.

If the server has no matching lease → NAK.

To force a real DISCOVER: sudo rm -f /run/systemd/netif/leases/* + sudo ip addr flush dev ens33 + sudo ip link set ens33 down/up + sudo dhcpcd -1 -B ens33 (one-shot, no daemon).

If a capture shows only REQUEST/ACK (2 packets) instead of DORA (4 packets) → students think the DHCP server configuration is wrong and spend the whole session debugging in the wrong direction.

In reality, the client is doing INIT-REBOOT without anyone knowing. This is a trap every time you want to demo a full DORA capture in the lab.

Right: systemd-networkd assigning a static IP **does not run ACD** (by default), sends no DHCPDECLINE and logs no warning; for DHCP addresses it only probes + DECLINEs when SendDecline=yes is set.

Both machines claim the IP → every ARP request gets 2 replies from 2 different MACs → ARP cache flap.

The sysctl `arp_announce=2; arp_ignore=1` (client-side) reduces it but is NOT enough — only DHCP snooping + Dynamic ARP Inspection (DAI) on the switch (RFC 7039) stops it for good.

Believing Linux handles conflicts by itself → not enabling DHCP snooping/DAI on the switch → the production network keeps dropping whenever a user mistypes an IP.

It is very hard to debug because there is no specific error log, only 'the network is flaky'.

The Case B lab demonstrates this directly: 2 clients claim .201 and arping shows 2 MACs replying in turn.

Right: Both are ARP Request (opcode 1) broadcasts BUT they differ completely in the **Sender IP**: ARP Probe (RFC 5227) has `Sender IP = 0.0.0.0` (asking 'is anyone using IP X?'

before assigning it, without polluting anyone else's ARP cache); Gratuitous ARP has `Sender IP = Target IP` (announcing 'IP X is mine' to update every machine's ARP cache).

The purposes are completely opposite.

Telling them apart wrongly leads to misreading Wireshark: you see who-has 192.168.X tell 0.0.0.0 and take it for an attack (because a zero Sender IP looks odd), when it is actually standard RFC client behavior.

Or you see who-has X tell X and take it for a Probe → a wrong conclusion about the conflict detection mechanism.

Wireshark filters that tell them apart: arp.src.proto_ipv4 == 0.0.0.0 (Probe) vs arp.src.proto_ipv4 == arp.dst.proto_ipv4 (Gratuitous).

Right: Only `dhcpcd` and a few other clients (`udhcpc -t`) send a DECLINE per RFC 2131 §4.4.1.

By default (`SendDecline=no`), `systemd-networkd` does **NOT** run ACD for DHCP addresses, so it does not detect the duplicate and sends no DECLINE — it just assigns the IP,

creating a real conflict on the LAN; with `SendDecline=yes`, networkd probes ARP and DECLINEs per the RFC (Lab 4).

For static IPs, no client sends a DECLINE. NetworkManager behaves differently depending on its version.

Consequence: in Case B (a duplicate static IP) you see no DECLINE in tcpdump and may think the lab failed.

Test Case B with the default systemd-networkd client → no DECLINE → the student thinks the 'client-side self-protection' mechanism does not exist.

The mechanism does exist, but it has to be enabled: networkd probes DHCP addresses only when SendDecline=yes, and never probes static IPs.

To demo the full chain ARP Probe → DAD → DECLINE → APIPA fallback, use dhcpcd -1 ens33. This is a major implementation difference between Linux distros.

Right: 169.254.0.0/16 is the standard IANA link-local range (RFC 3927).

It is a **legitimate fallback** when: (1) the DHCP server is unreachable → APIPA (Windows / dhcpcd auto-assign); (2) after a DHCPDECLINE → dhcpcd `probing for an IPv4LL address`.

A machine using APIPA can only communicate within the same L2 segment and has no default route → it cannot reach the internet.

Blocking this range = blocking a legitimate fallback + zero-config networking.

Seeing 169.254.x.x on a client is a sign that the DHCP infrastructure has a problem (server down, pool exhausted, a wrong filter...) — debug the ROOT cause, do not block the IP.

It is also useful for diagnosing a cluster: if several nodes suddenly show 169.254, the DHCP server on that subnet has a problem.

The Case B lab with dhcpcd demonstrates the APIPA fallback after a DECLINE directly — it is the CORRECT behavior, not an error.

Lab 1 — Set up VMware + 3 VMs on VMnet1 host-only

20 minutes

Separate the DHCP lab onto its own host-only network (VMnet1) so that (1) our DHCP server does not race the VMware NAT's DHCP for the OFFER, and (2) the lab traffic is kept apart from the office network.

The Server needs a static IP so the Clients can point to it as the gateway + DHCP server.

This exercise uses 192.168.81.10/24 for the Server because .1 is already taken by the VMware host adapter by default.

VMnet1 host-only has no internet.

So while the 3 VMs still have a NAT adapter attached (the default when a VM is created), pre-install every package this exercise uses, and only then switch the adapter to VMnet1 in step 2.

# 0. While the VM is still on NAT (has internet): pre-install packages for the whole lab
# On the Server:
sudo apt update && sudo apt install -y isc-dhcp-server tcpdump iputils-arping
#   (isc-dhcp-server may report a start error because it is not configured yet — that is normal, it is configured in Lab 2)
# On Client1 and Client2:
sudo apt update && sudo apt install -y dhcpcd-base tcpdump iputils-arping
# Power off the VM, and only then change the Network Adapter to VMnet1

# On the host (Windows): VMware Workstation → Edit → Virtual Network Editor
#   VMnet1 → Host-only → Subnet 192.168.81.0/24 → turn off 'Use local DHCP service'

# On the Server VM (console or SSH):
sudo nano /etc/netplan/50-cloud-init.yaml
#   network:
#     version: 2
#     renderer: networkd
#     ethernets:
#       ens33:
#         dhcp4: false
#         addresses: [192.168.81.10/24]
sudo chmod 600 /etc/netplan/50-cloud-init.yaml
sudo netplan apply
ip -br link
ip -br a

# (If the old IP is still there): check for a conflicting netplan file
ls -la /etc/netplan/
sudo cat /etc/netplan/*.yaml
# Move the conflicting file to /tmp and apply again
sudo mv /etc/netplan/99-lab.yaml /tmp/99-lab.yaml.bak
sudo netplan apply
sudo ip addr del 192.168.81.128/24 dev ens33 2>/dev/null

Observe: ip -br a show ens33 shows only 1 IP, 192.168.81.10/24 (no old cached IP). ls /etc/netplan/ leaves only 1 netplan file referencing ens33.

1. Open VMware Workstation → Edit menu → Virtual Network Editor (admin required). Select VMnet1 in the list.

Verify: Type=Host-only, Subnet=192.168.81.0/24, and the checkbox 'Use local DHCP service to distribute IP addresses to VMs' is UNCHECKED.

The DHCP column in the list shows - (empty) for VMnet1. In the bottom panel: Subnet IP 192.168.81.0, Subnet mask 255.255.255.0, DHCP checkbox unchecked.

VMware Virtual Network Editor — VMnet1 host-only, DHCP service disabled

*Virtual Network Editor (VMware Workstation Pro 25H2): VMnet1 host-only, subnet 192.168.81.0/24, Use local DHCP service unchecked.

Turning off VMware's DHCP lets our ISC dhcpd be the only one issuing IPs on VMnet1. *

2. Open the Server's VM Settings (right-click the VM in VMware Workstation → Settings). Hardware tab → Network Adapter. Verify: Custom: Specific virtual network → VMnet1 (Host-only).

Verify the same for Client1 and Client2.

The VM Settings dialog shows the Server's Network Adapter attached to VMnet1 host-only (not NAT/Bridged).

VMware VM Settings — Server Network Adapter custom VMnet1 Host-only

*Server VM settings: the Network Adapter is set to Custom: VMnet1 (Host-only). Client1/Client2 are configured the same way.

All 3 VMs are on the same VMnet1 with no internet uplink — exactly the sandbox lab requirement. *

3. On the Server VM, set the static IP 192.168.81.10/24 via netplan.

Edit /etc/netplan/50-cloud-init.yaml with sudo nano with this content: dhcp4: false + addresses: [192.168.81.10/24] for ens33. Then chmod 600 + sudo netplan apply.

ip -br a on the Server shows only ens33 UP 192.168.81.10/24 .... If you also see the old IP (e.g.

.128) → check for a conflicting netplan file, move the extra file to /tmp, run netplan apply again, and ip addr del the old IP.

Server VM ip -br a output showing single IP 192.168.81.10/24 on ens33

*The Server VM after applying netplan: ens33 UP 192.168.81.10/24 only. This will be the gateway + DHCP server IP for VMnet1. Note: .1 is taken by the VMware host adapter, so the Server uses .10.

Troubleshooting:

Lab 2 — Install and configure a minimal DHCP Server

15 minutes

ISC dhcpd is the reference implementation of RFC 2131. The minimal configuration needs only subnet + range + option routers + option domain-name-servers for a Client to get an IP.

No NAT and no ping-check is needed in this phase — keep it KISS so DORA is proven to work first, and extend later (ping-check in Step 8).

# 1. The packages were installed in Lab 1 (while the VM was on NAT) — check again
dpkg -l isc-dhcp-server tcpdump | grep '^ii'

# 2. Enable listening on ens33
sudo nano /etc/default/isc-dhcp-server
#   INTERFACESv4="ens33"
#   INTERFACESv6=""

# 3. Minimal dhcpd.conf configuration (10 lines)
sudo nano /etc/dhcp/dhcpd.conf
#   default-lease-time 120;
#   max-lease-time 300;
#   authoritative;
#   log-facility local7;
#   subnet 192.168.81.0 netmask 255.255.255.0 {
#     range 192.168.81.100 192.168.81.110;
#     option routers 192.168.81.10;
#     option domain-name-servers 8.8.8.8, 1.1.1.1;
#     option broadcast-address 192.168.81.255;
#   }

# 4. Verify the syntax
sudo dhcpd -t -cf /etc/dhcp/dhcpd.conf

# 5. Restart + check
sudo systemctl restart isc-dhcp-server
sudo ss -ulnp | grep :67

Observe: On the Server: dhcpd -t shows 'Config file: /etc/dhcp/dhcpd.conf' along with 'Database file:' and 'PID file:' (no errors). ss -ulnp shows dhcpd LISTENing on UDP port 67.

On Client1 after boot: ip -br a shows ens33 with the IP 192.168.81.100/24 (the first IP in the pool).

1. On the Server: check that isc-dhcp-server and tcpdump were installed in Lab 1 (dpkg -l isc-dhcp-server tcpdump).

Then set the listen interface via /etc/default/isc-dhcp-server: INTERFACESv4="ens33" + INTERFACESv6="".

which dhcpd → /usr/sbin/dhcpd. cat /etc/default/isc-dhcp-server has only 2 lines, INTERFACESv4 + INTERFACESv6.

2. Edit /etc/dhcp/dhcpd.conf with the 10 minimal lines: default-lease-time 120, authoritative, subnet 192.168.81.0/24 with range .100 .110 + option routers 192.168.81.10 (the Server acts as the gateway).

cat /etc/dhcp/dhcpd.conf shows exactly those 10 lines. A pool of 11 IPs (.100 → .110) is enough for 2-3 demo Clients.

cat /etc/dhcp/dhcpd.conf showing the 10 lines of the minimal configuration

Minimal dhcpd.conf: subnet 192.168.81.0/24, pool .100-.110, 120s lease, gateway .10, public DNS. No ping-check (see Step 8).

3. Verify the syntax: sudo dhcpd -t -cf /etc/dhcp/dhcpd.conf. If it is OK → sudo systemctl restart isc-dhcp-server + sudo ss -ulnp | grep :67 to confirm dhcpd is listening on UDP 67.

dhcpd -t prints 'Config file: /etc/dhcp/dhcpd.conf' (with the Database/PID file), and NO line starting with 'error'. ss shows dhcpd LISTENing on 0.0.0.0:67.

sudo dhcpd -t -cf output success — Config file/Database file/PID file lines, no error

dhcpd -t passes: it shows the Config file path + the Database file /var/lib/dhcp/dhcpd.leases + the PID file /var/run/dhcpd.pid. This is a mandatory gate before systemctl restart.

4. On Client1 (a new VM, Network Adapter Custom VMnet1, default cloud-init netplan dhcp4: true): boot the VM. Log in on the console. Run ip -br a.

ens33 UP 192.168.81.100/24 metric 100 fe80::... — Client1 has completed DORA and received the first pool IP .100.

On the Server: sudo cat /var/lib/dhcp/dhcpd.leases | tail -10 shows a lease entry for Client1's MAC.

Client1 booted, login dhcp-client-1, ip -br a shows ens33 192.168.81.100/24

*Client1 (Ubuntu 24.04, hostname dhcp-client-1) after boot: ens33 received 192.168.81.100/24 from the pool. The system info banner also confirms 'IPv4 address for ens33: 192.168.81.100'.

DORA completed automatically via systemd-networkd. *

Troubleshooting:

Lab 3 — Capture DORA and analyze the fields with tcpdump

25 minutes

RFC 2131 specifies 4 core message types (DISCOVER/OFFER/REQUEST/ACK) + 1 auxiliary (RELEASE).

Analyzing a pcap with tcpdump -vv lets you verify that each field/option (Message Type 53, Lease 51, Server ID 54, Requested IP 50, chaddr, yiaddr) matches the specification.

We skip tshark + the Wireshark GUI because the Server in this lab has no internet — tcpdump -vv gives enough information.

# 1. Server: capture in the background via systemd-run (no HUP when SSH drops)
sudo systemctl reset-failed lab-tcpdump.service 2>/dev/null
sudo systemd-run --unit=lab-tcpdump --collect \
  /usr/bin/tcpdump -i ens33 -n -e -p -U \
  -w /tmp/dora.pcap '(udp port 67 or udp port 68) or arp or icmp'

# 2. Client1: force a release + request again on the console (NOT over SSH, because stopping networkd will disconnect it)
# On the Client1 console:
sudo systemctl stop systemd-networkd systemd-networkd.socket
sudo rm -f /run/systemd/netif/leases/*
sudo ip addr flush dev ens33
sudo ip link set ens33 down; sleep 1; sudo ip link set ens33 up; sleep 1
sudo systemctl start systemd-networkd
sleep 6
ip -br a

# 3. Server: stop tcpdump, read the pcap
sudo systemctl stop lab-tcpdump.service
sudo chmod a+r /tmp/dora.pcap

# 4. List the DHCP packets
sudo tcpdump -nn -tttt -r /tmp/dora.pcap 'udp port 67 or udp port 68'

# 5. Verbose: view options + xid + chaddr/yiaddr
sudo tcpdump -nn -vv -tttt -r /tmp/dora.pcap 'udp port 67 or udp port 68'

Observe: The tcpdump -nn -tttt output shows the sequence: 0.0.0.0.68 → 255.255.255.255.67 (DISCOVER), Server.67 → Client.68 (OFFER), 0.0.0.0.68 → 255.255.255.255.67 (REQUEST),

Server.67 → Client.68 (ACK) — 4 packets less than 1 second apart. -vv shows the same xid across the 4 packets (e.g. 0x690b711b), chaddr as the Client's MAC, yiaddr as the issued IP,

and the options 53/54/51/3/6 in detail.

An optional RELEASE appears first if the client cleans its lease.

1. On the Server via SSH: capture in the background via systemd-run --unit=lab-tcpdump --collect,

writing to /tmp/dora.pcap with the filter (udp port 67 or udp port 68) or arp or icmp. systemd-run keeps tcpdump from being HUP'd when the SSH session drops.

sudo systemctl status lab-tcpdump shows active (running), with tcpdump as the Main PID. ls /tmp/dora.pcap shows the file growing.

2. On the Client1 CONSOLE (not SSH, because systemctl stop systemd-networkd would drop the SSH session): a hard flush sequence — stop networkd + delete the lease cache + flush the addresses + bounce the link + start networkd again.

The goal: force the Client to send a fresh DHCPDISCOVER (not an INIT-REBOOT REQUEST for the old IP).

After ~6s, ip -br a on Client1 shows ens33 UP 192.168.81.100/24 (still in the pool; same MAC → the server issues the same IP again).

On the Server: journalctl -u isc-dhcp-server -n 20 shows DHCPDISCOVER → DHCPOFFER → DHCPREQUEST → DHCPACK.

3. On the Server: stop tcpdump + chmod it readable + list the packets: sudo tcpdump -nn -tttt -r /tmp/dora.pcap 'udp port 67 or udp port 68'

The output shows 4 packets (or 5 if there is a Release):

0.0.0.0.68 → 255.255.255.255.67 BOOTP/DHCP,Request from <MAC> (DISCOVER) Server.67 → Client.68 BOOTP/DHCP,Reply (OFFER) 0.0.0.0.68 → 255.255.255.255.67 BOOTP/DHCP,Request (REQUEST) Server.67 → Client.68 BOOTP/DHCP,Reply (ACK) Less than 1 second apart.

Server tcpdump output — 5 packets: Release + DORA

*tcpdump -nn -tttt reading /tmp/dora.pcap — 5 packets: 1 Release (Client1 stopped networkd) + 4 DORA (Discover/Offer/Request/Ack). The time between the Discover and the ACK is ~1 second.

The src 0.0.0.0 on DISCOVER+REQUEST means broadcast because Client1 has not committed an IP. *

4. Analyze the options in detail with sudo tcpdump -nn -vv -tttt -r /tmp/dora.pcap 'udp port 67 or udp port 68'.

Look for: (a) the same xid across the 4 packets, (b) chaddr = the Client's MAC, (c) yiaddr in OFFER/ACK = the issued IP, (d) Option 53 Message-Type {1,2,3,5}, (e) Option 54 Server-ID, (f) Option 51 Lease-Time, (g) Option 50 Requested-IP in the REQUEST.

The DISCOVER has DHCP-Message (53): Discover, Parameter-Request (55): Subnet-Mask, Default-Gateway, DNS, Hostname..., Hostname: dhcp-client-1.

The OFFER has DHCP-Message: Offer, Your-IP 192.168.81.100, Server-ID 192.168.81.10, Lease-Time 300, Subnet-Mask 255.255.255.0, Default-Gateway 192.168.81.10, Domain-Name-Server 8.8.8.8, 1.1.1.1.

The REQUEST has Requested-IP (50) 192.168.81.100, Server-ID (54) 192.168.81.10 — the client commits to this server. The ACK echoes the lease parameters back.

tcpdump -vv excerpt — detailed DHCP Options of the 4 DORA packets

*tcpdump -vv shows the fields/options in detail: xid 0x690b711b is consistent across the 4 packets; OFFER+ACK contain Option 54 (Server-ID), 51 (Lease-Time 300s),

1/3/6 (Subnet-Mask + Gateway + DNS); REQUEST contains Option 50 (Requested-IP) + 54 (Server-ID echo) to commit to the chosen server.

5. Verify that the xid matches across Discover/Offer/Request/Ack — it is a random Transaction ID that the server/client use to match request-reply within one DORA round.

Sample output from the lab session: xid 0x690b711b in all 4 packets.

In the tcpdump -vv output, the first line of each DHCP packet has xid 0x<hex> — it must be IDENTICAL across the 4 DORA packets of the same round.

If it differs → there are 2 different rounds interleaved.

6. (Optional) Pull the pcap to the host for analysis in the Wireshark GUI (if installed): scp <USER>@<HOST>:/tmp/dora.pcap . in Windows PowerShell.

Open Wireshark → display filter bootp or dhcp. This lab uses the tcpdump -vv CLI because the Server has no internet and the Wireshark GUI takes time to set up.

Wireshark shows the packet list; expand each packet to see the DHCP Options block with Message Type, Lease Time, Server ID and Requested IP clearly highlighted.

Troubleshooting:

Lab 4 — Case A: Manual set first (Client2 static → Client1 DHCP)

20 minutes

A common production scenario: a user sets a static IP on a device (printer, NAS) INSIDE the DHCP pool range. When a new DHCP client boots, the server may OFFER an IP that is already taken.

The protection mechanism on the Client side: RFC 5227 ARP Probe before committing to the IP.

The (optional) protection mechanism on the Server side: ping-check, an ICMP echo before the OFFER (see Step 8).

# 1. On the Client2 console: convert DHCP → static .100 (steal the IP Client1 uses)
sudo nano /etc/netplan/50-cloud-init.yaml
#   network:
#     version: 2
#     ethernets:
#       ens33:
#         dhcp4: false
#         addresses: [192.168.81.100/24]
#         routes: [{to: default, via: 192.168.81.10}]
sudo netplan apply
ip -br a

# 2. On the Server: wipe the lease DB + restart dhcpd
sudo systemctl stop isc-dhcp-server
sudo sh -c 'echo -n > /var/lib/dhcp/dhcpd.leases'
sudo systemctl start isc-dhcp-server

# 3. Capture packets on the Server
sudo systemctl reset-failed lab-tcpdump.service 2>/dev/null
sudo systemd-run --unit=lab-tcpdump --collect \
  /usr/bin/tcpdump -i ens33 -n -e -p -U \
  -w /tmp/case-a.pcap '(udp port 67 or udp port 68) or arp or icmp'

# 4. On the Client1 console: enable ACD + DECLINE for DHCP addresses
#    (networkd defaults to SendDecline=no — no probe, no DECLINE)
sudo mkdir -p /etc/systemd/network/10-netplan-ens33.network.d
printf '[DHCPv4]\nSendDecline=yes\n' | sudo tee /etc/systemd/network/10-netplan-ens33.network.d/send-decline.conf
#    then force a fresh DISCOVER
sudo systemctl stop systemd-networkd systemd-networkd.socket
sudo rm -f /run/systemd/netif/leases/*
sudo ip addr flush dev ens33
sudo ip link set ens33 down; sleep 1; sudo ip link set ens33 up; sleep 1
sudo systemctl start systemd-networkd
sleep 8
ip -br a

# 5. Server: stop tcpdump, look at the log
sudo systemctl stop lab-tcpdump.service
sudo journalctl -u isc-dhcp-server -n 30 --no-pager
sudo tcpdump -nn -tttt -r /tmp/case-a.pcap 'arp or (udp port 67 or udp port 68)'

Observe: The server log shows the sequence: DHCPDISCOVER from <MAC Client1> → DHCPOFFER on 192.168.81.100 → (Client1 ARP probes .100 → Client2 replies) → Client1 sends DHCPDECLINE → server:

DHCPDECLINE of 192.168.81.100 ... abandoned → DHCPOFFER on 192.168.81.101 → DHCPACK on 192.168.81.101.

In the pcap: the ARP who-has 192.168.81.100 tell 0.0.0.0 (probe) sits between the OFFER and the REQUEST. Client1 ends up with ens33 192.168.81.101/24.

1. On the Client2 console: edit /etc/netplan/50-cloud-init.yaml to switch to dhcp4: false + addresses: [192.168.81.100/24] + a default route via .10.

Run netplan apply + verify ip -br a.

Client2 shows ens33 UP 192.168.81.100/24. On the Server: arping -c 2 -I ens33 192.168.81.100 gets a reply from Client2's MAC (it has taken the static IP).

2. On the Server: wipe the lease DB so the pool returns to a clean state. systemctl stop isc-dhcp-server → echo -n > /var/lib/dhcp/dhcpd.leases → systemctl start isc-dhcp-server.

Start the background tcpdump into /tmp/case-a.pcap.

journalctl -u isc-dhcp-server -n 5 shows dhcpd starting fresh. The lease DB is empty (a 0-byte file or only a header).

3. On the Client1 console:

create the drop-in /etc/systemd/network/10-netplan-ens33.network.d/send-decline.conf with [DHCPv4] + SendDecline=yes (the file 10-netplan-ens33.network is generated by netplan in /run/systemd/network/),

then force a fresh DISCOVER (the networkd flush sequence as in Lab 3).

Wait 8 seconds for DORA + the ARP probe to complete.

ip -br a on Client1 shows 192.168.81.101/24 (NOT .100) — because the server abandoned .100 after the DECLINE.

4. Server: stop tcpdump + read the dhcpd log: sudo journalctl -u isc-dhcp-server -n 30 --no-pager.

Look for the sequence: DHCPDISCOVER → DHCPOFFER on .100 → DHCPDECLINE of .100 ... abandoned → DHCPOFFER on .101 → DHCPACK on .101.

The dhcpd log has 6+ lines, including the line DHCPDECLINE of 192.168.81.100 from <MAC Client1> via ens33: abandoned.

The lease DB after the test: lease 192.168.81.100 { binding state abandoned; }.

5. Read the pcap to see the ARP Probe sitting between the OFFER and the DECLINE: sudo tcpdump -nn -tttt -r /tmp/case-a.pcap 'arp or (udp port 67 or udp port 68)'.

Look for: DISCOVER → OFFER → ARP, Request who-has 192.168.81.100 tell 0.0.0.0 (Client1 probes) → ARP, Reply 192.168.81.100 is-at <MAC Client2> → DECLINE → OFFER .101 → REQUEST → ACK.

The ARP Probe pattern: sender IP 0.0.0.0 (characteristic of RFC 5227), target IP 192.168.81.100. The ARP Reply has sender IP 192.168.81.100 telling Client2's MAC.

The server then sends a NAK/new OFFER.

Analysis of the observed behavior

Observe: The ISC dhcpd server issues IP .101 to Client1 instead of .100, the first IP in the pool. The lease DB records .100 in the abandoned state.

The pcap has an ARP Probe (sender 0.0.0.0) between the OFFER and the DECLINE — this is the Client-side protection mechanism (systemd-networkd with SendDecline=yes) per RFC 5227.

Mechanism: The server does not know Client2 is using .100 because Client2 set it statically (not through DHCP). The server OFFERs .100 in pool order.

Before assigning .100, Client1 sends an ARP Probe (Sender IP=0.0.0.0, Target IP=.100).

Client2 replies from .100 → Client1 detects the conflict → sends a DHCPDECLINE (Option 53 type 4).

The server receives the DECLINE → marks .100 as abandoned in the lease DB → OFFERs the next IP, .101.

(If ping-check is enabled as in Step 8, the server skips .100 right before the OFFER using an ICMP echo — one step earlier.)

Lesson: NEVER set a static IP inside the DHCP pool range. Best practices: (1) Split the subnet or limit the range so static IPs sit outside it (e.g. a /24 subnet, pool .100-.200, static .10-.99).

(2) Use a DHCP reservation via host { hardware ethernet ...; fixed-address ...; } so the static IP is managed by dhcpd, avoiding conflicts.

(3) Enable ping-check on the server side as defense-in-depth. (4) The abandoned pool shrinks over time — monitor it + reset the DB periodically.

Troubleshooting:

Lab 5 — Case B: Manual set later + the surprise of cloned VMs sharing a machine-id

20 minutes

Scenario: Client1 is holding a DHCP IP. A user configures a 2nd device (Client2) with a static IP that duplicates it, or 2 devices share a Client-Id after a full clone.

The server does not re-check after the ACK — there is no mechanism to watch for IP conflicts after commit. Consequences: ARP cache flapping on the router/switch/other hosts, and packet loss.

RFC 2131 §3.1 describes the DHCP state machine but does not require the server to send ARP probes periodically.

# Setup: Client1 on DHCP, Client2 also on DHCP (or a duplicate static)
# In this lab session: Client2 is a full clone of Client1 → shares the machine-id
# → both claim 192.168.81.100

# On the Server: probe ARP over several rounds to catch the MAC flap
sudo arping -c 2 -w 1 -I ens33 192.168.81.100
# Repeat 4-6 times to see 2 MACs replying in turn

# View the lease DB — both MACs have a lease entry
sudo cat /var/lib/dhcp/dhcpd.leases | grep -B1 -A6 'lease 192.168.81.100'

# View the dhcpd journal — ACKs issuing .100 to both MACs
sudo journalctl -u isc-dhcp-server -n 20 --no-pager | grep -E 'DHCPACK|DHCPOFFER'

Observe: The arping output shows 2 different MACs replying from the IP 192.168.81.100 within the same broadcast probe. The reply order is not deterministic (an L2 race condition).

The server journal has 2+ DHCPACK on 192.168.81.100 lines with different MACs.

The lease DB has several entries for the same IP .100 with different hardware ethernet values, alternating active state.

1. Setup state: 2 Client VMs (Client1 + the Client2 clone) on the same VMnet1, both dhcp4: true, sharing a machine-id (because a full clone does not regenerate it).

Power on both → both ask for DHCP → both receive .100.

On the Server: journalctl -u isc-dhcp-server shows 2 DORA sequences close together with different MACs, both DHCPACK on 192.168.81.100.

Reason: the identical dhcp-client-1 hostname + the shared machine-id → the same Option 61 Client-Id → dhcpd treats the 2 VMs as 1 client.

2. On the Server: sudo arping -c 2 -w 1 -I ens33 192.168.81.100, repeated 4 times to catch several rounds.

In each round, arping broadcasts 1 request → receives 2 replies from 2 different MACs (Client1's MAC + Client2's MAC). The reply order may swap between rounds.

This is exactly 'ARP cache flapping' — the characteristic symptom of an IP conflict.

Server arping 4 rounds — 2 MACs replying for the same 192.168.81.100

*Live lab session: 00:0C:29:4C:8B:DA (the Client2 clone) + 00:0C:29:C7:BE:73 (Client1) both claim .100. The reply order swaps in round 4 — an L2 race condition.

The server's dhcpd log also has a DHCPACK issuing .100 to both MACs because the shared machine-id → duplicate Client-ID Option 61. *

3. Read the Server's lease DB: sudo cat /var/lib/dhcp/dhcpd.leases | grep -A4 'lease 192.168.81.100'. Look for several entries for the same .100 with different hardware ethernet values.

The lease DB has 4+ lease 192.168.81.100 { ... } entries alternating active state with 2 different MACs (00:0c:29:c7:be:73 and 00:0c:29:4c:8b:da).

Each ACK writes a new entry over the old one — but dhcpd does NOT report a conflict in its log.

Analysis of the observed behavior

Observe: The same IP 192.168.81.100 has 2 different MACs replying to ARP. The server log has several DHCPACK on 192.168.81.100 lines with different MACs and no warning.

The lease DB contains a lease history alternating between the 2 MACs.

Network impact: L3 traffic to .100 is delivered at random to one of the 2 clients, depending on the router/switch ARP cache at the moment of forwarding.

Mechanism: Two mechanisms lead to this state: (1) Manual conflict — Client2 sets a static IP duplicating the one Client1 holds via DHCP.

The server does not know, and has no mechanism to re-check after the ACK.

(2) Cloned VMs sharing a machine-id — a full clone copies /etc/machine-id → systemd-networkd generates the same Client-Id (Option 61) → dhcpd uses the Client-Id as the binding key → treats the 2 VMs as the same client → issues the same IP.

Both cases lead to an 'IP collision' but the root mechanisms differ.

Protection on the Client side:

dhcpcd with strict ARP DAD will DECLINE and fall back to APIPA 169.254.x.x (see Step 10). systemd-networkd by default (SendDecline=no) does not probe DHCP addresses so it does not send a DECLINE —

it just assigns the address.

Lesson: A DHCP server alone cannot prevent IP conflicts caused by user or clone behavior. Defense-in-depth: (1) Network-level:

enable DHCP snooping + Dynamic ARP Inspection (DAI) on the switch —

block ARP replies that do not match the DHCP binding table.

(2) IPAM: a tool that manages both static and DHCP IPs (e.g. NetBox, phpIPAM) — a single source of truth.

(3) VM clone discipline: after a full clone you MUST regenerate the machine-id (sudo rm /etc/machine-id; sudo systemd-machine-id-setup; sudo reboot) + change the hostname so the Client-Id is unique.

(4) Monitoring: alert on continuous DHCPACKs for the same IP with different MACs in a short window.

Troubleshooting:

Lab 6 — Compare Case A vs Case B + Report

15 minutes

Consolidate and compare the 2 cases to understand clearly where the protection mechanism sits in the DHCP lifecycle (BEFORE the OFFER vs AFTER the ACK).

This part is the final deliverable — a comparison table + best practices for prevention, used for the exercise report.

# Summary — compare the 2 cases (a markdown table — no command needed)

# Case A — Manual FIRST: Client2 static .100 first, Client1 DHCP afterwards
#   Mechanism: Client1 ARP Probe → conflict → DECLINE → the server abandons .100
#   Result: Client1 gets .101 (next in the pool)
#   IP pool: .100 enters the 'abandoned' state → the pool shrinks over time

# Case B — Manual LATER / Clone sharing a machine-id: 2 clients claim .100
#   Mechanism: the server does not re-check after the ACK; both clients assign .100 → ARP flap
#   Result: both clients have the same IP, L3 traffic is delivered at random
#   IP pool: lease entries alternate between 2 MACs, still 'active'

Observe: The comparison table in the report + the lessons learned. No runtime evidence is needed — this is the consolidation phase.

1. Comparison table of the 2 cases

Criterion

When the conflict occurs

Case A (manual FIRST)

The server is OFFERing, Client1 has not committed

Case B (manual LATER / clone)

Both clients have already been ACKed

Criterion

Who detects it

Case A (manual FIRST)

Client1 (ARP Probe RFC 5227)

Case B (manual LATER / clone)

An outside party (router/switch/arping)

Criterion

Who 'loses' the conflict

Case A (manual FIRST)

The server (abandons the IP, issues another)

Case B (manual LATER / clone)

Nobody backs off → both claim it

Criterion

Characteristic packets

Case A (manual FIRST)

ARP Probe (sender 0.0.0.0) + DHCPDECLINE

Case B (manual LATER / clone)

ARP Reply from 2 MACs for the same IP (Gratuitous-like)

Criterion

Lease DB state

Case A (manual FIRST)

binding state abandoned

Case B (manual LATER / clone)

Multiple active entries for the same IP

Criterion

Long-term consequence

Case A (manual FIRST)

The pool shrinks (abandoned IPs are not reissued)

Case B (manual LATER / clone)

Intermittent network drops, ARP cache flap

Criterion

Detection via logs

Case A (manual FIRST)

dhcpd: DHCPDECLINE ... abandoned

Case B (manual LATER / clone)

Silent — dhcpd logs no warning

2. The role of the MAC across the whole flow

Stage

DHCP Discover/Request

Field holding the MAC

chaddr (BOOTP header) + Option 61 Client-Id

Role

Identifies the Client so the server can create the lease binding

Stage

DHCP Offer/ACK

Field holding the MAC

chaddr echoed back + the lease table

Role

Ensures the same MAC → the same IP every time it asks (sticky lease)

Stage

ARP Probe (RFC 5227)

Field holding the MAC

Sender MAC, Sender IP=0.0.0.0

Role

Asks 'is anyone using this IP?' before committing

Stage

Gratuitous ARP / IP conflict

Field holding the MAC

Sender MAC, Sender IP=Target IP

Role

Announces 'this IP is mine' / a sign of conflict when 2 MACs announce it

3. Best practices for prevention (production checklist)

  1. A clear IP scheme: split the subnet or keep the static range outside the DHCP pool (e.g. a /24 subnet, static .10-.99, DHCP pool .100-.200).

  2. DHCP Reservation: for devices that need a fixed IP (printer, server, IP camera) — use host { hardware ethernet ...; fixed-address ...; } so dhcpd manages them and users do not set them by hand.

  1. Server-side ping-check: enable ping-check true; ping-timeout 1; in dhcpd.conf (see Step 8) — the server sends an ICMP echo before the OFFER and abandons the IP if there is a reply.

  1. Note: this requires dhcpd to run as root to have CAP_NET_RAW.

  1. L2 protection on the switch: DHCP Snooping (builds a binding table from DHCP traffic) + Dynamic ARP Inspection (DAI blocks ARP replies that do not match the binding) + Source Guard.

  2. An IPAM tool: NetBox / phpIPAM track both static and DHCP IPs — a single source of truth, with alerts on conflicts.

  1. VM clone discipline: regenerate the machine-id after a full clone: sudo rm /etc/machine-id /var/lib/dbus/machine-id && sudo systemd-machine-id-setup && sudo reboot.

  1. Change the hostname so the Client-Id is unique.

  1. Monitoring: alert when the dhcpd log has continuous DHCPDECLINE or abandoned entries, or when the switch reports an ARP flap.

Analysis of the observed behavior

Observe: The two cases have their protection mechanisms at 2 different positions in the DHCP lifecycle: Case A is protected BEFORE the OFFER (server ping-check) or BEFORE the ACK (client ARP probe + DECLINE).

Case B has no automatic protection after the ACK — you must rely on L2 (switch DAI) or external monitoring.

Mechanism: The DHCP protocol (RFC 2131) was originally designed for trusted networks: the server issues an IP, the client commits, and there is no periodic re-validation handshake.

Conflict protection mechanisms were added through: (1) RFC 5227 ARP Probe (client-side, mandatory for ACD - Address Conflict Detection), (2) the ISC dhcpd ping-check extension (server-side,

optional, not in the RFC), (3) L2 mechanisms (DHCP snooping + DAI) outside the DHCP protocol.

Lesson: When designing a production system: do not trust the DHCP server alone.

Combine 4 layers: (1) an IP scheme that separates static from dynamic, (2) DHCP reservations for important devices, (3) ping-check + ARP probe enabled, (4) L2 protection on the switch.

This lab demonstrates why a single layer is NOT enough — in Case A the pool shrinks over time, in Case B the network quietly goes haywire. The real world needs defense-in-depth.

Review questions

Question 1. Why does DHCPDISCOVER use src=0.0.0.0 instead of a real IP?

  1. To be anonymous, for security

  2. The client has no IP yet, and 0.0.0.0 is a special address meaning 'no IP yet'

  3. 0.0.0.0 is the standard broadcast address

  1. So the DHCP server can easily recognize a Discover packet

Answer: The client has no IP yet, and 0.0.0.0 is a special address meaning 'no IP yet'. A client that has just booted has not been assigned any IP. TCP/IP requires a source IP to send a packet.

RFC 2131 specifies that 0.0.0.0 is used when the client has no address — this is the only valid way to send UDP without an IP.

Question 2. The client has received a DHCPOFFER — why must the next step (Request) still be broadcast instead of unicast straight to the server?

  1. Because the client does not know the server's IP

  2. To tell the other DHCP servers on the LAN which server was chosen

  3. Unicast uses more bandwidth than broadcast

  1. It is a design flaw of the DHCP protocol

Answer: To tell the other DHCP servers on the LAN which server was chosen. A LAN may have several DHCP servers, and all of them send an Offer.

When the client broadcasts the Request (with the server identifier), the servers that were not chosen know to release the IPs they had reserved. This is a mechanism against wasting resources.

Question 3. The lease time is 24 hours. At what point will the client start its first renewal?

  1. After 24 hours (at expiry)

  2. After 21 hours (T2 = 87.5%)

  3. After 12 hours (T1 = 50%)

  1. After 1 hour (T1 = 1/24)

Answer: After 12 hours (T1 = 50%). T1 = 50% of the lease time = 12 hours. This is the first renewal — the client unicasts to the original DHCP server.

The purpose is to renew early so there is plenty of time to cope if the server does not respond.

Question 4. A VM is on subnet 10.0.1.0/24. The DHCP server is on subnet 10.0.0.0/24. The VM's DHCPDISCOVER does not reach the server. What is the right solution?

  1. Put the DHCP server on the same subnet 10.0.1.0/24

  2. Configure a DHCP relay agent on the router between the 2 subnets

  3. Use a static IP instead of DHCP

  1. Raise the TTL of the DHCPDISCOVER to 255

Answer: Configure a DHCP relay agent on the router between the 2 subnets. This is exactly the use case for DHCP relay.

The relay agent on the router receives the broadcast from 10.0.1.x, converts it into a unicast packet and sends it to 10.0.0.x (the DHCP server).

The server replies by unicast to the relay, and the relay forwards it back to the client.

Question 5. A Wireshark capture shows DHCPDISCOVER → DHCPOFFER → DHCPREQUEST but NO DHCPACK. What could the cause be?

  1. The client rejected the IP the server proposed

  2. The DHCP server is busy handling another request

  3. The IP the client wants to Request is in conflict (another machine is already using it), and the server sent a NACK

  1. The network is dropping packets at L1

Answer: The IP the client wants to Request is in conflict (another machine is already using it), and the server sent a NACK.

When the server receives a Request but that IP is already in conflict or no longer valid, it sends a DHCPNAK (negative acknowledgment) instead of an ACK.

On receiving the NACK, the client must start DORA over. The Wireshark capture will show the NACK packet.

Question 6. Which command is right for viewing the DHCP lease a client is holding on Linux?

  1. cat /etc/resolv.conf

  2. ip route show

  3. cat /var/lib/dhcp/dhclient.leases

  1. sudo netstat -an | grep 67

Answer: cat /var/lib/dhcp/dhclient.leases. dhclient stores the lease info (IP, gateway, DNS, expire time, server ID) in /var/lib/dhcp/dhclient.leases.

This file tells you where the IP came from, when it expires, and which server issued it.

Question 7. Do production servers use DHCP or a static IP? Why?

  1. DHCP — automatic, no manual configuration

  2. Static IP — a fixed IP so DNS, firewall rules and monitoring do not break

  3. It depends on the type of server; there is no general rule

  1. DHCP, but with a very long lease time (years)

Answer: Static IP — a fixed IP so DNS, firewall rules and monitoring do not break.

Production servers need a static IP because: the DNS A record points at that IP, firewall/security group rules are based on the IP, monitoring alerts, SSH known_hosts — all of them fail if the IP changes.

DHCP is strong for workstations/containers, not for long-lived servers.

Flashcards

Discover → Offer → Request → Ack. The process by which a client automatically gets an IP from a DHCP server. *DORA is the most important debugging keyword when a machine cannot get an IP.

Knowing the 4 steps = knowing how to check in Wireshark where it gets stuck. *

The client has no IP at all. 0.0.0.0 is the 'unspecified address' per RFC 2131 — the valid way to send UDP when you have no address.

*Understanding this explains the whole reason DHCP has to use broadcast — you cannot unicast without a source IP. *

Port 67: the DHCP Server listens (receives Discover + Request). Port 68: the DHCP Client listens (receives Offer + Ack). *You need to know this when debugging with tcpdump/Wireshark.

Use the filter 'udp port 67 or 68' to capture the whole of DORA. *

To tell the other DHCP servers on the LAN which server was chosen, so the remaining servers release the IPs they had reserved.

*In an environment with several DHCP servers → the broadcast Request is the coordination mechanism that avoids wasting the pool. Skip this step = the other servers hold their reserved IPs forever. *

T1=50% of the lease time: unicast renew to the original server. T2=87.5% of the lease time: broadcast rebind to any server.

*Understanding T1/T2 = being able to debug 'the network drops by itself after a few hours'.

It is usually a dead DHCP server: the client cannot renew at T1, the rebind at T2 also fails, and at 100% the IP is lost. *

A relay agent (usually a router) converts a DHCP broadcast into unicast so it can cross the router to a DHCP server on another subnet. *An enterprise has 1 central DHCP server for many subnets.

Without relay, every subnet would need its own server — which does not scale. Cisco: 'ip helper-address', Linux: isc-dhcp-relay. *

Negative Acknowledgment — the server rejects a Request. It happens when the IP is in conflict, the client is on the wrong subnet, or the lease is no longer valid.

*An important debugging clue: you see Discover→Offer→Request but no Ack → look for the NACK packet in Wireshark. The client must Discover again from the beginning. *

Static: servers, databases, routers, gateways, printers — anything that needs a fixed IP long term. DHCP: workstations, dev VMs, containers, user devices. *Choosing wrong causes real downtime.

A server on DHCP: the IP changes → DNS is wrong → every client fails. A workstation on static: IP conflicts, an admin nightmare. *

sudo dhclient -v eth0 (renew). Or: sudo dhclient -r eth0 (release) and then sudo dhclient eth0 (DORA again).

*Needed when debugging DHCP or when you want to change the IP without rebooting. '-v' (verbose) shows each DORA step in the terminal. *

udp.port == 67 || udp.port == 68 This command captures all DHCP traffic. You can see the 4 DORA messages and check the src/dst IPs and the payload options. Whichever step is missing = debug there.

Client: /var/lib/dhcp/dhclient.leases. Server: /var/lib/dhcp/dhcpd.leases. *The lease file holds the IP, expire time, server ID, DNS and gateway.

Read this file to know where the IP in use came from and when it expires. *

inet 192.168.1.50/24 brd 192.168.1.255 scope global dynamic eth0 — the keyword 'dynamic' means it came from DHCP. *The keyword 'dynamic' distinguishes a DHCP IP from a static one.

This is the fastest way to verify that DORA succeeded. *

Related articles

The DHCP protocol