Topic 4.5
DHCP: How a Device Gets Its Address
In one line
When a device joins a network it needs an IP address, a subnet mask, a default gateway, and DNS servers. DHCP hands these out automatically in four messages (Discover, Offer, Request, Acknowledge), as a lease that must be renewed. When DHCP fails, the device falls back to a useless 169.254.x.x address. Servers usually get fixed addresses through DHCP reservations or cloud assignment rather than hand-typed static config.
Think of it like this
Checking into a hotel. You arrive with no room (no address), ask at reception (broadcast), they offer room 214 (offer), you accept (request), they hand you the key card for three nights (acknowledge, with a lease). Stay longer and you renew at the desk.
Words you'll meet
New words in this topic, in plain English. Come back here whenever one feels fuzzy.
- DHCP
- Dynamic Host Configuration Protocol: automatically gives devices their IP settings.
- Lease
- The period a device may use its assigned address before renewing.
- DORA
- Discover, Offer, Request, Acknowledge: the four DHCP messages.
- DHCP reservation
- A rule that always gives the same address to a specific device (by MAC address).
- DHCP relay
- A router feature that forwards DHCP broadcasts to a server on another subnet.
- APIPA / link-local
- A self-assigned 169.254.x.x address used when DHCP fails.
Step by step
01Meera's phone joins the café Wi-Fi
Meera connects to the Wi-Fi at a café in Guwahati. Before she can open Tiffin, her phone has to get an address. It shouts on the local network, the router answers, and within a second she's configured.
02Watching it on Linux
On a Linux laptop you can see the lease and even request a fresh one. The lease file shows everything the server provided.
03Fixed addresses without hand-typing
Tiffin's office printer and the kitchen display tablet must always have the same address. Instead of typing static IPs on each device (and risking duplicates, Topic 4.1), the router gets a reservation: this MAC address always gets this IP.
# hand out 192.168.0.100-200, leases for 12 hours
dhcp-range=192.168.0.100,192.168.0.200,12h
dhcp-option=option:router,192.168.0.1
dhcp-option=option:dns-server,192.168.0.1
# always give these devices the same address (outside the pool)
dhcp-host=3c:52:82:aa:10:01,kitchen-display,192.168.0.20
dhcp-host=00:1b:a9:44:2e:7f,office-printer,192.168.0.21Break it on purpose
Errors are the best teachers. Make each change, read the error, guess what went wrong, then reveal the answer.
Break #1
The 169.254 address
The office router's DHCP service crashes overnight. In the morning Arjun's laptop reconnects.
Myth vs fact
Myth
Servers must use static IPs typed into their config.
Fact
Reservations or cloud-assigned addresses give stable IPs while keeping one source of truth and avoiding duplicates.
Pro corner
Extra depth for experienced readers. New to this? Skip it for now and come back later.
- ▸
DHCP has no authentication, so a rogue DHCP server on a LAN can hand out a malicious gateway or DNS server. Managed switches defend against this with DHCP snooping, which only allows DHCP offers from trusted ports.
Remember this
- 1
A device needs four settings to talk beyond itself: IP address, subnet mask (prefix), default gateway (router), and DNS servers. DHCP delivers all four, plus optional extras like the domain search list and NTP servers.
- 2
DORA: Discover (client broadcasts 'anyone?'), Offer (server proposes an address), Request (client asks for that address), Acknowledge (server confirms). It uses UDP ports 67 (server) and 68 (client), and broadcasts, because the client has no address yet.
- 3
Addresses are leased for a time (hours to days). The client renews at half the lease time. If the DHCP server is gone for longer than the lease, clients eventually lose their addresses.
- 4
Broadcasts don't cross routers, so a DHCP relay (on the router) forwards requests to a central DHCP server on another subnet.
- 5
No answer → the client gives itself a link-local address
169.254.x.x(APIPA), which works only on that local link. Seeing 169.254 means 'DHCP failed', not 'network fine'. - 6
In the cloud, DHCP still runs but the platform controls it. AWS assigns each instance's private IP from the subnet and serves it via DHCP, and a 'DHCP options set' controls the DNS servers and domain name for the VPC.
Explain it without notes
Why does DHCP use broadcasts?
What does a 169.254.x.x address tell you?
Practice
Find your current lease details: address, gateway, DNS, and lease expiry.
Configure a DHCP reservation for a device.
Trade-offs
- ↔
DHCP centralises configuration and avoids duplicate addresses but becomes a dependency: if it's down long enough, devices lose connectivity. Long leases reduce traffic and risk but fill pools on busy guest networks.
Done when you can
I can explain DORA and leases.
I recognise a 169.254 address as DHCP failure.
I use reservations instead of hand-typed static IPs.