The DHCP Conversation
10 years ago
General
These days, almost all networks support the Dynamic Host Configuration Protocol, or DHCP to its friends. It's a method to allow computers to hook up to the network and get relevant information about how to connect to it, including an IP address for it to use. But how exactly does that work? Believe it or not, a conversation occurs between the DHCP server and the new machine.
First, the new machine sends a message on the network's broadcast address. This address (255.255.255.255) is not bound by any subnets. It is everywhere. The machine essentially shouts across the entire physical network. And it sends a DHCPDISCOVER message. Essentially, it says "HEY! Any DHCP Servers out there?"
If a DHCP server is listening on that physical network, it will reply to the machine with a DHCPOFFER message and an IP address. "Yeah, I'm here and you can have 192.168.50.33."
If that machine finds that address acceptable (and for a first-time request, it should have no reason not to), it sends back a DHCPREQUEST message with that address. "May I have 192.168.50.33?"
And if the DHCP server finds that acceptable, it sends back a DHCPACK (DHCP Acknowledge) message with the IP address. "Yes, you may have 192.168.50.33." And life is good.
Mind you there's more than just the IP address given out by the DHCP server. Other common information includes subnet mask, network gateway and DNS servers for the new machine to use. But there are many other pieces of information that can be given out (like BOOTP information, for remote-booting workstations).
Now just because the addresses are dynamic doesn't mean a machine gets a new address every time. Machines are required to renew their address leases after a certain amount of time, even if the machine has not been turned off or disconnected from the network during that period. In that case, the machine sends a DHCPREQUEST to the server with its current address and if things are still cool, the server sends back a DHCPACK.
But if a machine is returning after being gone for a while, chances are still good it'll get the same address it had before provided that address hasn't been given out to another machine. All the DHCP messages contain the requesting machine's MAC address, and it's trivial for a server to go through its old leases, find what address it had given to that MAC address before and give it back out again.
It's also possible on many DHCP servers to make sure a certain MAC address will get a specific IP address when it makes a request. While the same result could be accomplished by giving the machine a fixed IP address, the advantage to doing it through DHCP is that the machine still gets all the extra info provided by DHCP (netmask, gateway, etc) while having a fixed address. The machine need only be set for dynamic address, making configuration by the end user a breeze.
Just in case you don't quite believe the story about the conversation, here's a log dump. The addresses have been changed to protect the guilty.
Aug 21 19:16:43 server dhcpd: DHCPDISCOVER from 4b:1e:3e:ce:2e:1c (SmartPhone) via eth2.1
Aug 21 19:16:43 server dhcpd: DHCPOFFER on 10.8.25.34 to 4b:1e:3e:ce:2e:1c (SmartPhone) via eth2.1
Aug 21 19:16:43 server dhcpd: DHCPREQUEST for 10.8.25.34 (10.8.25.1) from 4b:1e:3e:ce:2e:1c (SmartPhone) via eth2.1
Aug 21 19:16:43 server dhcpd: DHCPACK on 10.8.25.34 to 4b:1e:3e:ce:2e:1c via eth2.1
First, the new machine sends a message on the network's broadcast address. This address (255.255.255.255) is not bound by any subnets. It is everywhere. The machine essentially shouts across the entire physical network. And it sends a DHCPDISCOVER message. Essentially, it says "HEY! Any DHCP Servers out there?"
If a DHCP server is listening on that physical network, it will reply to the machine with a DHCPOFFER message and an IP address. "Yeah, I'm here and you can have 192.168.50.33."
If that machine finds that address acceptable (and for a first-time request, it should have no reason not to), it sends back a DHCPREQUEST message with that address. "May I have 192.168.50.33?"
And if the DHCP server finds that acceptable, it sends back a DHCPACK (DHCP Acknowledge) message with the IP address. "Yes, you may have 192.168.50.33." And life is good.
Mind you there's more than just the IP address given out by the DHCP server. Other common information includes subnet mask, network gateway and DNS servers for the new machine to use. But there are many other pieces of information that can be given out (like BOOTP information, for remote-booting workstations).
Now just because the addresses are dynamic doesn't mean a machine gets a new address every time. Machines are required to renew their address leases after a certain amount of time, even if the machine has not been turned off or disconnected from the network during that period. In that case, the machine sends a DHCPREQUEST to the server with its current address and if things are still cool, the server sends back a DHCPACK.
But if a machine is returning after being gone for a while, chances are still good it'll get the same address it had before provided that address hasn't been given out to another machine. All the DHCP messages contain the requesting machine's MAC address, and it's trivial for a server to go through its old leases, find what address it had given to that MAC address before and give it back out again.
It's also possible on many DHCP servers to make sure a certain MAC address will get a specific IP address when it makes a request. While the same result could be accomplished by giving the machine a fixed IP address, the advantage to doing it through DHCP is that the machine still gets all the extra info provided by DHCP (netmask, gateway, etc) while having a fixed address. The machine need only be set for dynamic address, making configuration by the end user a breeze.
Just in case you don't quite believe the story about the conversation, here's a log dump. The addresses have been changed to protect the guilty.
Aug 21 19:16:43 server dhcpd: DHCPDISCOVER from 4b:1e:3e:ce:2e:1c (SmartPhone) via eth2.1
Aug 21 19:16:43 server dhcpd: DHCPOFFER on 10.8.25.34 to 4b:1e:3e:ce:2e:1c (SmartPhone) via eth2.1
Aug 21 19:16:43 server dhcpd: DHCPREQUEST for 10.8.25.34 (10.8.25.1) from 4b:1e:3e:ce:2e:1c (SmartPhone) via eth2.1
Aug 21 19:16:43 server dhcpd: DHCPACK on 10.8.25.34 to 4b:1e:3e:ce:2e:1c via eth2.1
cetas
∞cetas
You did that via your smart phone? I do hope that is your attempt to try and get back on Steam or Skype here. Also I do hope you are doing ok with the State of Emergency in Washington due to the wildfires, never know if those might jump to Oregon or such.
FA+
