Explaining technology as a story - DHCP

Who am I?

When people ask me something technical, I frequently find it useful to tell the basics as a story or an analogy. Obviously all these stories have limitations to how accurate they can get, but it’s surprising how well it gets people to understand what you mean. So this post is part of a series of “explaining technology as a story”

DHCP

For a machine to be able to talk over IP it, naturally, needs an IP address. And that address needs to be unique on the local network.

Now for small networks you might be able to do this by manually configuring the address on each machine (e.g. on a home network you might do something like “my desktop is 192.168.0.10; the printer is 192.168.0.11; the laptop is 192.168.0.11; the X-box is…“). You might also want to do that if you have a bunch of servers where you need to know the address.

But this can be a pain, and it’s a lot of work to keep up. Even in a home environment do you really want to have to allocate everything? Your desktop, your laptop, your phone, your smart-TV, your DVR, your X-box, your IoT light-switch, IoT bulbs… I look at stuff in my house with an IP address and there’s a lot.

So what we do is use DHCP (“Dynamic Host Configuration Protocol”).

When a machine is added to the network (e.g. plugged into to an ethernet port, or connected to WiFi) the machine will send out a message, asking for what IP address to use (“Who am I, on this network?”).

The process has been given the name DORA, after the four steps:

  • DISCOVER - the client calls out to the local network “Hey, can anyone tell me what my address is?”
  • OFFER - A DHCP server on the network sends a reply “Oh, hi! If you like you can have address 192.168.0.100”
  • REQUEST - The client tries to confirm this “Hey, server, is it OK if I use address 192.168.0.100?”
  • ACKNOWLEDGE - The server responds. “Yep, that’s fine. Oh, you might also want to know these are the details default route, and the DNS servers, and the time server and so on. BTW, check back in no later than 3 hours later just in case this has changed”

If this fails for any reason (maybe the DHCP server isn’t working, or it doesn’t think there’s any free addresses) then the client will try a few times and then give up. At that point you might notice you get no address or you might get an address in the 169.254.. range (Windows, for example, will use the 169.254 range).

At roughly the half the check back time the client will try to refresh the values. It does that by jumping straight to the REQUEST part; “Hey, server, can I keep using this address?” If everything is OK the server will respond with its normal “That’s fine” response. If the server doesn’t like it then it might respond with a NAK (“No, that’s not good, ask for a new address”) and the client will go back to the DISCOVER part.

This refresh process is useful. It allows the server to update the client (eg if you changed your DNS servers, for example, the clients will eventually pick up the change). It also allows for the server to know if a client has left the network, so it can re-use the address elsewhere.

Static configuration and Dynamic DNS

Many DHCP servers, including the one built into many home routers, allows you to reserve addresses. For example, in an office you might have a printer on the same network as workstations. While the workstations can change address, the printer should always get the same one. To do this you would use the printer’s MAC address (this is the low level address built into the ethernet or WiFi card) and associate it with a fixed address. Now at the OFFER state the DHCP server will always respond with that address.

Now the REQUEST phase can be a little more complicated. When the client is requesting an address it can include additional information, such as “BTW, my name is ‘Stephens_Desktop’“. The server can use this information to update the DNS server’s configuration, so other machines can use the name. You don’t need to know what IP address a client received if the DNS is automatically updated.

Summary

In many offices desktop segments may have a Windows based DHCP and DNS server, which are also hooked into Active Directory. When a desktop is rebooted or a laptop connected it will use the DHCP server to get all the necessary details to talk on the network.

This process is fundamentally the same as when you turn on your X-Box at home, getting an address from your home router which typically has DHCP and DNS servers built into it.

Large or small deployments; DHCP is very common!