DHCP: How Hosts Get Configured Automatically
How a device that has just joined a network receives its address, mask, gateway and DNS servers: the DORA exchange, leases, reservations, relay agents, and the faults that follow when DHCP breaks.
The problem DHCP solves
A host needs four settings before it can use a network: IP address, subnet mask, default gateway and DNS server(s). Typing them into hundreds of laptops and phones by hand would be slow and error-prone, and two devices given the same address would break each other. DHCP (Dynamic Host Configuration Protocol, RFC 2131) hands these out automatically and keeps track of who has what.
The DORA exchange
When a device connects, it has no address and does not know where any server is, so the first messages are broadcasts.
- Discover: the client broadcasts from
0.0.0.0to255.255.255.255, UDP port 68 to port 67. - Offer: a server picks a free address from its pool and offers it with the other settings.
- Request: the client formally asks for that address (also broadcast, so other servers that made offers know theirs was declined).
- Acknowledge: the server confirms and records the lease.
The settings arrive as options: the subnet mask, the router (default gateway, option 3), the DNS servers (option 6), the domain name, and more.
Leases
An address is leased, not given forever. The lease has a duration (for example 8 hours or 24 hours). The client tries to renew quietly at 50% of the lease time by asking the same server, and if that fails it starts broadcasting again at about 87.5%. If the lease expires, the client must stop using the address.
Choosing lease times: short leases (hours) suit busy guest Wi-Fi where devices come and go; long leases (days) suit stable office networks. A pool that is too small for a short-lived crowd runs out of addresses, so new devices fail to connect.
Pools, exclusions and reservations
A server’s configuration for each subnet normally includes:
- the scope or pool: the range it can hand out (for example
192.168.1.100to192.168.1.200), - exclusions: addresses inside the range it must never hand out,
- reservations: a fixed address always given to a particular MAC address. Use these for printers or servers that need a predictable address but are still managed centrally.
Keep static addresses (routers, switches, servers configured by hand) outside the pool, or exclude them, so DHCP never gives away an address that is already taken.
DHCP across subnets: the relay agent
Routers do not forward broadcasts, so a client’s Discover cannot reach a DHCP server on another subnet. Rather than running a server per subnet, you configure a DHCP relay agent (often called IP helper or DHCP relay) on the router interface that faces the clients. The relay receives the broadcast, forwards it to the server as unicast, and tags it with the client’s subnet so the server answers from the right pool. This is how one server serves a whole organisation.
What breaks, and how to spot it
| Symptom | Likely cause |
|---|---|
Address 169.254.x.x |
The client got no answer: server down, pool exhausted, relay missing, or wrong VLAN or Wi-Fi network |
| Right address, wrong gateway or DNS | A rogue DHCP server (often a home router plugged into the office network) answered first |
| Two devices with the same address | A static address inside the DHCP pool, or a reservation that overlaps |
| Some clients fail after a while | The pool ran out of free addresses (many devices, long leases) |
| One subnet fails, others work | Relay agent missing or pointing to the wrong server on that subnet |
Useful commands:
ipconfig /all # shows DHCP server, lease obtained and expires
ipconfig /release
ipconfig /renew
ip addr show # current address
sudo dhclient -v # request a lease and watch the exchange (varies by system)
nmcli device show # NetworkManager systems
IPv6 hosts can configure themselves without DHCP (SLAAC) or with DHCPv6. Those are covered later in this course.
A new laptop on a guest Wi-Fi shows 169.254.8.71. Other guests on the same Wi-Fi are working. What would you check?
The laptop failed to get a lease, but others succeed, so the DHCP service itself is probably fine. Check whether the laptop actually joined the right network and VLAN, whether the pool for that subnet is exhausted (a lease list can show this), whether the device is blocked by a MAC filter, and try a renewal (ipconfig /renew). If many clients start failing, look at pool size and lease time.
Can You Explain It?
Close the lesson and answer these without looking back. The goal isn't the wording — it's whether you've formed a usable mental model.
- Walk through DORA and explain why the first two messages are broadcasts.
- What is the difference between an exclusion and a reservation?
- Why do you need a relay agent when the DHCP server is on another subnet?
🧪 Want to practise this on your own computer? See how to set up your lab →