Introduction to DHCP Messages
DHCP Message Format
Figure 3-12 shows the format of a DHCP message.
In Figure 3-12, numbers in the parenthesis indicate lengths of fields, in bytes.
Field |
Length |
Description |
---|---|---|
op (op code) |
1 byte |
Indicates the message type. The options are
as follows:
|
htype (hardware type) |
1 byte |
Indicates the hardware type. For an Ethernet address, the value of this field is 1. |
hlen (hardware length) |
1 byte |
Indicates the length of a hardware address, in bytes. For an Ethernet address, the value of this field is 6. |
hops |
1 byte |
Indicates the number of DHCP relay agents
that a DHCP message passes through. This field is set to 0 by a DHCP
client or a server. Its value increases by 1 each time the message
passes through a DHCP relay agent. This field limits the number of
DHCP relay agents that a DHCP message can pass through.
NOTICE:
A maximum of 16 DHCP relay agents are allowed between a DHCP server and a DHCP client. That is, the number of hops must be less than or equal to 16. Otherwise, DHCP messages are discarded. |
xid |
4 bytes |
Indicates a random number chosen by a DHCP client to exchange messages with a DHCP server. |
secs (seconds) |
2 bytes |
Indicates the time elapsed since the client obtained or renewed an IP address, in seconds. |
flags |
2 bytes |
Indicates the Flags field. Only the leftmost
bit in the Flags field is valid, and other bits are set to 0. The
leftmost bit determines whether the DHCP server unicasts or broadcasts
a DHCP Offer message. The options are as follows:
|
ciaddr (client ip address) |
4 bytes |
Indicates the IP address of a client. The IP address can be an existing IP address of a DHCP client or an IP address allocated by a DHCP server to a DHCP client. During initialization, the client has no IP address, and the value of this field is 0.0.0.0. The IP address 0.0.0.0 is only used by a DHCP-enabled device to temporarily communicate with other devices during startup. It is an invalid destination address. |
yiaddr (your client ip address) |
4 bytes |
Indicates the IP address allocated by a server to a client. The DHCP server fills this field into a DHCP Offer message. |
siaddr (server ip address) |
4 bytes |
Indicates the server IP address from which a DHCP client obtains the startup configuration file. |
giaddr (gateway ip address) |
4 bytes |
Indicates the IP address of the first DHCP relay agent. If the DHCP server and client are located on different network segments, the first DHCP relay agent fills this field with its own IP address and forwards the message to the DHCP server. The DHCP server determines on which network segment the client resides based on the Giaddr field, and allocates an IP address on this network segment to the client. The DHCP server also returns a DHCP Offer message to the first DHCP relay agent. The DHCP relay agent then forwards the DHCP Offer message to the client. If the DHCP Discover message passes through multiple DHCP relay agents before reaching the DHCP server, the value of this field is the IP address of the first DHCP relay agent and remains unchanged. However, the value of the Hops field increases by 1 each time the DHCP Discover message passes through a DHCP relay agent. |
chaddr (client hardware address) |
16 bytes |
Indicates the MAC address of a client. This field must be consistent with the hardware type and hardware length fields. When sending a DHCP Discover packet, the client fills its hardware address in this field. For Ethernet, a 6-byte Ethernet MAC address must be filled in this field when hardware type and hardware length fields are set to 1 and 6 respectively. |
sname (server host name) |
64 bytes |
Indicates the name of the server from which a client obtains the configuration. This field is optional and is filled in by a DHCP server. The field must be filled in with a character string that ends with 0. |
file (file name) |
128 bytes |
Indicates the startup configuration file name specified by the DHCP server for a DHCP client. The DHCP server fills this field and then delivers it together with the IP address to the client. This field is optional. The field must be filled in with a character string that ends with 0. |
options |
Variable |
Indicates the DHCP Options field, which has a maximum of 312 bytes. This field 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 Message Types
A DHCP server and a DHCP client communicate by exchanging DHCP messages. DHCP messages are classified into eight types.
Message Name | Description |
---|---|
DHCP Discover |
A DHCP Discover message is broadcast by a DHCP client to locate a DHCP server when the client attempts to connect to a network for the first time. |
DHCP Offer |
A DHCP Offer message is sent by a DHCP server to respond to a DHCP Discover message. A DHCP Offer message carries various configurations. |
DHCP Request |
A DHCP Request message is sent in the following scenarios:
|
DHCP Ack |
A DHCP ACK message is sent by a DHCP server to acknowledge the DHCP Request message from a DHCP client. After receiving a DHCP ACK message, the DHCP client obtains the configuration parameters including the IP address. |
DHCP Nak |
A DHCP NAK message is sent by a DHCP server to reject the DHCP Request message from a DHCP client. For example, if a DHCP server cannot find matching lease records after receiving a DHCP Request message, the DHCP server sends a DHCP NAK message to notify the DHCP client that no IP address is available. |
DHCP Decline |
A DHCP Decline message is sent by a DHCP client 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 Release message is sent by a DHCP client to release its IP address. After receiving a DHCP Release message, the DHCP server can allocate this IP address to another DHCP client. |
DHCP Inform |
A DHCP Inform message is sent by a DHCP client to obtain other network configuration parameters such as the gateway address and DNS server address after the DHCP client has obtained an IP address. |