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.

Quick reference
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:

DHCP DORA handshake: Discover, Offer, Request, Acknowledge, after which the client has a usable IP address Client (no IP yet) DHCP server DISCOVER broadcast: "any DHCP server out there?" OFFER "you can have 192.168.1.42, lease 24h" REQUEST broadcast: "I accept that offer" (other servers stand down) ACK lease confirmed — client can now use 192.168.1.42
REQUEST is broadcast too, not unicast to the chosen server — that's what tells every other server that offered an address that their offer wasn't taken.

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:

Real-world applications

Gotchas

Field notes