DHCP stands for Dynamic Host Configuration Protocol. As the name suggests, this protocol is used to dynamically assign an IP address to a new client in a network.
So, if you are already aware of TCP/IP, you already know that all the network devices require an IP address to communicate within a network. Before DHCP, devices used to have statically assigned IP addresses. The network admin had to assign an IP address to every device on a network using network configuration control panel. Later, with the help of DHCP, it became easier to handle a lot of devices in a network dynamically.
Certain terminologies are associated with DHCP. Let us have a look at them.
A scope is a range of IP addressed from where a DHCP server assigns an IP address dynamically to different devices coming into the network.
If the DHCP (Dynamic Host Configuration Protocol) server has the scope of private IP addresses from 192.168.1.100 to 192.168.1.200, it can only accommodate 100 devices at a time, and an IP address is dynamically assigned to a new device moving into the network.
In a network, it is also possible that a network device cannot be assigned a dynamic IP address. For example, the IP address of a default gateway cannot be changed very frequently because it will affect the entire network. That’s why the concept of reservation came in DHCP. Using reservations, we can tell the DHCP server to reserve some of the IP addresses and do not use those in dynamic assigning.
Leasing is the process of dynamically assigning an IP address to a new client in the network for a fixed period. After the leasing time expires, the device either requests for another IP address or the same IP address to be allocated to it.How does DHCP work?
When a new client wants to be a part of the network, it has to go through certain steps of negotiations. Here are those steps:
When a new client tries to join a network, it has no information about the network. So to get more information, the client will broadcast a DHCP Discover packet into the network. This packet is received by each of the nodes in the network.
The source address in the DHCP Discover packet will be 0.0.0.0 because the new client is still not aware of its IP address. However, the client will send its MAC address in the DHCP Discover packet.
If you are well aware of the data link layer from the OSI model then, using MAC address only the communication happens at layer two, i.e., the ethernet layer.
There could also be more than one DHCP server on a network. When all servers receive the DHCP Discover packet, they know that a new machine wants to join the network.
Thus, all the DHCP servers reply by sending DHCP offer packet. This packet contains an IP address being offered by the DHCP server. Upon receiving the DHCP offer packets, it is up to the new machine to choose an offer.
The DHCP (Dynamic Host Configuration Protocol) offer packet contains the following information:
- Client’s MAC address
- The offered IP address
- Subnet mask of the network
- The lease duration
- IP address of the server making the offer
After receiving multiple DHCP offer messages from different DHCP servers, the new client will choose one DHCP server offer, and it will notify the DHCP server by broadcasting using the DHCP request message. This is so because all the DHCP servers should also know that the new client has accepted a server’s offer. So that, others do not try to keep themselves engaged.
Upon receiving the DHCP request packet, the server sends an acknowledgment using the DHCP ACK packet. The server also makes sure that the IP address allotted to the new machine is not allocated to any other client in the network.
DHCP ACK packet contains other network details such as IP address, router address, subnet mask, etc. As the client receives this packet, the client configures itself.
Besides the above four steps, there are other auxiliary DHCP messages as well which helps a network administrator in organizing the network.
DHCP release packet is used mostly when a client is going to leave the network. DHCP release is used to release the connection and allocate the IP address back into the scope, or in simple terms, the lease expires.
The DHCP reservations that we read at the beginning of the article is configured using DHCP inform message. DHCP inform message is used when the network administrator has manually configured a machine. In this case, the server is informed to reserve that IP address and refrain from assigning it to anyone.
DHCP relay agent
If multiple local area networks (LANs) have just one DHCP server, then DHCP relay agent helps in forwarding the DHCP request to a DHCP server and transmitting the response back to the client. That’s because a client device (without an IP address) can’t communicate with the DHCP server directly if the server isn’t present on the client’s local network.
Reliability in DHCP (Dynamic Host Configuration Protocol)
DHCP ensures reliability using two techniques.
- Renewal and,
To ensure that a particular client does not over utilize the network for long and others also get a chance, DHCP uses renewal to ensure reliability. Once half of the lease time has elapsed, each client has to send DHCP request again to get a new IP address or continue using the same IP address. If the server is unreachable then, the client keeps on trying until the server replies.
In some instances, the DHCP server fails to reply. In that case, the client tries to contact the backup server. Otherwise, it will rebroadcast the DHCP request to all the DHCP servers in the network. If rebinding fails, then the lease gets expired, and the client must start the DHCP process all over again.