Sub topic 7
Options: mask, router, DNS, lease time and more
This chapter assumes you know IPv4 addresses and subnet masks, what a default gateway and a DNS server do, and the Discover, Offer, Request, Acknowledge exchange from the previous chapter.
Why options exist
An IP address alone does not let a host work on a network. The client also needs a mask, a gateway and a DNS server. The base DHCP message has fixed fields for the offered address (yiaddr) and a few others. Everything else travels in options.
An option is a small record with three parts: a one-byte code, a one-byte length and the value. The options section of the message starts after a fixed "magic cookie" value and ends with option 255 (End). Because every option carries its length, a client can skip codes it does not know.
The common options
| Code | Name | What the client does with it |
|---|---|---|
| 1 | Subnet mask | Sets the mask on the interface |
| 3 | Router | Installs the default gateway |
| 6 | DNS server | Uses these servers for name lookups |
| 15 | Domain name | Appends this domain to short host names |
| 51 | Lease time | Sets how long the address is valid, in seconds |
| 53 | DHCP message type | Identifies Discover, Offer, Request, Ack and so on |
| 54 | Server identifier | Names the server that made the offer |
| 58 | Renewal time (T1) | Overrides the default 50% renewal timer |
| 59 | Rebinding time (T2) | Overrides the default 87.5% rebinding timer |
Options 53 and 54 are protocol machinery. The others configure the host. Option 6 and option 3 can each carry several addresses, listed in order of preference.
How options travel in the exchange
The server puts configuration options in the Offer and again in the Acknowledge. The client's Request also carries options. Two of them matter most:
- Option 50 (requested IP address) says which address the client wants.
- Option 55 (parameter request list) lists the option codes the client would like, such as 1, 3, 6, 15 and 51.
The server answers from its own configuration. It normally returns the options the client asked for, and it may add others. The client must use the values in the Acknowledge, not the Offer.
Setting options on a server
The dnsmasq example below sets the options a client needs. The dhcp-range line supplies the mask and the lease time. The two dhcp-option lines set options 3 and 6.
# /etc/dnsmasq.conf (DHCP part only)
interface=eth0
# Hand out 192.168.1.100-192.168.1.200 with a 12-hour lease
dhcp-range=192.168.1.100,192.168.1.200,255.255.255.0,12h
# Option 3 (router) and option 6 (DNS server)
dhcp-option=option:router,192.168.1.1
dhcp-option=option:dns-server,192.168.1.1
# Reservation: this MAC address always gets the same IP
dhcp-host=aa:bb:cc:dd:ee:ff,192.168.1.50Here the 12-hour lease is sent as option 51 with the value 43200. If you do not set option 58 or 59, clients compute T1 and T2 from the lease time.
Common errors
- Missing router option. The client gets an address and can reach its own subnet, but not other networks. Check that option 3 is set.
- Wrong or missing DNS option. Pinging an IP address works but names do not resolve.
- Mask that does not match the router's interface. The client may think a remote host is local and never send the packet to the gateway.
- Very long or very short leases. Long leases keep stale entries in the pool. Very short leases create constant renewal traffic.
- Client ignores an option. The client only applies options it understands, and many only request what is in its parameter request list.
sudo tcpdump -n -i eth0 -vv 'udp and (port 67 or port 68)'With -vv, tcpdump prints each option by name, so you can confirm the mask, router, DNS and lease time in the Acknowledge.
Exercise
A client receives the address 192.168.1.120 and can ping other hosts on 192.168.1.0/24, but it cannot reach any host on another network. Which DHCP option is most likely missing from the server's reply, and which option would you add?
Show answer
The router option (option 3) is most likely missing, so the client has no default gateway. Add option 3 with the gateway address, for example 192.168.1.1, and renew the lease.