A DHCP server assigns IP addresses to clients. A DHCP client sends a message to a DHCP server to request configuration parameters, such as the IP address, subnet mask, and default gateway address. The DHCP server responds with a message carrying the requested configuration parameters. Both the request and reply messages are encapsulated in UDP packets.
A DHCP client accesses a network for the first time.
Discovery stage: The DHCP client searches for a DHCP server. The DHCP client broadcasts a DHCPDISCOVER message and only DHCP servers respond to the message.
Offer stage: Each DHCP server offers an IP address to the DHCP client. After receiving the DHCPDISCOVER message from the DHCP client, each DHCP server selects an unassigned IP address from the IP address pool, and sends a DHCPOFFER message with the leased IP address and other configurations to the DHCP client.
Request stage: The DHCP client selects an IP address. If multiple DHCP servers send DHCPOFFER messages to the DHCP client, the DHCP client accepts the first DHCPOFFER message it receives, and broadcasts to each DHCP server a DHCPREQUEST message carrying information about the selected IP address.
Acknowledgment stage: The DHCP server acknowledges the IP address that is offered. After receiving the DHCPREQUEST message, the DHCP server sends a DHCPACK message to the client. The DHCPACK message contains the offered IP address and other settings. The DHCP client then binds its TCP/IP protocol suite to the network interface card.
Except the IP address offered by the DHCP server selected by the DHCP client, the unassigned IP addresses offered by other DHCP servers are available for other clients.
A DHCP client accesses a network for the second time.
When a DHCP client accesses a network for the second time, the DHCP client goes through the following procedures to set up a connection with the DHCP server:
If the client has previously accessed the network correctly, it does not broadcast a DHCPDISCOVER message. Instead, it broadcasts a DHCPREQUEST message that carries the previously assigned IP address.
After receiving the DHCPREQUEST message, the DHCP server responds with a DHCPACK message if the requested IP address is not assigned, notifying the client that it can continue to use the original IP address.
If the IP address cannot be assigned to the DHCP client (for example, it has been assigned to another client), the DHCP server responds with a DHCPNAK message to the client. After receiving the DHCPNAK message, the client sends a DHCPDISCOVER message to apply for a new IP address.
A DHCP client extends the IP address lease.
An IP address dynamically assigned to a DHCP client usually has a validity period. The DHCP server withdraws the IP address after the validity period expires. To continue using the IP address, the DHCP client must renew the IP address lease.
In actual application, a DHCP client automatically sends a DHCPREQUEST message to the DHCP server to renew the IP address lease when the DHCP client is started or half the duration of the lease is remaining. If the IP address is valid, the DHCP server replies with a DHCPACK message to inform the DHCP client of the new lease.
To force a DHCP client to enter the RENEW state, configure a DHCP server to send a unicast FORCERENEW message to the client.
To avoid address conflicts, the DHCP server pings the IP address before assigning it to a client.
The ping command checks whether a response to the ping packet is received within the specified period. If no response to the ping packet is received, the DHCP server continues to send ping packets to the IP address until the number of sent ping packets reaches the maximum limit. If there is still no response, this IP address is not in use, and the DHCP server assigns the IP address to a client. (This method is implemented based on standard protocols.)
DHCP supports IP address reservation for clients. The reserved IP addresses must belong to the address pool. If an address in the address pool is reserved, it is no longer assignable. Addresses are usually reserved for specific clients, such as DNS and WWW servers.