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 (DORA) exchange from the earlier chapters. Here you will see how a DHCP message carries configuration beyond the IP address, and how to read and set those values.
Why options exist
A DHCP message has fixed fields. One of them, yiaddr ("your IP address"), carries the address the server assigns. An address alone is not enough to talk on a network. The client also needs a mask, a gateway and a DNS server. All of that travels in options, which are variable-length entries stored after the fixed fields.
Each option is a small record:
- Code: one byte that says what the option is (for example 3 means router).
- Length: one byte that says how many value bytes follow.
- Value: the data itself.
The option area starts with a four-byte "magic cookie" (99.130.83.99) and ends with option 255, called End. Option 0 is a one-byte pad with no length. Because the length is one byte, a single option holds at most 255 bytes of data.
The options you will meet most
| Code | Name | What it configures |
|---|---|---|
| 1 | Subnet mask | The mask for the assigned address, such as 255.255.255.0 |
| 3 | Router | One or more default gateways, in order of preference |
| 6 | Domain name server | One or more DNS resolvers, in order of preference |
| 12 | Host name | The client's name, sent by the client or assigned by the server |
| 15 | Domain name | The DNS suffix for the network, such as example.lan |
| 28 | Broadcast address | The subnet's broadcast address |
| 42 | NTP servers | Time servers |
| 43 | Vendor-specific information | Data that only a specific vendor's devices understand |
| 50 | Requested IP address | Sent by the client to ask for a particular address |
| 51 | IP address lease time | The lease length in seconds |
| 53 | DHCP message type | 1 Discover, 2 Offer, 3 Request, 4 Decline, 5 Ack, 6 Nak, 7 Release, 8 Inform |
| 54 | Server identifier | The IP address of the server that made the offer |
| 55 | Parameter request list | The option codes the client wants |
| 58 | Renewal time (T1) | Seconds until the client starts renewing |
| 59 | Rebinding time (T2) | Seconds until the client broadcasts to any server |
| 60 | Vendor class identifier | A string identifying the client's hardware or software |
| 61 | Client identifier | A unique ID for the client, often derived from its MAC address |
| 66, 67 | TFTP server name, boot file name | Used by network boot (PXE) |
| 119 | Domain search list | Several DNS suffixes to try when resolving short names |
| 121 | Classless static routes | Extra routes, which can include a default route |
Some options, such as 53, 54, 50 and 61, are about the conversation itself. Others, such as 1, 3, 6 and 15, are about the client's network settings.
Who sends what
Options flow in both directions.
- In the Discover, the client sends option 53 and often options 12, 60, 61 and 55.
- The Offer carries the server's proposed settings, including its identity in option 54.
- In the Request, the client sends option 50 (the address it wants) and option 54 (which server it chose). Option 54 tells the other servers that their offers were declined.
- The Acknowledge repeats the settings, and these are the ones the client applies.
The client does not receive everything the server knows. Instead it lists the codes it wants in option 55, the parameter request list. A typical client asks for 1, 3, 6, 15, 51, 58 and 59, plus others depending on the operating system. A server answers with the requested options it has configured. Some servers also send options that were not requested. Clients often ignore those.
The core settings and what happens if they are wrong
Subnet mask (1). The mask tells the client which destinations are on its own subnet. A mask that is too wide makes the client try to reach remote hosts directly with ARP and fail. A mask that is too narrow sends local traffic to the gateway.
Router (3). This sets the default gateway. If it is missing, the host can talk on its own subnet but not beyond it. If it lists several routers, the client uses the first and treats the others as backups.
DNS servers (6). If this is missing or wrong, names do not resolve, but pings to raw IP addresses still work. That pattern ("the internet is up but websites will not load") points to this option.
Lease time (51). The value is a 32-bit count of seconds. The value 0xFFFFFFFF (4294967295) means the lease is infinite. Short leases, such as 1 hour, free addresses quickly in busy guest networks. Long leases, such as 24 hours or more, reduce renewal traffic and tolerate server outages better. Options 58 and 59 are optional. When they are absent, the client uses the defaults of 50% and 87.5% of the lease.
Option 121 and option 3. Option 121 (RFC 3442) carries a list of routes, and each route has its own prefix length. If a server sends both 121 and 3, a compliant client uses 121 and ignores 3. So a default route in option 121 wins over a different one in option 3.
Reading options from raw bytes
The script below decodes the options of an Offer. The hex string is built from the byte layout in the earlier sections. Run it with Python 3.
import ipaddress
NAMES = {
1: "subnet mask", 3: "router", 6: "dns servers", 15: "domain name",
51: "lease time", 53: "message type", 54: "server identifier",
58: "T1 (renew)", 59: "T2 (rebind)",
}
MSG = {1: "Discover", 2: "Offer", 3: "Request", 4: "Decline",
5: "Ack", 6: "Nak", 7: "Release", 8: "Inform"}
def ips(value):
return ", ".join(
str(ipaddress.IPv4Address(value[i:i + 4]))
for i in range(0, len(value), 4)
)
def decode(code, value):
if code == 53:
return MSG.get(value[0], str(value[0]))
if code in (1, 3, 6, 54):
return ips(value)
if code in (51, 58, 59):
return f"{int.from_bytes(value, 'big')} s"
if code == 15:
return value.decode("ascii")
return value.hex()
def parse_options(data):
i = 0
while i < len(data):
code = data[i]
if code == 0: # pad: one byte, no length
i += 1
continue
if code == 255: # end of options
return
length = data[i + 1]
yield code, data[i + 2:i + 2 + length]
i += 2 + length
offer = bytes.fromhex(
"350102" # 53: message type = Offer
"3604c0a80101" # 54: server identifier 192.168.1.1
"330400015180" # 51: lease time 86400 s
"3a040000a8c0" # 58: T1 = 43200 s
"3b0400012750" # 59: T2 = 75600 s
"0104ffffff00" # 1: mask 255.255.255.0
"0304c0a80101" # 3: router 192.168.1.1
"0608c0a8010108080808" # 6: DNS 192.168.1.1 and 8.8.8.8
"0f0b6578616d706c652e6c616e" # 15: domain name example.lan
"ff" # 255: end
)
for code, value in parse_options(offer):
print(f"{code:>3} {NAMES.get(code, 'other'):<18} {decode(code, value)}")The output lists each option with its decoded value, for example 51 lease time 86400 s. Notice that the loop never needs to know an option's meaning to skip it. It reads the length byte and jumps. This is why new options can be added without breaking older clients.
Setting options on a server
In dnsmasq, dhcp-option sets an option for every client in the scope. Names such as option:router are shortcuts for the numeric codes.
# /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.50The mask (option 1) comes from the dhcp-range line, and the 12h becomes option 51 (43200 seconds). You can also set an option by number, for example dhcp-option=42,192.168.1.1 for an NTP server.
Seeing options on the wire
Capture the exchange and read the options in each message.
sudo tcpdump -n -i eth0 -vv 'udp and (port 67 or port 68)'With -vv, tcpdump prints each option by name, such as Subnet-Mask, Default-Gateway, Domain-Name-Server and Lease-Time. In the Discover and Request, look for the Parameter-Request line. It shows what the client asked for. If an option is missing from the Acknowledge, compare it against that list and against the server's configuration. A client cannot apply what the server never sent.
Common errors
- Missing router option. The client has an address and can reach local hosts, but not other subnets.
- Missing or wrong DNS option. Pings to IP addresses work. Name lookups fail.
- Mask mismatch. The scope uses a /24 mask, but the real network is a /23. Hosts on the other half become unreachable.
- Option 121 overriding option 3. An older router option is ignored because the server also sends classless routes.
- Lease too long for a changing network. If you change the DNS server, clients keep the old value until they renew. Lower the lease time before a planned change.
Exercise
A client with the address 192.168.1.120 can ping 8.8.8.8 but cannot open any website by name. Which DHCP option is the most likely cause, and how can you confirm it with a packet capture?
Show answer
Option 6 (domain name server) is missing or points to a resolver that does not work. Capture the exchange with tcpdump -n -i eth0 -vv 'udp and (port 67 or port 68)' and read the Acknowledge. Check whether it contains a Domain-Name-Server entry and whether the address is correct. Also check the client's Parameter-Request list to confirm it asked for option 6.
Exercise
Decode this option, given as hex: 33 04 00 02 a3 00. What is it, and what is the value in hours?
Show answer
Code 0x33 is 51, the lease time. The length is 4, and the value 0x0002a300 is 172800 seconds, which is 48 hours.