Dynamic Host Configuration Protocol (DHCP)

Broken Code
5 min readDec 11, 2021

Introduction:

DHCP (Dynamic Host Configuration Protocol) is an application layer protocol that automatically provides a variety of network configuration data such as user IP address, subnet mask, default gateway IP address, DNS server IP address and so on to a host device. It is a client/server protocol and uses UDP port 67 (server) and 68 (client) for the communication between client and server.

DHCP Clients:

Servers and network infrastructure devices such as routers and switches will not typically be DHCP clients. Common DHCP clients are: desktops, laptops, phones etc. DHCP is enabled on these devices because :

1: They are large in number.

2: They may be mobile so configuring them manually would be inefficient.

3: They don’t accept incoming connections so it would not matter if their IP address changes.

Benefits of DHCP:

  • Centralized and automated IP configuration.
  • Ease of adding new clients to a network.
  • Minimizes configurational errors caused by manual IP address configuration.

DORA Process:

D(Discover): This message is generated by DHCP Client in order to discover if there is any DHCP server present in a network or not. This message is broadcasted to all devices present in a network to find the DHCP server.

Source MAC address = host mac address
Source IP address = 0.0.0.0 (represents host has no IP address)
Destination MAC address = FF.FF.FF.FF.FF.FF
Destination IP address = 255.255.255.255

O(Offer): The server will respond to client with IP address and other configuration information. This message is broadcasted by server. If there are more than one DHCP servers present in the network then client will accept the first DHCP OFFER message it receives.

Source IP address = Server IP address
source MAC address = Server MAC address
Destination IP address = 255.255.255.255
Destination MAC address = FF.FF.FF.FF.FF.FF

R(Request): The DHCP Client broadcasts ARP packet (gratuitous arp) to check if there is any other host present in the network with same offered IP address. If there is no reply by any other device then there is no device with same TCP/IP configuration in the network. As a result DHCP client sends the DHCP request message to the server showing the acceptance of IP address.

Note: If there is a reply to the ARP by any device, the DHCP client sends DHCP Decline Message to the server showing the offered IP address is already in use.

Source MAC address = host mac address
Source IP address = 0.0.0.0
Destination MAC address = FF.FF.FF.FF.FF.FF
Destination IP address = 255.255.255.255

A(Acknowledgement): The server will make an entry of the DHCP client with the offered IP address and lease time. This IP address will not be provided by server to any other host. The DHCP client will have the IP address provided by server.

Source IP address = Server IP address
source MAC address = Server MAC address
Destination IP address = 255.255.255.255
Destination MAC address = FF.FF.FF.FF.FF.FF

Some other important points:

1: IP Address Lease Time: The time during which the client is allowed to use the IP address allocated by DHCP server is known as IP address lease time.

The DHCP server does not allocate an IP address to a client permanently. Instead it sets a time duration for that IP address and allows the client to use the allocated IP address for only that duration. If the client has to continue the allocated IP address for longer than the lease duration, it requests the DHCP server for renewal of the lease. Otherwise it performs an IP address release procedure.

In case of IP renewal, no DHCP Discover/Offer process is required. Also, the client and the server do not broadcast the DHCP Request/Acknowledgement messages but unicast them as the DHCP server and client have already known each other’s IP address. The client begins its IP address renewal procedure at the mid-point of the lease time.

            IP renewal time = lease time / 2

2: In case DHCP server is on other subnet, then DHCP relay agent is used.

DHCP relay agent is any TCP/IP host which is used to forward traffic between DHCP server and DHCP client when the server is present on the different network. The communication between DHCP relay agent and DHCP server is unicast.

3: In DHCP, the client and the server mainly exchange 4 DHCP messages (DORA process) in order to make a connection but there are actually 8 DHCP messages in the process viz;

  • DHCP DISCOVER
  • DHCP OFFER
  • DHCP REQUEST
  • DHCP DECLINE
  • DHCP ACK
  • DHCP NAK
  • DHCP RELEASE
  • DHCP INFORM

DHCP RELEASE: Once the client is logged-off, it returns the allocated IP address to the DHCP server by unicasting a DHCP Release message to the DHCP server.

DHCP negative acknowledgement message: DHCP NAK message is used by DHCP Server to reject a request of DHCP Client. For example when the server has no IP address unused or the pool is empty, then this message is sent by the server to client.

4: DHCP Option Numbers

Option No.         Meaning1                 Subnet Mask
3 Router IP Address
6 DNS Server IP Address
51 IP Address Lease Time
53 DHCP Message Type
82 Relay Agent Information

5: DHCP Message Type (option 53) Values:

Message type    valueDHCP DISCOVER     1
DHCP OFFER 2
DHCP REQUEST 3
DHCP DECLINE 4
DHCP ACK 5
DHCP NAK 6
DHCP RELEASE 7
DHCP INFORM 8

To know more about DHCP I will recommend to go through this article NETMANIAS DHCP.

--

--

Broken Code
Broken Code

No responses yet