A device that knows nothing
A brand-new device joining a network has no IP, no gateway and no DNS server. Configuring every phone, laptop and printer by hand would be slow and error-prone. DHCP (Dynamic Host Configuration Protocol) automates it. In one exchange it provides everything the earlier chapters needed:
| Setting | Home value | Used in |
|---|---|---|
| IP address | 192.168.1.23 | Chapter 2 |
| Subnet mask | 255.255.255.0 | Telling local from remote (chapter 4) |
| Default gateway | 192.168.1.1 | Reaching other networks (chapter 5) |
| DNS server | 192.168.1.1 | Resolving names (chapter 22) |
| Lease time | 24 hours | Section 4 |
DORA, packet by packet
Chapter 3 showed the four messages: Discover, Offer, Request, Ack. Here they are as real packets. Click each to see its addresses and contents:
- frame (MAC)
- a4:83:e7:2b:91:0c → ff:ff:ff:ff:ff:ff (broadcast)
- IP
- 0.0.0.0 → 255.255.255.255
- UDP ports
- 68 → 67
- sent by
- Laptop
| DHCP field | Value |
|---|---|
| op | 1 (request) |
| xid | 0x3903f326 (random; ties the four messages together) |
| ciaddr / yiaddr | 0.0.0.0 / 0.0.0.0 |
| chaddr | a4:83:e7:2b:91:0c (the laptop's MAC) |
| Option | Value |
|---|---|
| 53 message type | DISCOVER |
| 50 requested IP | 192.168.1.23 (what it had last time) |
| 12 host name | kade-laptop |
| 55 parameter list | 1, 3, 6, 15, 51, 119 (what it wants to know) |
The laptop has no address and does not know where the server is, so it shouts to everyone.
- Why the Request is also a broadcast: a network can have more than one DHCP server, and several may send offers. Broadcasting the Request, with the chosen server's ID inside, tells the chosen one "yes" and all the others "no thanks" in one message.
- Option numbers: everything beyond the basic addresses travels as numbered options: 1 mask, 3 router, 6 DNS, 51 lease time, 53 message type, 54 server ID. Options like 42 (NTP servers) and 119 (domain search list) exist too.
- A final safety check: after the Ack, a careful client sends an ARP probe for its new address (chapter 9). If someone answers, the address is already in use; the client sends DHCPDECLINE and starts again.
More than four messages
| # | Message | From | When |
|---|---|---|---|
| 1 | DISCOVER, OFFER, REQUEST, ACK | both | Getting an address (DORA) |
| 2 | NAK | server | "You cannot have that address." Example: your laptop wakes up at the office still asking for its home address 192.168.1.23. The office server refuses, and the laptop starts a fresh Discover. |
| 3 | DECLINE | client | The ARP check found the offered address already in use |
| 4 | RELEASE | client | "I am done with this address" (a clean shutdown or ipconfig /release) |
| 5 | INFORM | client | A device with a static IP asking only for the other settings (DNS, etc.) |
Leases: renew, rebind, expire
A DHCP address is a lease: it is yours only for a set time, say 24 hours. Two timers decide what happens before it runs out:
| # | Time | State | What the client does |
|---|---|---|---|
| 1 | 0 | Bound | Uses the address normally |
| 2 | T1 = 50% (12 h) | Renewing | Sends a Request straight to its own server (unicast). An Ack resets the lease to a fresh 24 hours. |
| 3 | T2 = 87.5% (21 h) | Rebinding | Its server has not answered, so it broadcasts the Request: any DHCP server may extend the lease. |
| 4 | 100% (24 h) | Expired | Must stop using the address, and starts over with Discover |
If a device leaves and never renews, its address goes back to the pool for reuse. That is exactly why your laptop's IP can change (chapter 7). Try it: see what the office PC does when the DHCP server goes down:
- bound
- renewing
- rebinding
- no lease: 169.254.x.x
- 0 hDORA: lease 172.16.1.61 for 24 h
- 12 hRenew at T1 (unicast to its server) → Ack: lease reset to 24 h
- 24 hRenew at T1 (unicast to its server) → Ack: lease reset to 24 h
The office PC, with a 24 h lease: T1 at 12 h, T2 at 21 h. Retries happen at half the remaining time each (a common pattern). Its address keeps working through every failed renewal, until the lease actually expires.
Pools, reservations and static addresses
The server hands out addresses from a pool (also called a scope or range) for each network. Kadé's office staff network:
| # | Kind | Who decides the address | Good for |
|---|---|---|---|
| 1 | Dynamic | The server, any free address from the pool | Laptops, phones, visitors |
| 2 | Reservation | The server, always the same address for a given MAC (chapter 7) | Printers, the packing PC, anything others need to find. Still managed centrally, and gets DNS and gateway changes automatically. |
| 3 | Static | Typed into the device itself; no DHCP | The router itself, and the DHCP server |
One server, two networks: DHCP relay
DHCP relies on broadcasts, and broadcasts stop at routers (chapter 9). Kadé's office has two networks behind one router (chapter 6). Rather than run two DHCP servers, Kadé runs one on a small office server at 172.16.1.5 and lets the router relay:
The relay writes its own interface address into the giaddr field. The server reads it, sees 172.16.2.1, and picks an address from the warehouse pool (172.16.2.0/24), not the staff pool. On Cisco routers this setting is called ip helper-address.
Wide by design - scroll it sideways.
Attacks on DHCP
Like ARP, DHCP trusts whoever answers first. Anyone plugged into the office network can abuse that:
| # | Attack | What happens | Defence |
|---|---|---|---|
| 1 | Rogue DHCP server | An attacker's laptop (or a home router plugged in by mistake) answers Discovers faster than the real server and hands out itself as gateway and DNS. Every new device now sends its traffic, and its DNS lookups, through the attacker. | DHCP snooping on managed switches: only the port facing the real server may send Offers and Acks |
| 2 | Starvation | The attacker requests every address in the pool using fake MACs. Real devices get nothing and fall back to 169.254. | Port security (limit MACs per switch port); DHCP snooping rate limits |
DHCP in GCP, and IPv6
| GCP VMs | GCP runs DHCP for you: the metadata server (169.254.169.254) answers kade-api's DHCP requests and hands out its internal IP (10.10.1.10), the gateway and DNS settings. You never manage a pool. "Reserving" an internal IP in GCP is the same idea as a reservation. |
| IPv6 | Devices can build their own address from the network's prefix without any server (SLAAC), learning the router from router advertisements. DHCPv6 exists for networks that want central control. Covered in the IPv6 chapter later. |
Time sync: NTP
DHCP can also tell a device where to get the time (option 42). That sounds minor, but a surprising amount of networking breaks when clocks are wrong:
| # | Depends on correct time | What breaks when the clock is off |
|---|---|---|
| 1 | TLS certificates (chapter 25) | "Not yet valid" or "expired" errors for perfectly good certificates |
| 2 | 2-step codes (TOTP) | Codes change every 30 s: a clock 1 minute off rejects correct codes |
| 3 | Tokens (JWT exp, nbf) | kade-api rejects fresh tokens, or accepts expired ones. Libraries allow a small "clock skew" margin for this. |
| 4 | Logs across machines | kade-api and kade-db logs seem to happen in the wrong order, making incidents impossible to follow |
| 5 | Signed things with expiry | DNSSEC signatures, signed URLs, cloud API request signatures fail |
NTP (Network Time Protocol) keeps clocks within milliseconds of real time, over UDP port 123 (chapter 14). Servers form levels called strata: stratum 0 is a reference clock (atomic or GPS), stratum 1 servers are wired to one, stratum 2 servers ask stratum 1, and so on. A client asks several servers and trusts the best ones.
The clever part is correcting for network delay. Each exchange records four timestamps:
| t1 | client sends the request (client's clock) |
| t2 | server receives it (server's clock) |
| t3 | server sends the reply (server's clock) |
| t4 | client receives the reply (client's clock) |
delay = (t4 − t1) − (t3 − t2) · offset = ((t2 − t1) + (t3 − t4)) ÷ 2
- Round-trip delay
- (42 − 0) − (521 − 520) = 41 ms
- Clock offset
- ((520 − 0) + (521 − 42)) ÷ 2 = 499.5 ms
The client’s clock is 499.5 ms behind the server’s. It will speed up slightly until it catches up. The formula assumes the trip out and back take equal time; any difference between them becomes error, which is why NTP prefers nearby servers with short, steady delays.
- Gentle correction: NTP clients (chrony, systemd-timesyncd) normally slew the clock, running it slightly fast or slow until it is right, instead of jumping. Jumps back in time confuse programs that measure durations.
- In GCP, every VM gets time from the metadata server (
metadata.google.internal, 169.254.169.254). Google also "smears" leap seconds over a day, so clocks never show a strange extra second. - Security: plain NTP is unauthenticated, and old public NTP servers were abused for amplification attacks (chapter 14). NTS (Network Time Security) adds authentication.
Summary
| # | Idea | In one line | New terms |
|---|---|---|---|
| 1 | DHCP | Gives IP, mask, gateway, DNS and a lease; UDP 67/68 | DHCP |
| 2 | DORA | Discover and Request are broadcasts from 0.0.0.0; options carry the settings; ARP check after | DHCP options, server ID |
| 3 | Other messages | NAK, DECLINE, RELEASE, INFORM; returning clients skip to Request | DHCPNAK, DHCPDECLINE |
| 4 | Leases | Renew at 50% (unicast), rebind at 87.5% (broadcast), expire at 100% | lease, T1, T2 |
| 5 | Pools | Dynamic from a pool; reservations by MAC; static outside the pool | pool, scope, reservation |
| 6 | Relay | Routers forward broadcasts as unicast; giaddr picks the pool | DHCP relay, giaddr |
| 7 | Attacks | Rogue servers and starvation; DHCP snooping | DHCP snooping |
| 8 | Elsewhere | GCP runs DHCP for VMs; IPv6 uses SLAAC or DHCPv6 | SLAAC, DHCPv6 |
| 9 | Time | NTP over UDP 123; strata; 4 timestamps give offset and delay; GCP metadata server | NTP, stratum, clock skew, NTS |
Try it yourself
The last DHCP Ack your laptop got
- What to look for:
yiaddr,server_identifier,lease_time,router,domain_name_server. - Runs on: macOS · Linux: cat /var/lib/dhcp/dhclient.leases or nmcli device show
- From section: 2. DORA, packet by packet
ipconfig getpacket en0DORA live
- Steps:
sudo tcpdump -n -v -i en0 'udp port 67 or udp port 68', then reconnect to WiFi - What to look for:
0.0.0.0.68 > 255.255.255.255.67, then the options decoded. - From section: 2. DORA, packet by packet
sudo tcpdump -n -v -i en0 'udp port 67 or udp port 68'Lease times
- What to look for:
Lease Obtained,Lease Expires,DHCP Server. - Runs on: Windows
- From section: 4. Leases: renew, rebind, expire
ipconfig /allRELEASE, then a fresh DORA
- Steps:
ipconfig /releasethenipconfig /renew - What to look for: Usually the same address comes back.
- Runs on: Windows · macOS: sudo ipconfig set en0 DHCP
- From section: 4. Leases: renew, rebind, expire
ipconfig /releaseipconfig /renewEvery DHCP server that answers on your network
- What to look for: Exactly one. Two means a rogue server.
- From section: 7. Attacks on DHCP
sudo nmap --script broadcast-dhcp-discoverWhether the clock is synced, and how far off
- Steps:
timedatectlandchronyc tracking - What to look for:
System clock synchronized: yes; chrony'sSystem timeoffset, often well under 1 ms. - Runs on: Linux · macOS: sntp time.google.com · Windows: w32tm /query /status
- From section: 9. Time sync: NTP
timedatectlchronyc tracking