How does a computer obtain an IP address via DHCP?
How does the computer know which device on the network to query? How does the default gateway factor into this? Pretty much, what is the chain of events that occurs when a computer tries to obtain an IP address using DHCP?
The reason I ask is because I'm trying to figure out how to best set up a redundant DHCP server, in case the original fails for whatever reason.
It doesn't know what device to query. Thus it broadcasts its request to the entire subnet. The DHCP server is listening for a certain type of communication and when it hears that specific broadcast it begins the DHCP conversation with the device that broadcasted its request. Take a look at the DORA process for more information.
DORA stands for:
- D iscovery
- O ffer
- R equest
- A cknowledgement
As for the gateway, it can come into play only if it explicitly forwards DHCP traffic to another subnet. That feature is usually called DHCP Relay. Otherwise the gateway ignores the broadcast DHCP message just like it ignores every other broadcast message.
As for redundant DHCP servers, you'll want to keep them both on the same subnet and probably use the 80/20 rule. You can set up failover if you're using CentOS as your DHCP server.
DHCP is (generally) a broadcast protocol, so the client doesn't need to know anything about the network, it simply broadcasts a request.
DHCP servers on the network then see that request and respond to it.
Of course, it's much more complex than that, due to routing, and other network devices. The Wikipedia page is an excellent source.
And the relevant RFC covers the detail.
The reason I ask is because I'm trying to figure out how to best set up a redundant DHCP server, in case the original fails for whatever reason.
First, I laud your interest in learning more about the protocol. That is a good plan.
Second, I thank you for explaining your goal; I think it will help you get a good answer.
Finally, my answer:
For whichever DHCP server you choose to go with, there is likely a failover / redundancy configuration that permits you to set up a redundant DHCP server that can take over automatically (I believe Windows has such, and I know the ISC's DHCP server can). That would be my first choice, as it typically addresses issues with leases given out by the primary DHCP server before its failure, and because it recovers automatically and quickly.
Second choice would be to fully duplicate the configuration on another machine so that you can bring the other machine up manually in case of failure of the first. This isn't as optimal because you'll lose existing lease information and because of the implicit down-time between the first DHCP server failing and when you bring up the replacemnt.
Several steps are involved in obtaining an IP address from a dhcp server.
Discovery message, this message is broadcasted to search for a dchp server
The DHCP servers in the network replies with offer message.
DHCP request message is sent by the client by broadcasting..this message will inform all DHCP servers in the network, which offer was accepted by the client.
DHCP acknowledgement message is sent for the confirmation by the server.