How DHCP works Explained with Examples

This tutorial explains what DHCP is and how it works in detail. Learn the main functions of the DHCP, advantages and disadvantages of the DHCP, and DHCP address allocation Methods.

Each device in an IP network requires a valid IP configuration. If the network size is small, an administrator can manually provide an IP configuration to each device. But if the network size is large, assigning and managing the IP configuration on each device can be a challenging task.

For example, suppose you work as a network administrator in a company that has more than 2000 devices in its network. The company bought a new Internet connection and asked you to configure all devices to use the new Internet connection.

Depending on how you previously configured IP configuration on all devices, this task may be an easy or difficult task for you. If you have previously configured the IP addresses on these devices manually, now you have to manually change the configuration of each device.

However, if you have used DHCP, then you have to change the configuration on the DHCP server only. When the clients either reboot or renew their IP configuration, they will automatically acquire the new IP configuration from the DHCP server.

What is the DHCP?

DHCP is a service. It allows devices to acquire their IP configuration dynamically. It is defined in RFC 2131 and 2939. It works in the server/clients model. The server offers and delivers IP configuration. Clients request and acquire an IP configuration.

When a host (DHCP client) needs an IP configuration, it connects to a DHCP server and requests for an IP configuration. DHCP server contains several pre-configured IP configurations. DHCP server, upon receiving a request from the DHCP client, offers an IP configuration from all available IP configurations.

This entire process goes through the four steps: Discover, Offer, Request, and Acknowledgment. The following image shows these steps.

how dhcp works

Let's understand these steps in detail.

DHCP discovery

When you start a device, the device checks whether a valid IP configuration is available on the device or not. If the valid IP configuration is not available, the device generates a special message known as DHCPDISCOVER and broadcasts this message on the local LAN segment.

To broadcast DHCPDISCOVER messages, the device uses the and as the source address and destination address, respectively.

The and are two special addresses. Any device, whether it has a valid IP configuration or not, can use these addresses to send local broadcast messages.

From these addresses, the is used as the source address. If a device does not have the source address, it can use this address to send broadcast messages. is the local broadcast address. Any message sent on this address is received by all hosts of the local network.

DHCP offer

Since the client sends the DHCPDISCOVER message to the local broadcast address, if a DHCP server is configured on the local network, it will also receive the message. If multiple DHCP servers are configured on the local network, they all will receive the DHCPDISCOVER message.

If multiple DHCP servers are available, based on their configuration, one of them or all of them can reply to the DHCPDISCOVER message. In reply to the DHCPDISCOVER message, a DHCP server sends a DHCPOFFER message to the client.

Since the client does not have an IP address, the DHCP server cannot send the DHCPOFFER message directly to the client. Because of this, the server sets the destination address to In other words, the server also broadcasts the DHCPOFFER message to the local network.

The DHCPOFFER message includes the following important information: IP address of the client, subnet mask of the segment, IP address of the default gateway, DNS domain name, DNS server address or addresses, and TFTP server address or addresses.

Apart from these, the DHCPOFFER message also contains other protocol-specific information such as the lease duration and client ID. This information is required by the core functions of DHCP.

DHCP request

All hosts in the local network receive the DHCPOFFER message. The host that sent the DHCPDISCOVER message accepts the DHCPOFFER message. Except the original host, all other hosts ignore the DHCPOFFER.

How does a host find out whether the broadcasted DHCPOFFER message is for it or not?

The DHCPDISCOVER message contains the host's MAC address. When a DHCP server broadcasts a DHCPOFFER message, it also includes the host's MAC address in a parameter known as the client ID. When hosts receive the DHCPOFFER message, they check the client ID field in the message. If a host sees its MAC address in the client ID field, the host knows that the message is meant for it. If a host sees the MAC address of another host in the client ID field, the host knows that the message is not intended for it.

Depending on the number of DHCP servers, a host may receive multiple DHCPOFFER messages. If a host receives multiple DHCPOFFER messages, it accepts only one message and tells the corresponding server with a DHCPREQUEST message that it wants to use the offered IP configuration.

If only one DHCP server is available and the provided IP configuration conflicts with the client’s configuration, the client can respond with a DHCPDECLINE message. In this situation, the DHCP server offers another IP configuration.

When DHCP servers receive the DHCPREQUEST message, besides the server whose offer has been accepted, all other servers withdraw any offers that they might have made to the client and return the offered address to the pool of available addresses.

The DHCPREQUEST message contains a Transaction ID field. Just like hosts use the client ID field of the DHCPOFFER message to know whether the message is intended for them or not, DHCP servers use the Transaction ID field of the DHCPREQUEST message to know whether their offer has been accepted or not.

DHCP acknowledgment

When the DHCP server receives a DHCPREQUEST message from the client, the configuration process enters its final stage. In this stage, the server sends a DHCPACK message to the client.

The DHCPACK message is an acknowledgment to the client indicating that the DHCP server has received the DHCPREQUEST message of the client, and the client can use the offered IP configuration.

In some cases, the server may also respond with a DHCPNACK message. The DHCPNACK message tells the client that the offer is no longer valid and the client needs to request an IP configuration again. Typically, this occurs when the client takes too long to respond with a DHCPREQUEST message after receiving a DHCOFFER message from the server. In such a case, the client can make a new request for another IP configuration.

The following image shows the above steps.

dhcp steps explained

The following table summarizes messages that are used in each stage.

Discover The DHCP client broadcasts this message to find a DHCP server.
Offer The DHCP server broadcasts this message to lease an IP configuration to the DHCP client.
Request The DHCP client uses this message to notify the DHCP server whether it accepts the proposed IP configuration or not.
Acknowledgment The DHCP server uses this message to confirm the DHCP client that it can use the offered IP configuration.

An easy way to remember these messages in the correct order is to think of the popular children's show "Dora the Explorer".

dhcp dora steps

Each letter of the spelling DORA corresponds to the first letter of each step: D (Discover), O (Offer), R (Request), and A (Acknowledgment). Just as DORA discovers new things in its show, a DHCP client discovers a new IP configuration in the process.

DHCP Address Allocation Methods

To provide IP configuration, a DHCP server can use three mechanisms. These mechanisms are the following.

Static allocation

In this method, the administrator configures an allocation table on the DHCP server. In this table, the administrator fills the MAC addresses of all clients and assigns an IP configuration to each client.

The DHCP server uses the allocation table to provide an IP configuration. When a client requests an IP configuration, the DHCP server checks the table and finds a match. If the DHCP server finds a match, the DHCP server offers the IP configuration that is associated with the MAC address of the client in the match.

Dynamic allocation

In this method, the administrator configures a range of IP addresses on the DHCP server. The DHCP server assigns an IP configuration from the configured range to each client that requests an IP configuration.

In this method, the DHCP offers the IP configuration only for a specific time. This specific time is known as a lease. The IP configuration remains valid until the lease duration is over. Once the lease period is over, the client is required to obtain a new IP configuration from the server.

Automatic allocation

Same as the dynamic method, in this method, the administrator also configures a range of IP addresses on the DHCP server and the DHCP server assigns an IP configuration from the configured range to each client that requests an IP configuration.

Unlike the dynamic method, in this method, the DHCP server assigns IP configuration permanently. To assigns an IP configuration permanently, the DHCP server sets the lease duration to infinite. As a result, once the DHCP server chooses an IP configuration from the pool and assigns the IP configuration to a client, the IP configuration remains with that same client indefinitely.

That's all for this tutorial. In the next part of this tutorial, we will understand the configuration settings of the DHCP server in detail. If you like this tutorial, please don't forget to share it with friends.


ComputerNetworkingNotes CCNA Study Guide How DHCP works Explained with Examples