Dynamic Host Configuration Protocol


There are basically two ways to assign the IP addresses to any network device. One is Static IP address allocation and the other is dynamic IP address allocation.
 Incase of static configuration of IP address we have following disadvantages:
  1. There is chance of assigning duplicate IP address to the clients is very high when the network is having so many devices.
  2. For every new device that is connected to network, user has to manually assign the IP address.
DHCP (dynamic host configuration protocol) is a protocol which is used to assign the IP addresses to clients dynamically.
Using DHCP protocol we can overcome the problems faced above due to static IP address assignment.
DHCP is a application layer protocol which uses UDP as transport layer. In DHCP configuration, we need to configure one device in a subnet as DHCP server so that all the clients in that subnet receive the IP address from that server dynamically. As DHCP uses broadcast messages (which will be by default dropped by routers), we normally need to configure one DHCP server per subnet. Incase, we don’t want to maintain separate DHCP server per subnet we need to configure DHCP relay agent so that DHCP messages from clients reach to the DHCP server located in the different subnet.

The working flow of DHCP is as follows:

During DHCP configuration, we need to provide the pool of IP addresses that will be provided to DHCP clients.
When DHCP client boots up, it discovers the DHCP server using DHCP discover broadcast message. If DHCP server exists in the network then server responds to client with DHCP offer unicast message which basically includes the IP address which can be used by the client.
If client is ready to accept that IP address then client stores the lease period and DHCP server IP address and assigns IP address to it.
The client in turn respond with the DHCP request broadcast message with the IP address it is going to use and DHCP server it has taken the IP address from so that other DHCP servers in the network if any comes to know about it and don’t send DHCP offer to the client anymore.
The DHCP server in turn responds with DHCPACK unicast message.
Now client maintains the database of the information provided by the DHCP server and client moves to Bound state. Client starts two Timers T1 And T2.T1 is 50% lease period and T2 is 87.5% of lease period. When timer T1 reaches to 50% of Lease period then client moves to renewal state, and starts sending the DHCP request unicast message to the DHCP server to renew the lease. If DHCP server responds with DHCPACK message then its well and good and lease period is extended, and timers T1 & T2 are reset. And same process/state transitions get repeated. However, if DHCP server responds with DHCPUNACK message then it keeps sending DHCP request unicast message to the DHCP server. When Timer T2 expires then DHCP client enters into rebinding state.DHCP client now starts sending the DHCP request rebinding broadcast message with the its IP address and lease information. If any DHCP server in the network gets sufficient lease information and agrees to extend the lease then the client receives a DHCPACK message, rebinding the lease. The client makes note of the server that is now in charge of this lease, the new lease expiration time, and any changed parameters sent by the server. It resets the T1 and T2 timers, and transitions back to the BOUND state. Else the client receives the DHCPNAK message, which tells the client that some server has determined that the lease should not be extended. The client immediately transitions to the INIT state to get a new lease.

Few frequently asked questions on DHCP:
  1. How do I assign the same IP address to a network device always? Suppose I connected one device in network and one IP address is assigned by DHCP server.I will now disconnect the device and connect it after 1 month in the same network. Now I should get same IP address which was assigned in the past.
  2. What is the main difference between renew and rebind in DHCP?
  3. How can i make use of single DHCP server for the hosts located in multiple subnets?

Comments