I want to dedicate a series of publications to the DHCP protocol, I hope it is instructive for you.
The DHCP server is responsible for assigning IP addresses to clients. A client sends a packet to the server for configurations such as the IP address, subnet mask, and default gateway. After receiving the packet, the server replies with a packet carrying the corresponding configurations according to policies. Both the request and reply messages are encapsulated in UDP packets.
Three Modes for the Interaction Between the DHCP Client and Server
To obtain a valid dynamic IP address, a DHCP client exchanges different information with a server at different stages. Generally, the DHCP client and server interact in the following modes (defined in RFC 2131):
The DHCP client accesses the network for the first time.
When a DHCP client accesses a network for the first time, the DHCP client undergoes the following stages to set up a connection with the DHCP server:
Discovering stage: indicates the stage at which the DHCP client searches for a DHCP server. The client broadcasts a DHCPDISCOVER packet and only DHCP servers replies to the packet.
Offering stage: indicates the stage at which each DHCP server offers an IP address to the DHCP client. After receiving the DHCP DISCOVER packet from the client, each DHCP server selects an unassigned IP address from the IP address pool, and then sends a DHCP OFFER packet with information about the leased IP address and other settings to the client.
Selecting stage: indicates the stage at which the DHCP client selects an IP address. If multiple DHCP servers send DHCP OFFER packets to the client, the client accepts the first received DHCP OFFER packet, and then broadcasts a DHCP REQUEST packet carrying information about the selected IP address.
Acknowledging stage: indicates the stage at which the DHCP server confirms the IP address that is offered. After receiving the DHCP REQUEST packet, the DHCP server sends a DHCP ACK packet to the client. The DHCP ACK packet contains the offered IP address and other settings. Then, the DHCP client binds its TCP/IP protocol suite to the network interface card.
Except the IP address selected by the client, the IP addresses offered by other DHCP servers are available for other clients.
The DHCP client accesses the network for the second time.
When a DHCP client attempts to access a network for the second time, the DHCP client undergoes the following stages to set up a connection with the DHCP server:
If the client has correctly accessed the network, it directly broadcasts a DHCP REQUEST packet that carries the previously-assigned IP address rather than a DHCP DISCOVER packet when it accesses the network again.
After receiving the DHCP REQUEST packet, the DHCP server responds with a DHCP ACK packet if the 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 client (for example, it has been assigned to another client), the DHCP server responds with a DHCP NAK packet to the client. After receiving the DHCP NAK packet, the client sends a DHCP DISCOVER packet to apply for an IP address.
The DHCP client extends the IP address lease.
Generally, there is a valid period for the IP address dynamically assigned to the client. The server withdraws the IP address after the valid period expires. If the client intends to continue to use this IP address, it needs to extend the IP address lease.
In practice, the DHCP client sends a DHCP REQUEST to the server automatically to update the IP address lease when the DHCP client is started or a half of the lease has passed. If the IP address is valid, the server replies with a DHCP ACK packet to inform the client of the new IP address lease.



