How DHCP works Explained with Examples

This tutorial explains how DHCP works in detail through an example. Learn how DHCP clients obtain an IP configuration from a DHCP server through four DHCP communication steps.

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

This entire process goes through the four steps: Discover, Offer, Request, and Acknowledgment. In this tutorial, we will understand these four steps in detail.

The following image shows all four steps of DHCP communication.

how dhcp works communication steps

Let's understand these steps in detail.

DHCP discovery

When we start a device, it checks whether a valid IP configuration is available or not. If the valid IP configuration is not available, the device generates a special message known as the DHCPDISCOVER message 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 contains protocol specific information and an IP configuration. An IP configuration typically includes the following important information: the IP address for the client, the subnet mask of the proposed IP address, the IP address of the default gateway, the DNS domain name, the DNS server address or addresses, and the 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 know 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 how dhcp server and client work

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".

dora dhcp messages

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

That's all for this tutorial. In the next part of this tutorial, we will understand DHCP configuration parameters and settings 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