Sub topic 6
Leases: renewal at T1, rebinding at T2, and expiry
This chapter assumes you know the Discover, Offer, Request, Acknowledge (DORA) exchange, IPv4 addressing, and the difference between unicast and broadcast traffic. Here you will learn what happens after the server sends the Acknowledge message.
What a lease is
A DHCP server does not give an address away permanently. It lends the address for a fixed time, called the lease time. The server sends the lease time in option 51 of the Offer and Acknowledge messages. When the lease ends, the client must stop using the address.
Leases let the server take back addresses from devices that have left the network. A laptop that disconnects without telling anyone does not hold an address forever.
The two timers: T1 and T2
The client starts two timers when it receives the Acknowledge message. RFC 2131 defines the defaults:
- T1, the renewal time, is 50% of the lease time. It is option 58.
- T2, the rebinding time, is 87.5% of the lease time. It is option 59.
A server can send its own values in these options. The client uses them if T1 is smaller than T2 and T2 is smaller than the lease time. Otherwise it uses the defaults.
lease_seconds = 86400 # 24-hour lease
t1 = lease_seconds * 0.5 # default renewal time: 50% of the lease
t2 = lease_seconds * 0.875 # default rebinding time: 87.5% of the lease
print(f"Renew (unicast to the original server) at {t1:.0f} s")
print(f"Rebind (broadcast to any server) at {t2:.0f} s")
print(f"Lease expires at {lease_seconds} s")For a 24-hour lease the output is 43200 s for T1 and 75600 s for T2.
What happens at each point
- Before T1: The client uses the address normally and sends no DHCP traffic.
- At T1 (renewing state): The client sends a Request by unicast to the server that gave it the lease. It can do this because it already has an address and knows the server's address. If the server replies with an Acknowledge, the lease restarts with a new lease time, and T1 and T2 are recalculated.
- At T2 (rebinding state): If the original server has not answered, the client sends a Request by broadcast. Any server that can extend the lease may answer. The original server may be down, but another server on the segment may know the lease.
- At expiry: If nobody answers, the client must stop using the address. It returns to the initial state and starts DORA again from the Discover message.
If the client does not receive a reply while renewing, it retries. RFC 2131 suggests waiting half of the remaining time until T2 between tries, with a minimum of 60 seconds.
Watching it happen
Use a short lease so you do not wait hours. Set dhcp-range=192.168.1.100,192.168.1.200,255.255.255.0,2m in dnsmasq, which gives a 2-minute lease and a renewal at 60 seconds. Then capture traffic on the client's network:
sudo tcpdump -n -i eth0 -vv 'udp and (port 67 or port 68)'After about 60 seconds you should see a Request from the client's own address to the server's address. This is unicast, unlike the broadcast Request in DORA.
Choosing a lease time
Lease time is a trade-off.
| Lease time | Advantage | Drawback |
|---|---|---|
| Short (minutes to hours) | Addresses return to the pool quickly | More DHCP traffic, and clients depend on the server being reachable |
| Long (days) | Little traffic, and clients survive a server outage | Unused addresses stay reserved for a long time |
A guest Wi-Fi network with many short visits suits a short lease, such as 1 to 2 hours. An office network with fixed desks can use a day or more. If the pool is nearly full, shorten the lease.
Common errors
- Assuming renewal is a broadcast. Only the rebinding request is broadcast. Filtering unicast traffic between the client and server breaks renewal while the first lease still works.
- Expecting an instant change. Changing a server option, such as the DNS server, does not reach clients until they renew. You can force it with
dhclient -randdhclientoripconfig /renew. - Setting the lease too short for a single server. If the server is down for longer than the time between T2 and expiry, clients lose their addresses.
Exercise
A server gives a client a 6-hour lease and sends no T1 or T2 options. At what times, measured from the Acknowledge message, does the client begin renewing and rebinding? To whom does it send each request?
Show answer
The lease is 21600 seconds. T1 is 50%, so renewal begins at 10800 s (3 hours) and the Request is a unicast to the server that issued the lease. T2 is 87.5%, so rebinding begins at 18900 s (5 hours 15 minutes) and the Request is a broadcast that any server can answer. If no server answers by 21600 s (6 hours), the client must stop using the address and restart with Discover.