Compared
DNS vs DHCP
DHCP gives a device its settings when it joins a network: an address, the default gateway and which DNS server to ask. DNS then turns names into addresses, every time the device looks one up. DHCP tells a device where its DNS server is; DNS never hands out addresses.
Side by side
| DNS | DHCP | |
|---|---|---|
| Job | Turns a name into an address | Gives a device its address, default gateway and resolver |
| Runs | At every lookup; answers are cached for their TTL | When a device joins a network, and to renew its lease |
| Ports | UDP 53, and TCP 53 | UDP 67 (server) and UDP 68 (client) |
| Messages | A question and an answer | Discover, Offer, Request, Ack |
| Reaches | Servers anywhere, through a resolver | Its own network, by broadcast; other networks through a DHCP relay |
| When it fails | Names do not resolve; IP addresses still work | The device gets no address |
| Check with | dig | udhcpc, then ip addr |
Each one explained
- DNS
- The distributed directory that turns names like bank.lab into addresses.
- DHCP
- How a device gets its address, gateway and DNS server when it joins a network.
- Recursive resolver
- The DNS server a device asks: it does the whole search and caches the answers.
- DHCP relay
- A router that passes DHCP broadcasts on to a server on another network, so one server can serve many.
See the difference on real machines
Each lab is a small network of real Linux machines in your browser.
- DNS: how a name finds its address, and why changes take time
- DHCP: how a machine gets its address
- DHCP relaying: one address server for every hall
- Is it DNS? Find where a name lookup breaks, and prove when it doesn't
Open DNS: how a name finds its address, and why changes take time