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.

  1. Your laptop
  2. DHCP server (router)
  1. Discover: "Is anyone a DHCP server?"Your laptop to DHCP server (router)
  2. Offer: "You can use 192.168.1.10"DHCP server (router) to Your laptop
  3. Request: "I will take it"Your laptop to DHCP server (router)
  4. 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

FieldBytesWhat it means
Message type011 means a request from a client.
Hardware type011 means Ethernet.
Hardware address length066 bytes for a MAC address.
Hops00Counts relay agents. Zero on a single network.
Transaction ID39 03 f3 26A random number that ties the four messages together.
Seconds00 00Time since the client began. Zero here.
Flags80 000x8000: "please reply by broadcast", because the laptop cannot receive unicast without an address.
Client IP address00 00 00 000.0.0.0: the client has no address yet.
Your IP address00 00 00 000.0.0.0: nothing is being offered yet.
Server IP address00 00 00 000.0.0.0: no server chosen yet.
Relay IP address00 00 00 00Zero: no relay agent is used.
Client hardware addressaa bb cc 00 00 02 00 ×10The laptop's MAC address, padded to 16 bytes. The server tracks leases by this.
Server name and boot file00 ×192Old fields for network booting. Unused, so all zeros.
Magic cookie63 82 53 6363 82 53 63 marks the start of the options and says this is DHCP.
Option 53: message type35 01 01Type 1 is DISCOVER.
Option 55: parameter request list37 03 01 03 06The laptop asks for: 1 subnet mask, 3 router and 6 DNS server.
Endffff 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

FieldBytesWhat it means
Message type022 means a reply from a server.
Hardware type011 means Ethernet.
Hardware address length066 bytes for a MAC address.
Hops00Counts relay agents. Zero on a single network.
Transaction ID39 03 f3 26A random number that ties the four messages together.
Seconds00 00Time since the client began. Zero here.
Flags80 000x8000: broadcast flag copied from the request.
Client IP address00 00 00 000.0.0.0: the client has no address yet.
Your IP addressc0 a8 01 0a192.168.1.10: the address the server offers.
Server IP addressc0 a8 01 01192.168.1.1: the server making the offer.
Relay IP address00 00 00 00Zero: no relay agent is used.
Client hardware addressaa bb cc 00 00 02 00 ×10The laptop's MAC address, padded to 16 bytes. The server tracks leases by this.
Server name and boot file00 ×192Old fields for network booting. Unused, so all zeros.
Magic cookie63 82 53 6363 82 53 63 marks the start of the options and says this is DHCP.
Option 53: message type35 01 02Type 2 is OFFER.
Option 54: server identifier36 04 c0 a8 01 01192.168.1.1: which server is offering.
Option 51: lease time33 04 00 01 51 8086,400 seconds, which is 24 hours.
Option 1: subnet mask01 04 ff ff ff 00255.255.255.0: addresses 192.168.1.x are on the same local network.
Option 3: router03 04 c0 a8 01 01192.168.1.1: the default gateway to the internet.
Option 6: DNS server06 04 c0 a8 01 01192.168.1.1: where to send DNS queries.
Endffff 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.

Back to Network Lab

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.