Command Palette

Search for a command to run...

Hectal
PHASE 4Intermediate ~15 min· topic 5 of 6

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.

0/6 · 0%

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.

Meera's phone joins the café Wi-Fidiagram
Rendering diagram…

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.

terminal
$ ip -4 addr show wlan0 | grep inet
ip route | grep default
resolvectl dns wlan0
sudo dhclient -v -r wlan0 && sudo dhclient -v wlan0
── expected output ──
inet 192.168.0.57/24 brd 192.168.0.255 scope global dynamic wlan0
default via 192.168.0.1 dev wlan0 proto dhcp metric 600
Link 3 (wlan0): 192.168.0.1
DHCPRELEASE of 192.168.0.57 on wlan0 to 192.168.0.1 port 67
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 3
DHCPOFFER of 192.168.0.57 from 192.168.0.1
DHCPREQUEST for 192.168.0.57 on wlan0 to 255.255.255.255 port 67
DHCPACK of 192.168.0.57 from 192.168.0.1
bound to 192.168.0.57 -- renewal in 41582 seconds.
`dynamic` and `proto dhcp` show these settings came from DHCP. Many modern systems use NetworkManager or systemd-networkd instead of dhclient.

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.

/etc/dnsmasq.d/reservations.confwhole filetext
# 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.21

Break 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.

terminal
$ ip -4 addr show eth0 | grep inet
ping -c1 192.168.0.1
── what you'll see ──
inet 169.254.37.112/16 brd 169.254.255.255 scope link eth0
ping: connect: Network is unreachable

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. 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. 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. 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. 4

    Broadcasts don't cross routers, so a DHCP relay (on the router) forwards requests to a central DHCP server on another subnet.

  5. 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. 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

01

Why does DHCP use broadcasts?

02

What does a 169.254.x.x address tell you?

Practice

01

Find your current lease details: address, gateway, DNS, and lease expiry.

02

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.