Sub topic 5
Discover, Offer, Request, Acknowledge step by step
This chapter assumes you know IPv4 addresses and subnet masks, what a default gateway and a DNS server do, and what a broadcast is on a LAN. It also assumes you have read the previous chapter on why DHCP uses UDP ports 68 and 67 and broadcast. Here you follow the four-message exchange that gives a new client its first address, and you learn how to read it in a packet capture.
The exchange in one picture
A client with no address runs a four-message conversation with a DHCP server. The messages are Discover, Offer, Request and Acknowledge. People often shorten this to DORA.
Every message is a DHCP packet carried in UDP. The client uses source port 68 and the server uses source port 67. The packet has a fixed header followed by a list of options. One option, number 53 (DHCP Message Type), says which of the four messages this is.
Fields that matter in every message
A few header fields tie the four messages into one conversation.
| Field | Meaning |
|---|---|
| `xid` (transaction ID) | A random 32-bit number chosen by the client. All four messages of one exchange carry the same value. |
| `chaddr` | The client hardware (MAC) address. The server uses it to identify the client and to match reservations. |
| `ciaddr` | Client IP address. It is 0.0.0.0 during DORA and is filled in only when the client already has a usable address (for example, when renewing). |
| `yiaddr` | "Your" IP address. The server puts the address it is offering or confirming here. |
| `siaddr` | Address of the next server to use in the boot process (for example a network-boot server). Most clients ignore it. |
| `giaddr` | Gateway address. It is 0.0.0.0 unless a relay agent forwarded the packet. A later chapter covers relays. |
| `flags` | Contains the broadcast bit. See the Offer step below. |
The xid is how a client ignores replies meant for other clients, since on a shared segment it may hear every broadcast.
Step 1: Discover
The client has no address, no mask and no idea whether a server exists. So it broadcasts a DHCPDISCOVER.
- Source IP: 0.0.0.0, source port 68.
- Destination IP: 255.255.255.255, destination port 67.
- Destination MAC: ff:ff:ff:ff:ff:ff.
- Options: message type 53 = Discover. The client may also include option 55 (Parameter Request List), which lists the options it wants, such as mask, router and DNS. It may include option 50 (Requested IP Address) if it remembers an earlier address, and option 61 (Client Identifier) and option 12 (Host Name).
The limited broadcast address 255.255.255.255 is not forwarded by routers. Only servers on the same subnet, or a relay agent on it, will see this message.
Step 2: Offer
Each server that receives the Discover and has a free address replies with a DHCPOFFER. The server picks the address by looking at, in rough order:
- A reservation for the client's MAC address or client identifier.
- The address the client asked for in option 50, if it is free and in the pool.
- The next free address in the pool.
The Offer contains:
yiaddr: the proposed address.- Option 53 = Offer.
- Option 54 (Server Identifier): the IP address of the server making the offer.
- Option 51 (IP Address Lease Time) and the other options the client asked for, such as option 1 (subnet mask), 3 (router) and 6 (DNS servers).
The server usually checks that the address is not in use before offering it. Some servers send an ICMP echo (ping), and some check their own lease database only. Either way, the offer is a temporary hold, not a commitment. The server may keep the address reserved for a short time while it waits for a Request.
How does the Offer reach a client that has no IP address? There are two common methods, controlled by the broadcast bit in the client's flags field.
- If the broadcast bit is set, the server sends the Offer to 255.255.255.255. Clients that cannot receive a unicast packet before their interface has an address set this bit.
- If the bit is clear, the server may send a unicast IP packet to the offered
yiaddr. It uses the client's MAC address in the Ethernet frame, so no ARP is needed.
Many clients and servers simply use broadcast, which always works.
A network with two DHCP servers gets two Offers. This is normal and is the reason the next step exists.
Step 3: Request
The client picks one Offer. A common rule is to take the first one that arrives. It then broadcasts a DHCPREQUEST.
- Source: 0.0.0.0:68. Destination: 255.255.255.255:67.
- Option 53 = Request.
- Option 54 (Server Identifier): the server whose Offer the client accepted.
- Option 50 (Requested IP Address): the address from that Offer.
The Request is broadcast on purpose, even though the client has chosen one server. Because it is a broadcast, every server hears it. A server that sees its own address in option 54 knows its Offer was accepted. Any other server sees a different address in option 54, concludes that its Offer was declined, and returns the offered address to its free pool.
Step 4: Acknowledge
The chosen server records the lease and sends a DHCPACK.
yiaddr: the confirmed address.- Option 53 = Ack.
- Option 54: the server's address.
- Option 51: the lease time in seconds.
- Option 58 (Renewal Time, T1) and option 59 (Rebinding Time, T2), if the server sets them. If not, the client uses the defaults of 50% and 87.5% of the lease.
- The configuration options: mask, router, DNS, domain name and others.
When the client receives the Ack, it configures its interface with the address, mask and other values. Many clients then send an ARP probe or an ARP announcement for the new address. If another host answers the probe, the address is already in use. The client then sends a DHCPDECLINE and starts over. Decline is covered in a later chapter.
If the server cannot honor the Request, for example because the address was given to someone else in the meantime, it sends a DHCPNAK instead. The client then returns to the Discover step.
Watching DORA in a capture
You can see all four messages with tcpdump. Run this on the client or on a host in the same broadcast domain, then renew a lease on the client.
sudo tcpdump -n -i eth0 -vv 'udp and (port 67 or port 68)'To trigger a new exchange on Linux with ISC dhclient, release the lease and ask for a new one. The -v flag prints the four steps as they happen.
sudo dhclient -r eth0 # release the current lease
sudo dhclient -v eth0 # request a new lease, verbose output
ip -4 addr show eth0 # check the address that was assignedIn the tcpdump output, look for these things in order:
- A packet from 0.0.0.0.68 to 255.255.255.255.67 with
DHCP-Message Option 53, length 1: Discover. - A packet from the server's address on port 67 to the client or to the broadcast address, with
Offerand the offeredYour-IP. - A second packet from 0.0.0.0.68 to 255.255.255.255.67 with
Request, plusServer-IDandRequested-IPoptions. - A final packet from the server with
ACK, theLease-Timeand the rest of the options.
All four share the same xid. If you see Discover packets with no Offer after them, no server is answering. If you see Offer followed by Request but no ACK, the server rejected or never received the Request.
Edge cases
- Several Offers. The client chooses one, and the
Server Identifierin the Request tells the others to back off. If a server's Offer is lost, the client may still have the others. - No Offer. The client retransmits Discover with a growing delay, with some random jitter. A typical sequence waits about 4, 8, 16 and 32 seconds, with a limit around 64 seconds. After repeated failures many clients fall back to a link-local address, covered in a later chapter.
- Offer is not a guarantee. Between Offer and Ack, the server may run out of addresses or the client may take too long. The server may then reply with a NAK. Clients must be ready to restart.
- Reboot with a remembered lease. A client that restarts and still holds an unexpired lease skips Discover and Offer. It sends a Request for its old address, with option 50 and no Server Identifier, and the server replies with an Ack or a NAK. This shortcut is sometimes called INIT-REBOOT.
- Multiple interfaces. Each interface runs its own DORA exchange with its own
xidandchaddr. - Lease time is chosen by the server. The client may ask for a lease time in option 51 of the Discover or Request, but the server can give a different one. The client must use the value in the Ack.
Common errors
| Symptom | Likely cause |
|---|---|
| Discover is seen, no Offer follows | No server on the segment, a server with an exhausted pool, a firewall blocking UDP 67, or no relay on a remote subnet |
| Offer appears but the client keeps sending Discover | The Offer did not reach the client, for example because of a switch filter or a wrong broadcast setting |
| Request is followed by NAK | The requested address is outside the scope, is already leased to another client, or the client moved to a different subnet |
| Two different Offers with different gateways | Two servers are active, which may include an unauthorized (rogue) one |
| Client gets an address but then reports a conflict | Another host uses that address statically, outside the server's knowledge |
Exercise
A capture shows a Discover, then two Offers (from 192.168.1.1 and 192.168.1.2), then a Request broadcast with option 54 set to 192.168.1.2. What does server 192.168.1.1 do when it sees this Request, and why is the Request a broadcast and not a unicast to 192.168.1.2?
Show answer
Server 192.168.1.1 sees that option 54 names a different server, so it treats its own Offer as declined and returns the offered address to its free pool. The Request is broadcast so that every server hears the client's choice. The client has no other way to tell the losing servers, and it does not send a separate rejection message. The client also still has no configured address at this point, so the broadcast is the simplest way to reach all servers.
Exercise
Which header field lets the client recognize that an Offer is a reply to its own Discover and not to another client's, and in which message does the server first place the address it intends to give?
Show answer
The transaction ID (xid), a random number the client picks and every message in the exchange repeats. The server first puts the address in the yiaddr field of the Offer.