Network Basics: The DHCP client

So what is DHCP?

How automatic configuration works

The DHCP client

When you bring your laptop over to your buddies house and plug into their network, your internet is ready by "magic".

This is achieved by the DHCP client daemon dhcpcd. When a new network link comes on line (e.g plugging in an ethernet cable, or connecting over WiFi), your machine sends announces itself to all devices on the link, and, if present, a DHCP server (usually the network's router) replies back, informing your computer of the settings for the particular network, and reserves you an IP address. So that it remembers you, it keeps a record of your MAC address, which is a unique identifier (although it's possible to present a fake one)

You can think of this as being equivalent to your friend giving you a piece of paper with the IP, netmask, gateway, dns server etc, and you manually entering it in. An important thing to remember (and many teachers fail to make this clear) is that DHCP does not actually do any of the configuration, it merely informs the system of the settings required for the network.

Therefore DHCP is platform independent, it does not need to know or care how to set the IP or DNS on your operating system, all it does is tell the system what the settings are.

After receiving this information, it is up to the system to actually do the configuration. A correctly configured DHCP server will happily serve an IP address to any internet connectable device, whether it be a lightbulb, iPhone, Linux workstation, Windows laptop, or cisco router. However, being different operating systems, windows, linux, and lightbulbs all implement network configuration their own way.

So what's the next step?

Each device has its own standards compliment* implementation of the DHCP client daemon. After receiving a response from the DHCP server, it feeds variables such as $new_ip_address, $new_subnet_mask etc into a script. This script then runs the commands appropriate for the system, feeding them the values. This can either be done via the system itself, or in the case of linux, it uses shell/command line utilities, for the most part, emulating an admin typing by hand.

In Linux, we can see this in action. Here we see the part of the script that adds the IP address

Figure 0.1: An excerpt from /sbin/dhclient-script showing how the new address is added using the ip cmd

We can also customize options in the dhclient.conf file.

DHCP leases are ephemeral.

A last point to mention, the information given to the client is often, but not always, ephemeral (short lived). The WiFi network at your coffee shop only has a limited number of IP addresses, and when an IP is given to you, it can't be given to anyone else, because devices inside a network must have unique IP addresses. Therefore, if everyone whose ever connected is given their ip for life, we would run out of addresses almost instantly. So, the information given by the DHCP server is valid only for a limited amount of time. After this period, the client must repeat the process