Names, time and addressesApplicationRFC 2131
DHCP: getting an address
How your phone or laptop gets an IP address, router and DNS server when it joins a network.
Ports and use: UDP 67 (server) and 68 (client)
In one sentenceDHCP hands out network settings automatically, so nobody has to type them in.
Think of it like thisIt is the hotel reception desk: you arrive without a room, ask for one, and leave with a key and directions.
Watch it happen
4 steps and 2 byte-by-byte decodes. Use the buttons or the arrow keys. Hover or focus a field to find its bytes.
- Your laptop
- DHCP server (router)
- Discover: "Is anyone a DHCP server?"Your laptop to DHCP server (router)
- Offer: "You can use 192.168.1.10"DHCP server (router) to Your laptop
- Request: "I will take it"Your laptop to DHCP server (router)
- Acknowledge: "It is yours"DHCP server (router) to Your laptop
Step 1 of 4 Discover: "Is anyone a DHCP server?"
Your laptop → DHCP server (router)
The laptop has no address, so it broadcasts to everyone on the network from 0.0.0.0.
DHCP discover 249 bytes
01 01 06 00 39 03 f3 26 00 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 aa bb cc 00 00 02 00 ×10 00 ×192 63 82 53 63 35 01 01 37 03 01 03 06 ff
| Field | Bytes | What it means |
|---|---|---|
| Message type | 01 | 1 means a request from a client. |
| Hardware type | 01 | 1 means Ethernet. |
| Hardware address length | 06 | 6 bytes for a MAC address. |
| Hops | 00 | Counts relay agents. Zero on a single network. |
| Transaction ID | 39 03 f3 26 | A random number that ties the four messages together. |
| Seconds | 00 00 | Time since the client began. Zero here. |
| Flags | 80 00 | 0x8000: "please reply by broadcast", because the laptop cannot receive unicast without an address. |
| Client IP address | 00 00 00 00 | 0.0.0.0: the client has no address yet. |
| Your IP address | 00 00 00 00 | 0.0.0.0: nothing is being offered yet. |
| Server IP address | 00 00 00 00 | 0.0.0.0: no server chosen yet. |
| Relay IP address | 00 00 00 00 | Zero: no relay agent is used. |
| Client hardware address | aa bb cc 00 00 02 00 ×10 | The laptop's MAC address, padded to 16 bytes. The server tracks leases by this. |
| Server name and boot file | 00 ×192 | Old fields for network booting. Unused, so all zeros. |
| Magic cookie | 63 82 53 63 | 63 82 53 63 marks the start of the options and says this is DHCP. |
| Option 53: message type | 35 01 01 | Type 1 is DISCOVER. |
| Option 55: parameter request list | 37 03 01 03 06 | The laptop asks for: 1 subnet mask, 3 router and 6 DNS server. |
| End | ff | ff marks the end of the options. |
Step 2 of 4 Offer: "You can use 192.168.1.10"
DHCP server (router) → Your laptop
A DHCP server picks a free address and offers it, with the subnet mask, router and DNS server.
DHCP offer 274 bytes
02 01 06 00 39 03 f3 26 00 00 80 00 00 00 00 00 c0 a8 01 0a c0 a8 01 01 00 00 00 00 aa bb cc 00 00 02 00 ×10 00 ×192 63 82 53 63 35 01 02 36 04 c0 a8 01 01 33 04 00 01 51 80 01 04 ff ff ff 00 03 04 c0 a8 01 01 06 04 c0 a8 01 01 ff
| Field | Bytes | What it means |
|---|---|---|
| Message type | 02 | 2 means a reply from a server. |
| Hardware type | 01 | 1 means Ethernet. |
| Hardware address length | 06 | 6 bytes for a MAC address. |
| Hops | 00 | Counts relay agents. Zero on a single network. |
| Transaction ID | 39 03 f3 26 | A random number that ties the four messages together. |
| Seconds | 00 00 | Time since the client began. Zero here. |
| Flags | 80 00 | 0x8000: broadcast flag copied from the request. |
| Client IP address | 00 00 00 00 | 0.0.0.0: the client has no address yet. |
| Your IP address | c0 a8 01 0a | 192.168.1.10: the address the server offers. |
| Server IP address | c0 a8 01 01 | 192.168.1.1: the server making the offer. |
| Relay IP address | 00 00 00 00 | Zero: no relay agent is used. |
| Client hardware address | aa bb cc 00 00 02 00 ×10 | The laptop's MAC address, padded to 16 bytes. The server tracks leases by this. |
| Server name and boot file | 00 ×192 | Old fields for network booting. Unused, so all zeros. |
| Magic cookie | 63 82 53 63 | 63 82 53 63 marks the start of the options and says this is DHCP. |
| Option 53: message type | 35 01 02 | Type 2 is OFFER. |
| Option 54: server identifier | 36 04 c0 a8 01 01 | 192.168.1.1: which server is offering. |
| Option 51: lease time | 33 04 00 01 51 80 | 86,400 seconds, which is 24 hours. |
| Option 1: subnet mask | 01 04 ff ff ff 00 | 255.255.255.0: addresses 192.168.1.x are on the same local network. |
| Option 3: router | 03 04 c0 a8 01 01 | 192.168.1.1: the default gateway to the internet. |
| Option 6: DNS server | 06 04 c0 a8 01 01 | 192.168.1.1: where to send DNS queries. |
| End | ff | ff marks the end. |
Step 3 of 4 Request: "I will take it"
Your laptop → DHCP server (router)
The laptop asks for that exact address and names the server it chose. Other servers learn their offers were not taken.
Step 4 of 4 Acknowledge: "It is yours"
DHCP server (router) → Your laptop
The server confirms the lease and records it. The laptop can now use the address until the lease runs out, and will renew halfway through.
Where you meet it
- Every phone, laptop and smart TV that joins home, office or café Wi-Fi.
- Cloud networks that give virtual machines private addresses.
- Giving a printer or server the same address every time by reserving it by MAC address.
Common mistakes
- Two DHCP servers on one network, such as a home router and an old access point, handing out conflicting settings.
- Giving a device a fixed address by hand inside the DHCP range, which can collide with a leased one.
- Making leases too short on a big network, which causes constant renewal traffic.
- Seeing a 169.254.x.x address and not realising it means DHCP failed.
Try it yourself
Run these on your own computer and compare the output with the lesson above.
ip addr showLinux: see the address you were given.ipconfig /allWindows: shows the DHCP server, lease start and end.sudo dhclient -vLinux: asks for a new lease and prints the four steps.
Addresses and values in the examples are made up for teaching (the 203.0.113.x range is reserved for documentation). Real traffic carries more options and details. Check the standard named above for the full rules.