Sub topic 4
How a client talks before it has an address: UDP 68 to 67 and broadcast
This chapter assumes you know IPv4 addresses and subnet masks, what a broadcast is on a LAN, and the basics of client-server communication. It covers the transport problem DHCP has to solve: a client must send messages before it owns an IP address.
The bootstrapping problem
A normal IP packet needs a source address and a destination address. A client that has just joined a network has neither a valid address of its own nor the address of a DHCP server. DHCP solves this with two special addresses and two fixed ports.
- Source IP 0.0.0.0. This means "this host, on this network", used only while the client has no address.
- Destination IP 255.255.255.255. This is the limited broadcast address. Routers never forward it, so it stays on the local link.
- Destination MAC ff:ff:ff:ff:ff:ff. This is the Ethernet broadcast. Every device on the segment receives the frame, so the DHCP server hears it without the client knowing where the server is.
Why UDP and ports 67 and 68
DHCP runs over UDP, not TCP. TCP needs a handshake between two known addresses, and a broadcast cannot be part of a TCP connection. UDP sends a single datagram with no connection, so it fits a broadcast.
| Role | UDP port | Used by |
|---|---|---|
| Server (and relay agent) | 67 | Listens for client requests |
| Client | 68 | Listens for server replies |
A client sends from port 68 to port 67. A server normally replies from port 67 to port 68. Both ports are fixed, unlike most client-server protocols, where the client picks a random source port. The client needs port 68 fixed because a server may reply by broadcast, and the reply must reach the right process on every host that sees it.
How the server replies
The server also has a problem: the client has no IP address yet, so a normal unicast to its IP is impossible. The DHCP message carries a chaddr field with the client's MAC address and a xid field, a random transaction ID. The client uses xid to match replies to its own requests.
The client can set the broadcast flag in the DHCP header to say how it wants replies delivered.
- Flag set: the server broadcasts the reply to 255.255.255.255.
- Flag clear: the server may unicast the reply to the offered IP address and the client's MAC address. It does this at layer 2 without relying on ARP, because the client cannot answer ARP yet.
Many clients set the flag because their network stack cannot receive unicast packets for an address it has not configured. Others leave it clear, and the server then unicasts to the client's MAC.
Seeing it on the wire
You can confirm this with a capture. Run it, then trigger a renewal on a client.
sudo tcpdump -n -i eth0 -vv 'udp and (port 67 or port 68)'In the first message you should see 0.0.0.0.68 > 255.255.255.255.67 and a destination MAC of ff:ff:ff:ff:ff:ff. Capture on the same segment as the client. A router or another VLAN will not show the broadcast.
Common errors
- Firewall blocks UDP 67 or 68. The client keeps broadcasting and never gets an answer. Allow both ports on the server host.
- Server on a different subnet. Routers drop 255.255.255.255, so the request never arrives. A relay agent fixes this, and a later chapter covers it.
- Capturing on the wrong interface or VLAN. You see no DHCP traffic even though clients are working.
Exercise
Why does a DHCP client send its first message from 0.0.0.0 port 68 to 255.255.255.255 port 67, and why does that message not leave the local network?
Show answer
The client has no IP address and does not know the server's address, so it uses 0.0.0.0 as the source and the limited broadcast address as the destination. The broadcast reaches every host on the segment, including any DHCP server. Port 67 is where servers listen, and port 68 is where the client listens for replies. Routers do not forward 255.255.255.255, so the message stays on the local network unless a relay agent forwards it.
Exercise
A client sets the broadcast flag in its request. How does the server's reply differ from the case where the flag is clear?
Show answer
With the flag set, the server broadcasts the reply to 255.255.255.255. With the flag clear, the server may unicast the reply to the offered IP address and the client's MAC address, so the client does not need to answer ARP first.