A DHCP server and a DHCP client communicate by exchanging DHCP messages. DHCP messages are transmitted using the User Datagram Protocol (UDP). A DHCP client uses UDP port 68 to send messages to a DHCP server, and a DHCP server uses UDP port 67 to send messages to a DHCP client. These messages are classified into eight types.
DHCP Message |
Description |
---|---|
DHCP Discover |
A DHCP client broadcasts this message to locate a DHCP server when the client attempts to connect to a network for the first time. |
DHCP Offer |
A DHCP server sends this message in response to a DHCP Discover message. A DHCP Offer message carries configuration information. |
DHCP Request |
A DHCP client sends this message in the following scenarios:
|
DHCP ACK |
A DHCP server sends this message to acknowledge a DHCP Request message sent from a DHCP client. After receiving a DHCP ACK message, the DHCP client obtains configuration parameters (including an IP address). |
DHCP NAK |
A DHCP server sends this message to reject a DHCP Request message from a DHCP client. For example, a DHCP server will send this message if it determines that there is no available IP address after receiving a DHCP Request message. |
DHCP Decline |
A DHCP client sends this message to notify the DHCP server that the allocated IP address conflicts with another IP address. The DHCP client then applies to the DHCP server for another IP address. |
DHCP Release |
A DHCP client sends this message to release its allocated IP address. After receiving a DHCP Release message, the DHCP server can allocate this IP address to another DHCP client. |
DHCP Inform |
A DHCP client sends this message to obtain network configuration parameters, such as the gateway address and DNS server address, after it has obtained an IP address. |
The format of DHCP messages is based on the format of BOOTP messages, which ensures support for BOOTP functionality and interoperability between BOOTP clients and DHCP servers.
Figure 1 shows the format of a DHCP message and Table 2 describes each of the fields in the DHCP message. In the figure, the numbers in parentheses indicate the size of each field in bytes.
Field |
Length |
Description |
---|---|---|
op |
1 byte |
Operation Code: indicates the general type of message. The values are:
|
htype |
1 byte |
Hardware Type: indicates the type of hardware used for the local network. The values of this field differ for different hardware types. The most common value is 1, which indicates Ethernet (10 Mb). |
hlen |
1 byte |
Hardware Address Length: indicates the length of a hardware address. For Ethernet, the value is 6. |
1 byte |
Hops: indicates the number of DHCP relay agents through which a DHCP message passes. This value is set to 0 by a client and is incremented by 1 each time the message passes through a DHCP relay agent. A DHCP message passes through a maximum of 16 DHCP relay agents when being transmitted between a server and a client. That is, the number of hops between the server and client cannot exceed 16. Otherwise, the DHCP message is discarded. |
|
xid |
4 bytes |
Transaction Identifier: indicates a random number chosen by a client for exchanging messages with a DHCP server. |
secs |
2 bytes |
Seconds: indicates the number of seconds elapsed since a client obtained or renewed an IP address. |
2 bytes |
Flags: indicates the Flags field. Only the leftmost bit in this field is used, and the other bits are set to 0. The leftmost bit specifies the mode a DHCP server uses to transmit a DHCP Offer message. The values are:
|
|
ciaddr |
4 bytes |
Client IP Address: indicates the IP address of a DHCP client. The IP address is either the existing IP address of the client or an IP address allocated by a DHCP server to the client. During the process of a client acquiring an IP address, the value of this field is 0.0.0.0. 0.0.0.0 is an invalid destination address and is used by a DHCP-enabled device to communicate only temporarily with other devices during startup. |
yiaddr |
4 bytes |
Your IP Address: indicates the IP address that a DHCP server allocates to a client. |
siaddr |
4 bytes |
Server IP Address: indicates the server IP address from which a DHCP client obtains its startup configuration file. |
4 bytes |
Gateway Address: indicates the IP address of the first DHCP relay agent. When a client sends a DHCP Request message and is on a different network segment from its DHCP server, the first DHCP relay agent forwards the message to the DHCP server and fills its IP address in the giaddr field. The DHCP server determines the network segment address of the client based on this field, selects an appropriate address pool, and assigns an IP address on this network segment to the client. The server also returns a DHCP reply message to the first DHCP relay agent, which then forwards the message to the client. If the DHCP Request message passes through multiple DHCP relay agents before reaching the DHCP server, the giaddr field value is still the IP address of the first DHCP relay agent, and the hops field value is incremented by 1 each time the message passes through a DHCP relay agent. |
|
16 bytes |
Client Hardware Address: indicates the Layer 2 address of a client. For Ethernet, this field must contain a 6-byte Ethernet MAC address if the hardware type and hardware length fields are set to 1 and 6 respectively. |
|
sname |
64 bytes |
Server Hostname: indicates the name of the server from which a client obtains configuration information. This field is optional, is filled in by the DHCP server, and must be a character string that ends with 0. |
file |
128 bytes |
Boot File: indicates the name of the startup configuration file to be obtained by a client. This field is filled in by a DHCP server and delivered to the client when a DHCP address is allocated to the client. The field is optional and must be a character string that ends with 0. |
options |
Variable |
Options: indicates the DHCP Options field. This field is a maximum of 312 bytes in length and contains the DHCP message type and configuration parameters allocated by a DHCP server to a client. The configuration parameters include the gateway IP address, DNS server IP address, and IP address lease. For details about the Options field, see DHCP Options. |
DHCP Options are tagged data items that provide control information and parameters to a DHCP client. The options are sent in a variable-length field at the end of a DHCP message. This field consists of Type, Length, and Value, which are shown in Figure 2 and described in Table 3.
Field |
Length |
Description |
---|---|---|
Type |
1 byte |
Indicates the information type. |
Length |
1 byte |
Indicates the length of the subsequent content in the Options field. |
Value |
Variable |
Indicates the message content. The length varies depending on the Length field. |
The values of the Options field range from 1 to 255. Some DHCP options are predefined and others can be user defined. Table 4 lists some of the common predefined DHCP options.
Option Code |
Function |
---|---|
1 |
Specifies a subnet mask. |
3 |
Specifies a gateway address. |
4 |
Specifies a time server. |
6 |
Specifies the IP address of a DNS server. |
7 |
Specifies a log server. |
12 |
Specifies the device name of a DHCP client. |
15 |
Specifies a domain name. |
17 |
Specifies the root path. |
28 |
Specifies a broadcast address. |
33 |
Specifies a group of classful static routes that the DHCP client must add to its routing table. In classful static routes, destination address masks are natural masks and cannot be used for subnetting. If Option 121 is configured, Option 33 is ignored. |
42 |
Specifies NTP servers. |
43 |
Specifies vendor specific information. |
44 |
Specifies a NetBIOS server name. |
46 |
Specifies a NetBIOS node type. |
Specifies a requested IP address. |
|
51 |
Specifies an IP address lease. |
52 |
Specifies an additional option. |
53 |
Specifies a DHCP message type. |
Specifies a server identifier. |
|
Specifies a parameter request list. A DHCP client uses this option to request specified configuration parameters. |
|
56 |
Specifies a message option, which is used to describe the reason why an IP address fails to be allocated. This option is encapsulated into the Option field of the following DHCP messages:
|
58 |
Specifies the lease renewal time (T1), which is 50% of the lease time. |
59 |
Specifies the lease renewal time (T2), which is 87.5% of the lease time. |
60 |
Specifies the vendor category, which identifies the DHCP client type and configuration. |
61 |
Specifies a client identifier. |
66 |
Specifies a TFTP server name allocated to DHCP clients. |
67 |
Specifies a startup file name allocated to DHCP clients. |
77 |
Specifies a user type. |
120 |
Specifies the IP address option of a SIP server. NOTE:
Currently, only IP addresses can be parsed and domain names cannot be parsed. |
121 |
Specifies a group of classless static routes that the DHCP client must add to its routing table. In classless static routes, destination address masks can be any value and can be used for subnetting. NOTE:
A device functioning as a DHCP client can receive static routes delivered from a DHCP server through Option 121. |
129 |
Specifies the IP address of a call server. |
184 |
Specifies a reserved option. You can customize information carried in this option. |
In addition to the predefined options, you can configure user-defined options to support a wide variety of devices, such as IP phones.
Vendor-specific information option (Option 43)
Option 43 is called the vendor-specific information option. Figure 3 shows the format of Option 43.
DHCP servers and DHCP clients exchange vendor-specific information through Option 43. When a DHCP server receives a DHCP Discover message with parameter 43 encapsulated in Option 55, it encapsulates Option 43 in a DHCP Offer message and sends the message to the DHCP client.
When a device functions as the DHCP server, it can deliver the AC's IP address to connected APs (Huawei devices), which facilitates the connection setup between the AC and APs.
Option 43 supports sub-options, as shown in Figure 3.
Sub-option type: type of the sub-option. When the device delivers the AC's IP address to APs, the value can be 0x01 (hexadecimal type), 0x02 (IP address type), or 0x03 (ASCII code type).
Sub-option length: length of the sub-option.
Sub-option value: value of the sub-option.
Relay agent information option (Option 82)
Option 82 is the DHCP relay agent information option that records the location of a DHCP client. A DHCP relay agent or a device with DHCP snooping enabled appends the Option 82 field to a DHCP Discover message sent from a DHCP client and then forwards the DHCP Discover message to a DHCP server.
The administrator can use the Option 82 field to locate a DHCP client and control the security and accounting of the DHCP client. The DHCP server that supports the Option 82 field can determine policies to allocate IP addresses and other parameters according to information in the Option 82 field. IP addresses can be allocated flexibly.