2 What is DHCP?
DHCP (dynamic host configuration protocol) is a networking protocol that let a client host acquire its IP address as well as
other network related settings (such as DNS servers) from a server.
DHCP is very useful in local area networks, where it is a big hassle, or impossible to configure each host to use a static IP
address. The use of static IP addresses is dangerous. For example, if two hosts set up to use the same static IP address, a lot
of confusion will happen as a result.
The basic mechanism of DHCP is rather simple:
- A client host “C” starts up. It sends a discovery UDP (user datagram protocol) broadcast packet. This is
basically saying “hey, who is in charge around here?”
- The DHCP server of the local network must be set up to accept multicast. Once the DHCP server receives the
discovery UDP packet, it replies “I am the one in charge here, and here is my offer.” Note that at this point,
the host “C” does not have an IP address, yet. As a result, addressing is done directly at the frame layer, using
the MAC (media access control) address of the NIC (network interface card).
- Once “C” receives the offer, it broadcasts another message to accept the offer (well, only if the terms are
acceptable). You may wonder why this message is broadcasted. We’ll explain this later.
- After the DHCP server receives the accept message (which is technically called a request message), it
acknowledges the acceptance.
Here comes a rather big wrench thrown into the gears of DHCP: what if there are multiple DHCP servers on the same
local network? Let’s say there are two DHCP servers, “X” and “Y”. Here’s a scenario:
- Client “C” sends the discovery broadcast packet. Both “X” and “Y” receives the discovery packet.
- “X” offers 192.168.1.32, and “Y” offers 192.168.1.153. Due to the limitations of the link layer, these two
replies are received by “C” sequentially. Let’s say the 192.168.1.32 offer from “X” was received first. “C”
decides to take this offer.
- “C” broadcasts its acceptance of 192.168.1.32 from “X”. Because this acceptance is a broadcast packet, both
“X” and “Y” receive it. “Y” now knows that its offer was not accepted. “Y” should update its own table so
that it also knows that the IP address 192.168.1.32 is now taken.
- “X” sends an acknowledgement packet to “C” to finish the transaction. “Y” doesn’t have to do anything.