What is DHCP?
DHCP is what happens in the second after you join a Wi-Fi network. Your device arrives with no IP address, asks loudly whether anyone can give it one, and a DHCP server, usually your router, hands over an address plus the gateway and DNS server to use.
Addresses are lent, not given. Each one comes with a lease, and the device renews it while it stays on the network. When it leaves, the address goes back into the pool for the next phone or laptop. Without DHCP, every device would need its address typed in by hand.
Think of it like this. It is like checking in at a hotel. You walk in with no room, ask the front desk, get offered room 23, say yes, and get a key card that works until checkout. If you want to stay longer, you ask to extend before the card stops working.
Step by step
Joining (DORA)
5 stepsYour laptop joins the home Wi-Fi with no address and gets one in four packets: Discover, Offer, Request, Ack.
Joining (DORA)
5 stepsYour laptop joins the home Wi-Fi with no address and gets one in four packets: Discover, Offer, Request, Ack.
- 1
Discover
Is there a DHCP server here?
The laptop has no IP address, so it cannot talk to anyone directly. It broadcasts a Discover from 0.0.0.0 to 255.255.255.255, port 67, and every device on the network hears it.
- 2
Offer
You can have 192.168.1.23
The router's DHCP server picks a free address from its pool and offers it, along with the mask, the gateway and the DNS server.
- 3
Request
Yes, I will take it
The laptop broadcasts a Request naming the offered address and the server it chose. Broadcasting it tells any other DHCP server that its own offer was not taken.
- 4
Ack
It is yours for a day
The server confirms with an Ack and the lease times. The laptop now has an address, a gateway and a DNS server.
- 5
Check for clashes
Is anyone already using it?
Before using the address, the laptop sends ARP probes asking who has 192.168.1.23. If nobody answers, it is safe to use.
Lease renewal
2 stepsTwelve hours later the lease is half used, so the laptop asks the router directly to extend it.
Lease renewal
2 stepsTwelve hours later the lease is half used, so the laptop asks the router directly to extend it.
- 1
T1 reached
Half the lease has passed
At T1, 12 hours into a one-day lease, the laptop sends a Request straight to the server that gave the address. No broadcast is needed: it already has an address and knows the server.
- 2
Ack
Another full day
The server answers with an Ack and a fresh 24-hour lease. Nothing changes for the laptop; open connections carry on. If the server stayed silent, the laptop would keep trying and broadcast at T2.
No server
4 stepsThe router is switched off. Nobody answers the Discover, and the laptop gives itself a 169.254 address.
No server
4 stepsThe router is switched off. Nobody answers the Discover, and the laptop gives itself a 169.254 address.
- 1
Discover, no reply
Silence
The laptop broadcasts a Discover. The router that runs DHCP is off, so nobody answers.
- 2
Try again, longer gaps
About 4, 8, then 16 seconds
DHCP clients resend with growing gaps, roughly doubling each time. The Seconds field grows to show how long the client has been trying.
- 3
Self-assigned address
169.254.x.x
After about a minute the laptop picks a random link-local address in 169.254.0.0/16, checks nobody uses it with ARP, and takes it. Windows calls this APIPA.
- 4
Local only
No gateway, no internet
With a 169.254 address the laptop can reach other self-assigned devices on the same cable, but not the internet. Seeing 169.254 in ipconfig almost always means DHCP failed.
Myths and mix-ups
- DHCP does not only give an IP address: it also sets the gateway, DNS servers, subnet mask and more.
- A 169.254 address is not a working network address; it means no DHCP server answered.
- Your device does not wait until the lease runs out to renew; it starts at half time.
- Turning the router off and on does not always give you a new address, because the server remembers devices by their MAC address.
Try it yourself
Run these on your own computer to see DHCP at work.
See your lease (Windows)
ipconfig /allLook for DHCP Server, Lease Obtained and Lease Expires under your Wi-Fi adapter.
Ask for a fresh lease (Windows)
ipconfig /release && ipconfig /renewDrops the address and runs DORA again. Your connection blips for a second.
See the last DHCP packet (macOS)
ipconfig getpacket en0Shows the server, lease time and every option. Use en1 if en0 is not your Wi-Fi.
See DHCP options (Linux)
nmcli -f DHCP4 device show wlan0Replace wlan0 with your interface name from nmcli device.
DHCP at a glance
- Layer
- Application (7)
- Ports
- UDP 67 (server) and 68 (client)
- Four steps
- Discover, Offer, Request, Ack (DORA)
- Typical home lease
- 1 day, renewed at half time
- Fallback address
- 169.254.x.x when no server answers
- Built on
- BOOTP (1985)
- Defined
- 1997 (RFC 2131 and RFC 2132)
- IPv6 version
- DHCPv6 on ports 546 and 547
Defined inRFC 2131RFC 2132RFC 3927
Header fields
What DHCP puts in its messages, with example values from the stories above.
DHCP
- Message type
Boot Request (1)- Transaction ID
0x6a3f9c21A random number picked by the client. Every reply in this conversation carries the same one.- Seconds elapsed
0- Flags
0x0000 (Unicast)- Client IP (ciaddr)
0.0.0.0- Your IP (yiaddr)
192.168.1.23The address the server is handing to the client.- Client MAC
3c:22:fb:1a:2b:3cHow the server recognises this device, so it can give it the same address next time.- Option 53: DHCP message type
Discover (1)- Option 61: Client identifier
01:3c:22:fb:1a:2b:3c- Option 12: Host name
ravi-laptopLets the router show a friendly name in its device list.
Test yourself
What are the four DHCP messages, in order?
Questions people ask
What is DHCP and how does it work?
DHCP gives devices an IP address automatically when they join a network. The device broadcasts a Discover, the server offers an address, the device requests it and the server confirms with an Ack.
Why do I have a 169.254 IP address?
Your device did not hear back from a DHCP server, so it gave itself a link-local address. Check the cable or Wi-Fi, restart the router, then run ipconfig /renew.
What is a DHCP lease time?
How long a device may keep its address. Home routers often use one day. The device renews at half the lease, so it rarely changes while you use it.
What is the difference between a static IP and DHCP?
A static IP is typed in by hand and never changes. DHCP lends addresses automatically. Routers can also reserve the same DHCP address for one device, which gives you the best of both.
Which port does DHCP use?
UDP port 67 on the server and UDP port 68 on the client. DHCPv6 uses 547 and 546.