Why does it take seconds to obtain IP address via DHCP?
Solution 1:
In addition to the actual acquisition of the DHCP lease from the DHCP server (which typically doesn't take very long), some servers will first ping the IP address it's about to hand out before it actually hands it out to verify that it's not already in use on the network - this takes a few seconds to time out. The client sometimes will do the same (again, to prevent IP address conflicts) which will add some more time. Then, on top of that, some clients will also register their DNS entries etc.
Solution 2:
DHCP might take a bit longer time because it involves a series of transactions, not with a single server but with all the devices on the network during the initial request, as it sends a broadcast message.
If you check the RFC for DHCP,
http://www.faqs.org/rfcs/rfc2131.html
you can clearly see the the series of negotiations involves. At the beginning the client sends DHCPDISCOVER to all the devices on the LAN, then the servers running dhcp service return DHCPOFFER message. The client might also wait to get responses from all available dhcp servers before it picks one. Then it sends a DHCPREQUEST with an identifier which indicates which server it has chosen as its ip provider. Finally it gets DHCPACK with all the configuration parameters. This is just a summary of the "3.1 Client-server interaction - allocating a network address" from the RFC.
From my experience dhcp takes long time mainly in large LAN setting with lots of nodes connected. In a homenetwork with just a single dhcp server(WIFI router for instance) and one or two pcs, it is pretty fast.
Solution 3:
Two reasons (and solutions) I found when I wanted fast replies from my DHCP server.
1) My DHCP did a ping of the address it wanted to allocate. This added 3 seconds delay. I removed this by changing the DHCP config to have a mapping for MAC Address to IP address. This is basically using DHCP to allocate a static address. This removed the 3 second delay for me.
2) I have an isolated network, however, you may get this at times. There was a DNS look up being done, which for me resulted in many seconds delay from getting an IP Address from DHCP. In the DHCP server config there were options for our domain and DNS servers. After removing DNS options and above change I got instant replies from the DHCP server. (**)
These issues were what I found in my setup. Your milage may vary.
cheers
LB
(**) If I had a penny for every time a failed DNS lookup caused a delay which resulted in a strange knock on affect which resulted in me scratching my head, I would have many many pennies.