Network

What is DHCP Protocol and How Does it Work?

In this tutorial, we are going to see What is DHCP protocol and how does it work? DHCP stands for Dynamic Host Configuration Protocol. It is a protocol that allows a computer connecting to a network to get dynamically (i.e. without any particular intervention) its configuration (mainly, its network configuration). You only have to specify to the computer to find an IP address by itself by DHCP. The main goal is to simplify the administration of a network.

The DHCP protocol is mainly used to distribute IP addresses on a network, but it was originally designed as a complement to the BOOTP (Bootstrap Protocol) which is used for example when installing a machine over a network (BOOTP is used in close cooperation with a TFTP server on which the client will find the files to be uploaded and copied to the hard disk). A DHCP server can return BOOTP or configuration parameters specific to a given host.
 


 
 

How Does DHCP Protocol Work?

First of all, you need a DHCP server that distributes IP addresses. This machine will be the base for all DHCP requests, so it must have a fixed IP address. In a network, we can have only one machine with a fixed IP address.

The basic communication mechanism is BOOTP (with UDP frame). When a machine is started, it has no information about its network configuration, and especially, the user does not have to do anything special to find an IP address. To do this, the technique used is broadcasting: to find and talk to a DHCP server, the machine will simply send a special broadcast packet (broadcast on 255.255.255.255 with other information like the type of request, the connection ports…) on the local network. When the DHCP server receives the broadcast packet, it will send another broadcast packet (remember that the client does not necessarily have its IP address and therefore cannot be reached directly) containing all the information required for the client.

You might think that a single packet would be sufficient for the protocol to work properly. In fact, there are several types of DHCP packets that can be sent either by the client to the server(s) or by the server to a client:

  • DHCPDISCOVER (to locate available DHCP servers)
  • DHCPOFFER (server response to a DHCPDISCOVER packet, which contains the first parameters)
  • DHCPREQUEST (various requests from the client to extend its lease, for example)
  • DHCPACK (server response containing parameters and the client’s IP address)
  • DHCPNAK (response from the server to inform the client that its lease has expired or if the client announces a bad network configuration)
  • DHCPDECLINE (the client tells the server that the address is already in use)
  • DHCPRELEASE (the client releases its IP address)
  • DHCPINFORM (the client requests local parameters, it already has its IP address)
 

 
The first packet sent by the client is a DHCPDISCOVER packet. The server replies with a DHCPOFFER packet, in particular, to submit an IP address to the client. The client establishes its configuration, then makes a DHCPREQUEST to validate its IP address (request in broadcast because DHCPOFFER does not contain its IP address). The server simply replies with a DHCPACK with the IP address to confirm the allocation. Normally, this is enough for a client to get an efficient network configuration, but it can be more or less long depending on whether the client accepts or not the IP address.
 
 

DHCP Leases:

For network resource optimization reasons, IP addresses are issued with a start date and an end date of validity. This is called a “lease”. A client that sees its lease expiring can ask the server for an extension of the lease with a DHCPREQUEST. Similarly, when the server sees a lease expiring, it will issue a DHCPNAK packet to ask the client if it wants to extend its lease. If the server does not receive a valid answer, it makes the IP address available.

This is the complexity of DHCP: we can optimize the allocation of IP addresses by playing with the duration of the leases. The problem is that if no address is released after a certain period of time, no more DHCP requests can be fulfilled because there are no addresses to distribute.

On a network where many computers are connected and disconnected frequently (e.g. a school or commercial network), it is interesting to offer short leases. However, on a network where most of the computers are fixed and rarely rebooted, long-term leases are sufficient. Don’t forget that DHCP works mainly by broadcasting and this can block bandwidth on small, heavily used networks.
 
mcq-networking-question-answerComputer Network MCQ – Questions and Answers – Part 1Networking MCQs questions with answers to prepare for exams, tests, and certifications. These questions are taken from a real written exam and some parts are…Read More

Leave a Reply

Your email address will not be published. Required fields are marked *