Networking
DHCP
IP's own page answers "who assigns an address" with one sentence: "usually your router, automatically, via a protocol called DHCP." This page is that protocol — how a device that has never touched this network before gets a working IP address, a default gateway, and a DNS server, all without a single manual setting.
- What it is
- The protocol a device uses to automatically request and receive an IP address (and other network config) from a server on the local network.
- Mental model
- Checking into a hotel: reception hands you a room key for the length of your stay (a lease), and you hand it back — or it simply expires — when you leave.
- Key numbers
- Runs over UDP ports 67 (server) and 68 (client); the handshake is 4 messages, nicknamed DORA.
- Reach for it when
- Never chosen directly — it runs automatically the instant a device's network interface comes up with no static configuration set.
Why this needs its own protocol
A device that has just joined a network has no IP address yet — and therefore can't do anything that needs one, including asking for one the normal way. DHCP is built specifically to work around that chicken-and-egg problem: its very first message is sent as an Ethernet broadcast, precisely because the device has no unicast address of its own to be addressed by yet.
The DORA handshake
Four messages, all broadcast at first since neither side has confirmed anything yet:
Leases and renewal
An address isn't assigned forever — it's leased for a fixed duration (commonly hours to days). At roughly the halfway point of the lease, the client quietly sends a new REQUEST directly to the server (unicast this time, since it already has a working address) to renew it before it expires. If the device leaves the network and never renews, the lease simply times out and the server is free to hand that address to someone else.
What else DHCP hands out
An IP address alone isn't enough to actually use a network — DHCP typically hands out several other settings in the same OFFER/ACK:
- Subnet mask — so the device knows which addresses are "local" — see IP addressing.
- Default gateway — the router address to send anything outside the local network to.
- DNS server addresses — without this, a device has an IP address but no way to turn a domain name into one — see DNS.
- Lease time — how long the offered address is valid for before it must be renewed.
Real-world applications
- Every home and office Wi-Fi network — the router itself is almost always also the DHCP server, which is why "my Wi-Fi router" and "my DHCP server" are usually the same box.
- IoT device onboarding — a new sensor joining a network gets a usable IP within milliseconds of associating, with zero manual configuration required from whoever installed it.
- DHCP reservations — many routers let you pin a specific device's MAC address to always receive the same IP — a middle ground between full static configuration and a normal dynamic lease, common for servers, printers, and always-on embedded devices.
- Enterprise/campus networks — large networks run dedicated DHCP servers (not just a home router) managing thousands of leases across many subnets.
Gotchas
- DHCP pool exhaustion — if every address in the configured range is leased out (common on a busy guest Wi-Fi network), new devices simply can't get an address at all until an old lease expires.
- Rogue DHCP servers — a second, unauthorized DHCP server on the same network (a misconfigured router plugged in the wrong port, or something malicious) can race the real one to answer DISCOVER messages, handing out a wrong gateway/DNS and silently redirecting traffic — a real and hard-to-diagnose class of network incident.
- A device with a "self-assigned" address in the
169.254.x.xrange (link-local, APIPA) is a strong sign it never got a DHCP response at all — worth checking before debugging anything higher up the stack.