≡ Menu

What is DHCP and How DHCP Works? (DHCP Fundamentals Explained)

Computer networks can be of any form like a LAN, WAN etc. If you are connected to a local LAN or an internet connection, the IP addresses form the basis of communication over computer networks. An IP address is the identity of a host or a computer device while connected to any network.

In most of the cases when you connect your computer to a LAN or internet, you’ll notice that the IP address and other information like subnet mask etc are assigned to your computer automatically. Have you ever thought about how this happens? Well, in this article we will understand the concept of DHCP that forms the basis of this functionality.

What is DHCP?

DHCP stands for Dynamic Host Configuration Protocol.

As the name suggests, DHCP is used to control the network configuration of a host through a remote server. DHCP functionality comes installed as a default feature in most of the contemporary operating systems. DHCP is an excellent alternative to the time-consuming manual configuration of network settings on a host or a network device.

DHCP works on a client-server model. Being a protocol, it has it’s own set of messages that are exchanged between client and server. Here is the header information of DHCP :

FIELD OCTETS DESCRIPTION
op 1 Type of message
htype 1 type of hardware address
hlen 1 length of hardware address
hops 1 used in case of relay agents. Clients sets them to 0.
xid 4 Transaction ID used by the client and server for a session.
secs 2 Time elapsed (in seconds) since the client requested the process
flags 2 Flags
ciaddr 4 Client IP address.
yiaddr 4 The IP address assigned by server to the client
siaddr 4 Server IP address.
giaddr 4 IP address of the relay agent.
chaddr 16 Hardware address of the client.
sname 64 Host name of the server.
file 128 Boot file name.
options var Additional options

 
Understanding DHCP helps in debugging many network related problems. Read our articles on wireshark and Journey of a packet on network to enhance your understanding on network and network debugging tools.

In the next section, we will cover the working of this protocol.

How DHCP Works?

Before learning the process through which DHCP achieves it’s goal, we first have to understand the different messages that are used in the process.

1. DHCPDISCOVER

It is a DHCP message that marks the beginning of a DHCP interaction between client and server. This message is sent by a client (host or device connected to a network) that is connected to a local subnet. It’s a broadcast message that uses 255.255.255.255 as destination IP address while the source IP address is 0.0.0.0

2. DHCPOFFER

It is DHCP message that is sent in response to DHCPDISCOVER by a DHCP server to DHCP client. This message contains the network configuration settings for the client that sent the DHCPDISCOVER message.

3. DHCPREQUEST

This DHCP message is sent in response to DHCPOFFER indicating that the client has accepted the network configuration sent in DHCPOFFER message from the server.

4. DHCPACK

This message is sent by the DHCP server in response to DHCPREQUEST recieved from the client. This message marks the end of the process that started with DHCPDISCOVER. The DHCPACK message is nothing but an acknowledgement by the DHCP server that authorizes the DHCP client to start using the network configuration it received from the DHCP server earlier.

5. DHCPNAK

This message is the exact opposite to DHCPACK described above. This message is sent by the DHCP server when it is not able to satisfy the DHCPREQUEST message from the client.

6. DHCPDECLINE

This message is sent from the DHCP client to the server in case the client finds that the IP address assigned by DHCP server is already in use.

7. DHCPINFORM

This message is sent from the DHCP client in case the IP address is statically configured on the client and only other network settings or configurations are desired to be dynamically acquired from DHCP server.

8. DHCPRELEASE

This message is sent by the DHCP client in case it wants to terminate the lease of network address it has be provided by DHCP server.

Now as we know about the various DHCP messages, it’s time to go through the the complete DHCP process to give a better Idea of how DHCP works. Note that the steps mentioned below assume that DHCP functionality is enabled by default on the client side.

Here are the steps :

  • Step 1: When the client computer (or device) boots up or is connected to a network, a DHCPDISCOVER message is sent from the client to the server. As there is no network configuration information on the client so the message is sent with 0.0.0.0 as source address and 255.255.255.255 as destination address. If the DHCP server is on local subnet then it directly receives the message or in case it is on different subnet then a relay agent connected on client’s  subnet is used to pass on the request to DHCP server. The transport protocol used for this message is UDP and the port number used is 67. The client enters the initializing stage during this step.
  • Step 2: When the DHCP server receives the DHCPDISCOVER request message then it replies with a DHCPOFFER message. As already explained, this message contains all the network configuration settings required by the client. For example, the yaddr field of the message will contain the IP address to be assigned to client. Similarly the the subnet mask and gateway information is filled in the options field. Also, the server fills in the client MAC address in the chaddr field. This message is sent as a broadcast (255.255.255.255) message for the client to receive it directly or if DHCP server is in different subnet then this message is sent to the relay agent that takes care of whether the message is to be passed as unicast or broadcast. In this case also, UDP protocol is used at the transport layer with destination port as 68. The client enters selecting stage during this step
  • Step 3: The client forms a DHCPREQUEST message in reply to DHCPOFFER message and sends it to the server indicating it wants to accept the network configuration sent in the DHCPOFFER message. If there were multiple DHCP servers that received DHCPDISCOVER then client could receive multiple DHCPOFFER messages. But, the client replies to only one of the messages by populating the server identification field with the IP address of a particular DHCP server. All the messages from other DHCP servers are implicitly declined. The DHCPREQUEST message will still contain the source address as 0.0.0.0 as the client is still not allowed to use the IP address passed to it through DHCPOFFER message. The client enters requesting stage during this step.
  • Step 4: Once the server receives DHCPREQUEST from the client, it sends the DHCPACK message indicating that now the client is allowed to use the IP address assigned to it. The client enters the bound state during this step.

The Concept of Lease

With all the necessary information on how DHCP works, one should also know that the IP  address assigned by DHCP server to DHCP client is on a lease. After the lease expires the DHCP server is free to assign the same IP address to any other host or device requesting for the same. For example, keeping lease time 8-10 hours is helpful in case of PC’s that are shut down at the end of the day.  So, lease has to be renewed from time to time. The DHCP client tries to renew the lease after half of the lease time has expired. This is done by the exchange of DHCPREQUEST and DHCPACK messages. While doing all this, the client enters the renewing stage.

Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • Jalal Hajigholamali March 20, 2013, 1:37 pm

    Hi,

    Very nice and useful article

  • Ehan Chang March 20, 2013, 6:27 pm

    excellent! I can make it clear what I want to know.

  • Shad March 21, 2013, 2:19 am

    Great stuff Himanshu…Thanks for the post..

  • Veera March 21, 2013, 7:58 am

    quite useful stuff. Thankyou!

  • TD March 21, 2013, 10:07 am

    Nice post.

    Minor spelling error “recieved”

  • Anish Rana March 22, 2013, 1:51 am

    Good post.
    Defining the step by step process is really very good.

  • Manish Motilal Ratnani March 23, 2013, 9:17 am

    Sir
    What i want is a book on linux OS as i have switched from DOS and Windows to linux
    for the purpose of embedded systems prog . in c and java. the book should be a compiled ver. of one complete self explaining book . sir i switch over to your other books after learning linux os
    Thanking you
    Manish

  • Anonymous March 24, 2013, 4:34 am

    What is IP helper address ? IP helper address on the switch/router ?

  • Harishkumar March 27, 2013, 1:37 am

    Really good explanation..

  • Ramesh April 24, 2013, 8:36 pm

    Hi friend,

    Very useful information about how DHCP is really works on the network. Keep posting. Thanks.

  • Antony July 3, 2013, 9:21 am

    hi,thanks,i knew lot of information from here..its very useful

  • Alex September 4, 2013, 8:59 am

    Thanks for information!

    Interesting, what happens in case there are 2 DCHP servers in LAN?

  • Ashwini October 23, 2013, 1:54 am

    Very good and detailed explanation.

  • An Yanon October 30, 2013, 5:03 am

    Enjoyed article. Very clear and concise. I would have liked to see an example of dhcpnak. I’ll Google to learn more about dhcp. Thanks for excellent tutorial.

  • Beto November 4, 2013, 4:13 pm

    Very nice and simple way you got to explain this important topic.

    Keep up the good job!

  • Alishekhani December 4, 2013, 10:24 am

    Supper Topic

  • sg December 5, 2013, 4:53 am

    Awesome article. Concise, specific and complete.
    Very informative and extremely useful.

    Sure wish there was similar on DNS.

  • Tikkam chand J December 18, 2013, 1:00 am

    Good work on the documentation. It’s really simple and helpful

  • Wale Show January 24, 2014, 6:10 pm

    @Anonymous

    IP-Helper is used when the DHCP server is not in the same subnet as the requesting client. The ‘helper’ is in the same subnet as the requesting client and perform a relay function between the client and dhcp server

  • Shubham Kamboj February 9, 2014, 11:51 pm

    Please Give the proper explanation of DHCPREQUEST and DHCPACK whether they are broadcast or unicast.

  • Thendral K February 9, 2014, 11:52 pm

    Can you please elaborate the acknowledgement ie.DHCPACK.. whether it is a broadcast or unicast..

  • Nagaraj Ukkali May 19, 2014, 12:36 pm

    Good Information for beginners

  • shahid June 26, 2014, 2:18 am

    very nice explanation about DHCP server..

  • Imran September 4, 2014, 4:22 am

    Very good to understand

  • pradip dasila September 16, 2014, 3:33 am

    Very helpful article to known all about how dhcp works. thanks for the article.

  • hpc September 26, 2014, 1:24 am

    Excellent explanation , thanks,

    But one doubt , I get a IP of 192.168.10.109 to my embedded h/w all the time but when some other device is pssessing this IP
    I mean the h/w always gets the same ip (even same in different days),
    So is it saved somewhere in client or server ?
    can you please explain this behavior to me ?

  • Ravi Teja October 8, 2014, 1:05 am

    nice article

  • Sura December 19, 2014, 5:05 am

    Thank You very much 🙂
    it’s very helpfull

  • Anonymous January 14, 2015, 11:39 am

    it gave clear info

  • Jyoti January 29, 2015, 5:47 am

    Very good article…..
    Keep posting!!!!

  • rr April 13, 2015, 1:47 am

    nice article about DHCP working

  • Boparai April 29, 2015, 11:24 am

    very nice explain
    Tanks you

  • hanumant ghodekar April 30, 2015, 5:58 am

    thnx

  • Mangal July 3, 2015, 1:23 am

    Nice and crisp detailed..

  • Mehrshad Shahmohammadi August 5, 2015, 6:26 am

    thanks for article

  • jawad September 17, 2015, 12:31 am

    thanku sir detail description of dhcp

  • Qais Alazzam October 17, 2015, 3:29 am

    thank you for the details…

  • Jithesh PP November 5, 2015, 7:17 am

    Very useful article. Thanks

  • Anonymous December 1, 2015, 12:14 pm

    Excellent article on DHCP

  • Anonymous February 29, 2016, 10:37 pm

    very good article

  • Harish April 4, 2016, 1:44 am

    thanks for help

  • Anonymous May 11, 2016, 5:59 am

    really superb material for the beginners…..Thanks for it.

  • Hariram Ale Magar May 19, 2016, 9:21 pm

    Nice article ………

  • Shiwani December 19, 2016, 5:39 am

    Superb article and with easy words….. Excellent way of explanation.. ?

  • Rahul January 6, 2017, 12:55 pm

    Good one

  • Subin January 27, 2017, 1:57 am

    Good post

  • Subheesh January 27, 2017, 2:13 am

    Nice….

  • Sonali February 9, 2017, 8:41 am

    Hey Ramesh, all of your articles are excellent.
    Thanks a lot for sharing.

  • Shahzer Syed May 11, 2017, 3:31 am

    Very conceptual and very helpful.

  • Ihor May 11, 2017, 1:52 pm

    Thanks for detail explanation.

  • RK June 22, 2017, 6:17 pm

    How to check DHCP server broadcast IP address and subnet mask