DHCP
DHCP (Dynamic Host Configuration Protocol) is how a machine that has just joined a network gets its settings: an IP address and subnet mask, the default gateway, and the DNS servers to use. A DHCP server, usually your router at home or the cloud provider’s VPC, hands out addresses from a pool and leases each one for a limited time. The exchange takes four messages, remembered as DORA: Discover, Offer, Request, Acknowledge.
DORA, step by step
| NO. | STEP | FROM | TO | TYPE | INFO |
|---|---|---|---|---|---|
| 1 | 01 | 0.0.0.0:68 | 255.255.255.255:67 | DISCOVER | UDP broadcast · client MAC 3c:22:fb:7a:10:9e |
| 2 | 02 | 192.168.1.1:67 | client:68 | OFFER | yiaddr 192.168.1.42 · mask /24 · router .1 · DNS .1 · lease 86400 s |
| 3 | 03 | 0.0.0.0:68 | 255.255.255.255:67 | REQUEST | requested IP 192.168.1.42 · server id 192.168.1.1 |
| 4 | 04 | 192.168.1.1:67 | client:68 | ACK | lease confirmed · client configures its interface |
| 5 | 05 | 192.168.1.42:68 | 192.168.1.1:67 | REQUEST | renewal, sent directly to the server that granted the lease |
| 6 | 05 | 192.168.1.1:67 | 192.168.1.42:68 | ACK | lease timer restarts at 24 h |
- A laptop joins the Wi-Fi. It has a MAC address but no IP, and it doesn't know where the DHCP server is.
- Discover: it broadcasts to everyone on the LAN over UDP, from 0.0.0.0 port 68 to 255.255.255.255 port 67.
- Offer: the server picks a free address from its pool and offers it with the mask, gateway, DNS servers and lease time.
- Request: the laptop asks for that address. Still a broadcast, so any other DHCP server knows its offer was declined.
- Acknowledge: the server records the lease against the laptop's MAC, and the laptop configures its interface.
- Halfway through the lease, the laptop renews directly with the server. Same IP, fresh 24 hours. If it never renews, the address returns to the pool.
What a lease gives you
| Setting | Example | Check it with |
|---|---|---|
| IP address and prefix | 192.168.1.42/24 |
ip -br addr |
| Default gateway | 192.168.1.1 |
ip route | grep default |
| DNS servers | 192.168.1.1 |
resolvectl status |
| Search domain | corp.example.com |
cat /etc/resolv.conf |
| Lease time | 24 hours | nmcli device show wlan0, or the DHCP client’s lease file |
Leases are why a laptop or a cloud VM can come back with a different IP after a long shutdown, and why two machines never get the same address on a working network. If no server answers at all, the machine gives itself a link-local address from 169.254.0.0/16 and you have “connected, but no internet”.
Static IPs and reservations
Clients are fine with any address. Servers are not: a database, a Kafka broker or a printer must stay at a known address. Two ways to get that:
- Static configuration: set the IP, gateway and DNS by hand on the machine, using an address outside the DHCP pool so nothing else is given it.
- DHCP reservation (static lease): tell the DHCP server “MAC
3c:22:fb:7a:10:9ealways gets.42”. The machine still uses DHCP, so gateway and DNS changes still reach it, but its address never changes. Usually the better option on networks you manage.
In practice you put a DNS name in front of either, so clients never hard-code the IP.
DHCP in the cloud
Cloud VMs use DHCP too, but you rarely see it. In AWS, an instance’s private IP is fixed for its lifetime, and the VPC’s DHCP service hands it out at boot. What you configure is the DHCP option set: which DNS servers and domain name instances receive. This matters when a pipeline must resolve hostnames in an on-prem domain (for example db.corp.example.com) through a hybrid DNS resolver. Azure and GCP work similarly; for a fixed public address you allocate a static or elastic IP separately.
Common mistakes
- Giving a server a dynamic address and pointing pipelines at its IP. After the next reboot or lease expiry the job connects to the wrong machine, or to nothing.
- Picking a static IP inside the DHCP pool. Sooner or later the server hands the same address to someone else and both machines break intermittently.
- Two DHCP servers on one LAN (a forgotten home router plugged into the office switch). Clients get random gateways; run one server per subnet, or relays.
- Forgetting DHCP doesn’t cross routers. Each subnet needs its own server or a DHCP relay on the router that forwards the broadcasts.
Try it
ip -br addr # the address the lease gave you
ip route | grep default # "proto dhcp" means it came from DHCP
resolvectl status | grep "DNS Server" # DNS servers from the lease (systemd)
nmcli device show wlan0 | grep -i dhcp # lease details (NetworkManager)
ipconfig getpacket en0 # macOS: the full DHCP reply
sudo tcpdump -n -i any port 67 or port 68 # watch DORA while you reconnectLearning Resources
- RFC 2131: Dynamic Host Configuration Protocol: the specification
- DHCP on Wikipedia: clear diagrams of every message
- AWS: DHCP option sets in Amazon VPC
See also: IP addressing, DNS.