Network (6): Detailed explanation of DHCP principles and messages

1. DHCP request process and messages

Hosts in the local area network often move, increase or decrease, and it is necessary to allocate and manage IP addresses for the hosts in the local area network.

Advantages: Dynamically obtain addresses, the network environment is complex and the scale is relatively large

Message type

The main function

DHCP-DISCOVER

Broadcasted by the DHCP client to find available DHCP servers on the network.

DHCP-OFFER

The DHCP server is used to respond to the client's DHCP-DISCOVER request and specify corresponding configuration parameters for the client.

DHCP-REQUEST

The DHCP client broadcasts to the DHCP server to request configuration parameters or lease renewal.

DHCP-ACK

The DHCP server notifies the client that the assigned IP address and configuration parameters are available

DHCP-NAK

The DHCP server notifies the client that the address request is incorrect or the lease has expired and the lease renewal failed.

DHCP-RELEASE

The DHCP client proactively sends a message to the DHCP server to inform the server that the client no longer needs the assigned IP address.

DHCP-DECLINE

If the DHCP client finds an address conflict or the address cannot be used due to other reasons, it sends a DHCP-DECLINE message to notify the server that the assigned IP address is unavailable.

DHCP-INFORM

The DHCP client already has an IP address and uses it to request additional configuration parameters from the server.

Detailed explanation of message

The client uses UDP port number: 68;
The server uses UDP port number: 67

 

The explanations for each field are as follows:
op: The operation type of dhcp message, divided into request message and response message, 1 is request message; 2 is
response message.
htype, hlen: the hardware address type and length of the dhcp client.
hops: The number of dhcp relays that dhcp messages pass through. Each time a dhcp request message passes through a dhcp
Relay, this field will increase by 1.
xid: A random number selected when the client initiates a request, used to identify an address request process.
ecs: The time after the dhcp client started a dhcp request.
flags: The first bit is the broadcast response flag bit, used to identify the dhcp server response message.
Whether to use unicast or broadcast transmission. The remaining bits are reserved.
ciaddr: IP address of dhcp client.
yiaddr: The IP address assigned to the client by the dhcp server.
siaddr: The server IP address from which the dhcp client obtains IP address and other information.
giaddr: The IP address of the first dhcp relay that the dhcp client passes through after sending the request message.
chaddr: Hardware address of dhcp client.
sname: The server name from which the dhcp client obtains IP address and other information.
file: The startup configuration file name specified by the dhcp server for the dhcp client.
option: Optional variable-length option field, including message type, valid lease period, dns (domain n
ame system (domain name system) server's IP address, wins server's IP address and other configuration information.

 

 DHCP discover message

 

 DHCP offer message

 

DHCP request message

 

DHCP ack message

 Dhcp release message

Dhcp contract renewal

 

 

2.Dhcp relay

 Clients in the LAN can communicate with DHCP servers in other subnets through DHCP Relay and finally obtain legal IP addresses.

3. Questions

3.1 The dhcp offer message has been filled with the IP address assigned by the server to the client. Why does the client send another request message? 

Because discover broadcasts and multiple servers may reply to offer messages, the client needs to confirm which IP address provided by the server to use.

Guess you like

Origin blog.csdn.net/qq_37674086/article/details/124478826