How DHCP actually works
You can configure and use DHCP without knowing the details of how DHCP client configuration actually works. However, a basic understanding of the process can help you to understand what DHCP is actually doing. This understanding is not only enlightening, it can also help when you're troubleshooting DHCP problems.
The following paragraphs are a blow-by-blow account of how DHCP configures TCP/IP hosts. This procedure happens every time you boot up a host computer. It also happens when you release an IP lease and request a fresh lease.
- When a host computer starts up, the DHCP client software sends a special
broadcast packet, known as a DHCP Discover message. This message
uses the subnet's broadcast address (all host ID bits set to one) as the
destination address and 0.0.0.0 as the source address.
The client has to specify 0.0.0.0 as the source address because it doesn't yet have an IP address, and it specifies the broadcast address as the destination address because it doesn't know the address of any DHCP servers. In effect, the DHCP Discover message is saying, "Hey! I am new here. Are there any DHCP servers out there?" - The DHCP server receives the broadcast DHCP Discover message and
responds by sending a DHCP Offer message. The DHCP Offer message
includes an IP address that the client can use.
Like the DHCP Discover message, the DHCP Offer message is sent to the broadcast address. This makes sense because the client to which the message is being sent doesn't yet have an IP address and won't have one until it accepts the offer. In effect, the DHCP Offer message is saying, "Hello there, whoever you are. Here's an IP address you can use, if you want it. Let me know."
What if the client never receives a DHCP Offer message from a DHCP server? In that case, the client waits for a few seconds and tries again. The client will try four times - at 2, 4, 8, and 16 seconds. If it still doesn't get an offer, it will try again after five minutes. - The client receives the DHCP Offer message and sends back a message known as a DHCP Request message. At this point, the client doesn't actually own the IP address. It's simply indicating that it's ready to accept the IP address that was offered by the server. In effect, the DHCP Request message says, "Yes, that IP address would be good for me. Can I have it, please?"
- When the server receives the DHCP Request message, it marks the IP address as assigned to the client and broadcasts a DHCP Ack message. The DHCP Ack message says, in effect, "Okay, it's all yours. Here's the rest of the information you need to use it."
- When the client receives the DHCP Ack message, it configures its TCP/IP stack by using the address it accepted from the server.