Linux DHCP principle and linuxdhcp Principle
DHCP
DHCP (Dynamic Host Configuration Protocol) is a LAN network Protocol that uses UDP Protocol for two purposes: automatically allocate ip addresses, subnet masks, gateways, DNS, (batch network installation), and other TCP/IP information to internal network or network service providers, it provides users or internal network administrators with central management for all computers.
DHCP principles
DHCP lease IV
A: The client performs an IP request.
When a DHCP client starts, it automatically configures its IP address to 0.0.0.0. Because 0.0.0.0 cannot communicate normally, the client must obtain a valid IP address through the DHCP server. Because the client does not know the IP address of the DHCP server, it uses the 0.0.0.0 address as the source address, the UDP68 port as the source port, and 255.255.255.255 as the target address, use UDP67 port as the destination port to broadcast the request IP address information.The broadcast information contains the MAC address and computer name of the DHCP client, so that the DHCP server can determine which client sends the request.
B: Server Response
When the DHCP server receives the IP address of the client request, it finds whether a valid IP address is provided to the client in its IP address pool. If yes, the DHCP server marks the IP address and adds it to the DHCPOFFER message. Then, the DHCP server broadcasts a DHCPOFFER message containing the following information: the MAC address of the DHCP client; valid IP Address Provided by the DHCP server; subnet mask; default gateway (route); lease term; IP address of the DHCP server. Because the DHCP client does not have an IP address, the DHCP server uses its own IP address as the source address, UDP67 port as the source port, and 255.255.255.255 as the target address, use the UDP68 port as the destination port to broadcast DHCPOFFER information.
C: IP address selected by the client
The DHCP Client selects an IP address from the first DHCPOFFER Message received, and the DHCP server that sends the IP address retains the address, so that the address cannot be provided to another DHCP client. When the client receives DHCPOFFER from the first DHCP server and selects an IP address, the third process of DHCP lease occurs. The client broadcasts the DHCPREQUEST message to all DHCP servers, indicating that it accepts the provided content. The DHCPREQUEST message includes the Service Identifier (IP address) of the server that provides IP configuration for the client ). The DHCP server checks the server Identifier Field to determine whether it is selected to provide IP addresses for the specified client. If the DHCPOFFER is denied, the DHCP server will cancel providing and retain its IP address for the next IP lease request.
When the client selects an IP address, although the client selects an IP address, the IP address is not yet configured. However, there may be several DHCP servers in a network, so the client still uses the address 0.0.0.0 as the source address, use UDP68 as the source port, 255.255.255.255 as the destination address, and UDP67 as the destination port to broadcast DHCPREQUEST information.
D: confirm the lease on the server.
After receiving the DHCPREQUEST message, the DHCP server broadcasts a successful confirmation message to the client in the form of a DHCPACK message, which contains the valid lease of the IP address and other information that may be configured. Although the server has confirmed the client's lease request, but the client has not received the server's DHCPACK message, so the server still uses its own IP address as the source address, using the UDP67 port as the source port, use 255.255.255.255 as the destination address and UDP68 as the destination port to broadcast DHCPACK information. When the client receives the DHCPACK message, it configures the IP address and completes the TCP/IP initialization.
Server validation lease: DHCPNACK (DHCPNAK)
If the DHCPREQUEST fails, for example, the client tries to lease the previous IP address but the IP address is no longer available, or because the client moves to another subnet and the IP address becomes invalid, the DHCP server broadcasts a denial confirmation message DHCPNACK. When the client receives an unsuccessful confirmation, it will re-start the DHCP lease process.
DHCP renewal
The DHCP client sends a DHCPREQUEST message packet directly to the DHCP server that provides the IP address during the lease period of 50%. If the client receives the DHCPACK message package responded by the server, the client updates its configuration based on the new lease period provided in the package and other updated TCP/IP parameters, IP address lease updated. If you do not receive a reply from the server, the client continues to use the existing IP address because there is still 50% during the current lease period.
If the IP address is not updated during the lease period of 50%, the DHCP client will contact the DHCP server that provides the IP address again during the lease period of 75%. If not, the DHCP Client must discard the IP address and apply for a new IP Address at 100% of the lease. If no DHCP server is available at this time, the DHCP client will use a random address in 169.254.0.0/16 and try again every five minutes.