Configuration data carried by DHCP options
The primary function of the Dynamic Host Configuration Protocol (DHCP) is to provide a client device with network configuration parameters: an IP address, a subnet mask, a default gateway, and the address of a DNS server. This set allows the device to join the network and start communicating. A network can also require a domain name, time servers, network-boot parameters, or the address of a VoIP controller.
A company computer can require its domain name, time-server addresses, network-boot parameters for imaging, or the address of a particular VoIP controller. Entering these settings on every device increases work and creates opportunities for mistakes. DHCP provides a mechanism for this purpose called .
The options field is a variable-length area within a DHCP message. It carries standardized parameters and vendor-specific data. The option code identifies the meaning of the data, while the length lets the client read the value without knowing the rest of the list. This mechanism extends centralized network configuration beyond the IP address itself. The server places options in its reply, and the client interprets the codes it supports and needs.
DHCP Option Structure: Code, Length, and Value (TLV)
The DHCP options field does not contain one fixed set of fields. It contains a sequence of options. Most use a Code, Length, Value (TLV) format. The Pad and End codes are exceptions because each occupies one byte. The length covers only the Value data, so the receiver can reach the next option after reading the stated number of bytes.
- Tag (or Code)
- The code is a single byte with a length of 8 bits and identifies the option. The Subnet Mask code is , and the DNS server code is . The client uses it to recognize the meaning of the following data.
- Length
- The length is a single byte that specifies the number of bytes in the Value field. One option can therefore contain data of different sizes, such as a list of several server addresses.
- Value
- The value contains the option data, and its size follows from the Length byte. The Subnet Mask option has a length of because an IPv4 mask occupies four bytes. An example value is .
Special Option Codes
Two special codes have no Length or Value field. Their format follows directly from the code number:
- Pad Option (Code 0): This is one byte with a value of . It fills space between options and has no Length or Value field.
- End Option (Code 255): This is one byte with a value of and marks the end of the options field. Data after this code is ignored.
Common DHCP Options
The Internet Assigned Numbers Authority (IANA) maintains a registry of DHCP option codes. The registry gives each option's name, data format, and reference document. The entries below describe codes used in common IPv4 configurations and show typical applications.
Option 53: DHCP Message Type
Option 53 must appear in every DHCP message and identifies its message type. The server uses it to distinguish discovery, requests, acknowledgments, and other messages. The length of this option is always , and the value is the message-type code.
- Value : DHCPDISCOVER
- Value : DHCPOFFER
- Value : DHCPREQUEST
- Value : DHCPDECLINE (Client tells server the offered address is already in use)
- Value : DHCPACK
- Value : DHCPNAK (Server tells client its lease is invalid)
- Value : DHCPRELEASE
- Value : DHCPINFORM
Essential Network Parameters
- Option 1: Subnet Mask
- This option provides the client with its 4-byte IPv4 subnet mask. The device compares the mask with a destination address to decide whether it can send the packet directly on the local segment or should forward it to the default gateway.
- Option 3: Router (Default Gateway)
- This option provides the addresses of routers used as default gateways. The length is a multiple of 4 bytes, so the server can provide a list of routers. The client determines how it selects a router, and the option does not describe routes to every network.
- Option 6: Domain Name Server
- This provides a list of IPv4 DNS server addresses for name resolution. The length is a multiple of 4 bytes. Several addresses can allow name resolution to continue if one server fails.
# Example DHCP server configuration snippet
option routers 192.168.1.1;
option domain-name-servers 8.8.8.8, 1.1.1.1; - Option 15: Domain Name
- This option specifies the domain used when the client resolves unqualified hostnames. If the server provides 'corp.example.com', the resolver configuration can expand 'server1' to 'server1.corp.example.com'. The behavior depends on the resolver settings on the client.
Lease Time Management Options
- Option 51: IP Address Lease Time
- This option specifies the total IP address lease time in seconds as a 32-bit unsigned integer. The client uses it to calculate renewal times, while the server uses it to maintain the lease state.
- Option 58: Renewal (T1) Time Value
- This option specifies the time in seconds until the client enters the RENEWING state. RFC 2131 gives 50% of the lease time as the default when the server does not provide a value. The client then sends a unicast DHCPREQUEST to the original server. A server can set a different value for its lease policy.
- Option 59: Rebinding (T2) Time Value
- This option specifies the time in seconds until the client enters the REBINDING state. RFC 2131 gives 87.5% of the lease time as the default when the server does not provide a value. If renewal with the original server fails, the client sends DHCPREQUEST as a broadcast or through a relay agent to find an available server. Before the lease ends, the client can receive a DHCPACK from any server serving that subnet.
Parameter Request List (Option 55)
A DHCP client can explicitly identify the configuration parameters it needs. It does this with Option 55: Parameter Request List.
In a DHCPDISCOVER or DHCPREQUEST message, the client includes Option 55 with a list of codes. A list such as requests a subnet mask, routers, DNS servers, a domain name, and NTP servers. The order can express the client's preferences.
The DHCP server checks the list and can return values for supported options in DHCPOFFER and DHCPACK responses. The list can limit parameters that the client did not request, although the server is not required to return every listed option. The client must handle missing values and options returned in a different order.
Network Boot and Vendor-Specific Options
DHCP includes options for specific uses, including network booting and vendor-dependent data.
Options for Network Booting (PXE)
The allows a computer to boot software and load an operating system from the network. DHCP provides the client address and parameters needed to find the boot file.
- Option 66: TFTP Server Name: A PXE client first obtains an IP address through DHCP. Option 66 provides the name of the Trivial File Transfer Protocol (TFTP) server from which the client can download a file. The field identifies the server name, while other PXE parameters depend on the client and boot environment.
- Option 67: Bootfile Name: Option 67 specifies the boot file name, such as 'pxelinux.0' or 'bootx64.efi', that the client downloads from the TFTP server.
Option 43: Vendor-Specific Information
One standard code cannot describe every device configuration. Option 43 is a container for vendor-specific information. Its contents can use a sub-option format defined by the vendor. The option has no universal meaning beyond carrying that vendor-defined data.
In an enterprise network, a Cisco or Ubiquiti Wi-Fi access point can receive the address of its wireless controller in a vendor-specific sub-option inside Option 43. The access point can then find and register with its controller according to the vendor's documentation.