You are currently viewing What is DHCP and how it works

What is DHCP and how it works

If you consult the documentation, you will see that DHCP (Dynamic Host Configuration Protocol) is an application protocol that knows how to automatically assign an IP address to any device on the network. Let’s explain this protocol in layman’s terms and how it works.

Look at your computer. It can work on a network by having an IP address that consists of four blocks (octets) of digits separated by dots. For example, It’s like a person’s postal address, only instead of the city, house and flat, you specify the communication nodes and routers. Without the IP address, you won’t be able to communicate with other computers on the network.

Your computer and any other device, when it accesses the network, get a static IP or dynamic IP. A static IP is assigned manually by the network administrator (that could be your company sysadmin or your ISP). A dynamic IP is automatically set when you connect to a network. It is yours only for a specific period. A new connection session almost always means you will be given a new IP. This is convenient when many devices are connected to the network – you don’t need to set network parameters manually for each of them.

DHCP is responsible for automatically assigning an IP address to any device that connects to the network. It is a set of rules and actions that regulate the connection and exchange of information packets between network devices. It works using a client-server model, where the client is your computer or any other machine that requires an IP address. The server distributes these addresses, but in a way, those different devices do not have the same IP address.

Message exchange between DHCP server and client

Data exchange can be broken down into four basic steps, briefly called DORA. Let’s break down each of them.

  1. Discover: The client queries the server. The client (your device) searches the server (DHCP) to get the IP address, DNS, subnet mask and other data needed for the network. To do this, it sends a “DHCPDISCOVER” message to all devices in its network segment. Such requests are called broadcast requests. Only the DHCP server can reply to this message.
  2. Offer: The server replies to the client. When a DHCP server receives a message, it selects and sends a “DHCPOFFER” reply to the client with a free IP address. If a reply is received from several servers at once, the client can select any of them. The client then communicates only with the server.
  3. Request: The client confirms the server configuration. When the client receives the IP address, it sends a “DHCPREQUEST” message with its IP to each DHCP server in the network. This confirms the use of the address, and the network servers understand that the IP is busy and must not be offered to other clients.
  4. Acknowledgement: The server acknowledges Client access. The server remembers that an IP address is reserved for a specific device and sends the address, expiration date and other network settings in a “DHCPACK” message. By applying the received configuration, the client can work on the network.

Other DHCP options

Above, we have listed the basic types of messages that a server and a client can exchange. Now let’s talk about messages you might encounter when communicating with a DHCP server.

  • DHCPINFORM. This asks the client for the working configuration of the local network settings.
  • DHCPNAK. A message from the server to the client that an IP address is being denied.
  • DHCPRELEASE. Tells the client to tell the server to release the IP address.
  • DHCPDECLINE. The client sends a message to the server that the address assigned in DHCP is already in use.
  • DHCPINFORM. The client sends a message to the server to get a static IP address when the configuration settings require a dynamic one.

If the DHCP server and client are on different networks

Many networks are divided into subnetworks. Segmentation makes it possible to significantly improve network efficiency and ensure network security in the event of a compromise or failure in one of the segments. But there is a chance that the server-client bundle will be broken up by routers. And routers usually don’t allow broadcast traffic so that clients and servers from different subnets can’t communicate. They need help.

DHCP relay helps solve the problem by allowing the router to broadcast traffic related to the DHCP protocol. With this setting, full-fledged messaging can take place between client and server.