DHCP concepts:
DHCP Client: a DHCP Client that requests IP addresses through the DHCP protocol. DHCP client is an interface-level concept. If a host has multiple Ethernet interfaces, each interface on the host can be configured as a DHCP client. Each Vlan interface on a vswitch can also be configured as a DHCP client.
DHCP Server: DHCP Server, which provides IP addresses for DHCP clients and manages assigned IP addresses.
DHCP Relay: a DHCP Relay. When a DHCP client applies for an IP address across CIDR blocks, it can forward DHCP packets.
DHCP Security: DHCP Security features to manage valid user IP addresses
DHCP Snooping: a DHCP listener that records the user information applied for an IP address from a layer-2 device.
How DHCP works:
Discovery phase:
That is, the DHCP Client's process of searching for the DHCP Server corresponds to the client's process of sending the DHCP Discovery. Because the DHCP Server corresponds to the DHCP client, the DHCP Discovery packets sent by the DHCP client are broadcast packets, the source address is 0.0.0.0 and the destination address is 255.255.255.255. All hosts on the network that support TCP/IP will receive the DHCP Discovery packet, but only the DHCP Server will receive the packet.
If Multiple DHCP servers exist in the network, Multiple DHCP servers will reply to the DHCP Discovery packet.
If no DHCP Server exists in the same vlan and the VlanIf is configured with the DHCP Relay function, the Vlanif is a DHCP Relay, DHCP Relay modifies the source IP address of the DHCP packet to the IP address of the Vlanif packet, and the destination IP address is the IP address of the DHCP Server configured by DHCP Relay. In the DHCP packet, change giaddress to the IP address of VlanIf. And send the DHCP Discovery to the DHCP Server through unicast.
DHCP Server provision stage:
The DHCP Server provides a stage, that is, the DHCP Offer stage sent by the DHCP Server in response to the DHCP Discovery
After receiving the DHCP Discovery packet, the DHCP Server resolves the Subnet to which the IP address of the request belongs. And from dhcpd. obtain an available IP address from the matched subnet in the conf file (select an IP address from the available IP address segment, and then send an ICMP packet to ping the IP address, if you receive an ICMP packet from the IP address, discard the IP address and reselect the IP address to continue the ICMP packet test until you find an IP address that is not used by anyone in the network, used to prevent IP addresses dynamically allocated from conflicting with the IP addresses of other devices in the network. This IP address conflict detection mechanism can be configured.) It is set in the yiaddress field in the DHCP Discovery message, indicates the IP address assigned to the client, and sets the Option for this Subnet configuration for the Lease, such as the default leases Lease period, maximum Lease period, and router.
DHCP selects an IP address from the address pool with the following priority:
1. existing Ip Mac Mappings
2. Previous IP addresses of the Client
3. Read the value of Requested Ip Address Option in the Discovery message. If yes and the Ip Address is available
4. Select an IP address from the configured Subnet:
The DHCP Server resolves the Subnet to which the IP address of the DHCP Discovery request belongs. First, check whether the giaddress In the DHCP Discovery message has a DHCP Relay. If yes, obtain from the available IP address segments in subnet described in giaddress and assign an IP address. If giaddress does not have an IP address, the IP address is allocated from the CIDR Block of the interface bound to the DHCP Server.
DHCP Client selection stage:
After receiving DHCP Offer packets from several DHCP servers, the DHCP Client selects one of them as the destination DHCP Server. The selection policy is usually the DHCP Server to which the first response DHCP Offer packet belongs.
Then, a DHCP Request packet is broadcasted, which contains information such as the IP Address requested from the target DHCP server. The broadcast method is used to notify other DHCP servers that they will select the IP address provided by the DHCP Server.
DHCP Server validation phase:
When the DHCP Server receives the DHCP Request sent by the DHCP Client and confirms the IP address to be provided for the DHCP Client, it wants the DHCP Client to respond to a packet containing the IP address and other options, to tell the DHCP Client that the IP address can be used. Then, the DHCP Client can bind the IP address to the NIC. In addition, all other DHCP servers will reclaim their previous IP addresses provided for the DHCP Client.
DHCP Client re-log on to the network:
After the DHCP Client logs on again, it sends a DHCP Request message that contains the IP address information previously allocated by the DHCP Server. After the DHCP Server receives the Request, attempt to allow the DHCP client to continue using the IP address. Then an ACK message is returned.
However, if the IP address cannot be assigned to the DHCP Client again, DHCP replies with a nak message. When the DHCP Client receives the NAK message, it resends the DHCP Discovery message to obtain the IP address again.
DHCP Client update lease:
The IP address obtained by DHCP has a lease. After the lease expires, the DHCP Server recycles the IP address. Therefore, if the DHCP Client wants to continue using the IP address, it must update the lease. The update method is that when the current lease term is over half, the DHCP Client will send a DHCP Renew message to Renew the lease term.