DHCP
How your device gets an IP the instant it joins a network
You have never typed in an IP, subnet mask, gateway, and DNS server by hand — yet your devices get them automatically the moment they connect. That is DHCP at work. We have mentioned it in passing; now we see exactly how it works.
Why DHCP exists
A brand-new device joining a network knows nothing — it has no IP, no gateway, no DNS. Configuring all of that by hand for every device would be painful and error-prone. DHCP (Dynamic Host Configuration Protocol) automates it completely.
What DHCP hands out
In one exchange, DHCP provides everything a device needs to be on the network:
- IP address
- The device’s address on this network.
- Subnet mask
- So it can tell local from remote (Chapter 4).
- Default gateway
- The router to reach other networks (Chapter 5).
- DNS server
- Where to resolve names to IPs.
The DORA exchange
DHCP works in four steps, remembered as DORA:
- Discover
- Client: "Is there a DHCP server out there?"
- Offer
- Server: "Yes — here is an IP you can use."
- Request
- Client: "I would like that IP, please."
- Ack
- Server: "It is yours, here are all the settings."
Discover is a broadcast
Here is a neat detail: the client has no IP yet, so it cannot address the DHCP server directly. Instead the Discover message is a broadcast to the entire network — "will any DHCP server answer me?" The server then replies with an offer.
IPs are leased, not owned
A DHCP address is a lease — it is yours only for a set time (say 24 hours). Before it expires, your device renews it. If a device leaves and never renews, its address returns to the pool for reuse. This is exactly why your IP can change (Chapter 8).
Dynamic vs reserved
Usually DHCP hands out any free IP from a pool (dynamic). But you can also configure a reservation so a specific device — identified by its MAC address — always receives the same IP. Handy for printers, servers, and anything you want to find at a predictable address.