Home > DHCP Tutorial

DHCP Tutorial

June 18th, 2015 Go to comments

In IP environment, before a computer can communicate to another one, they need to have their own IP addresses. There are two ways of configuring an IP address on a device:
+ Statically assign an IP address. This means we manually type an IP address for this computer
+ Use a protocol so that the computer can obtain its IP address automatically (dynamically). The most popular protocol nowadays to do this task is called Dynamic Host Configuration Protocol (DHCP) and we will learn about it in this tutorial.

A big advantage of using DHCP is the ability to join a network without knowing detail about it. For example you go to a coffee shop, with DHCP enabled on your computer, you can go online without doing anything. Next day you go online at your school and you don’t have to configure anything either even though the networks of the coffee shop and your school are different (for example, the network of the coffee shop is 192.168.1.0/24 while that of your company is 10.0.0.0/8). Really nice, right? Without DHCP, you have to ask someone who knows about the networks at your location then manually choosing an IP address in that range. In bad situation, your chosen IP can be same as someone else who is also using that network and an address conflict may occur. So how can DHCP obtain an suitable IP address for you automatically? Let’s find out.

DHCP_Advantages.jpg

How DHCP works

1. When a client boots up for the first time (or try to join a new network), it needs to obtain an IP address to communicate. So it first transmits a DHCPDISCOVER message on its local subnet. Because the client has no way of knowing the subnet to which it belongs, the DHCPDISCOVER is an all-subnets broadcast (destination IP address of 255.255.255.255, which is a layer 3 broadcast address) and a destination MAC address of FF-FF-FF-FF-FF-FF (which is a layer 2 broadcast address). The client does not have a configured IP address, so the source IP address of 0.0.0.0 is used. The purpose of DHCPDISCOVER message is to try to find out a DHCP Server (a server that can assign IP addresses).

DHCP_Discover.jpg

2. After receiving the discover message, the DHCP Server will dynamically pick up an unassigned IP address from its IP pool and broadcast a DHCPOFFER message to the client(*). DHCPOFFER message could contain other information such as subnet mask, default gateway, IP address lease time, and domain name server (DNS).

DHCP_Offer.jpg

(*)Note: In fact, the DHCPOFFER is a layer 3 broadcast message (the IP destination is 255.255.255.255) but a layer 2 unicast message (the MAC destination is the MAC of the DHCP Client, not FF-FF-FF-FF-FF-FF). So in some books they may say it is a broadcast or unicast message.

3. If the client accepts the offer, it then broadcasts a DHCPREQUEST message saying it will take this IP address. It is called request message because the client might deny the offer by requesting another IP address. Notice that DHCPREQUEST message is still a broadcast message because the DHCP client has still not received an acknowledged IP. Also a DHCP Client can receive DHCPOFFER messages from other DHCP Servers so sending broadcast DHCPREQUEST message is also a way to inform other offers have been rejected.

DHCP_Request.jpg

4. When the DHCP Server receives the DHCPREQUEST message from the client, the DHCP Server accepts the request by sending the client a unicast DHCPACKNOWLEDGEMENT message (DHCPACK).

DHCP_Acknowledgement.jpg

In conclusion there are four messages sent between the DHCP Client and DHCP Server: DHCPDISCOVER, DHCPOFFER, DHCPREQUEST and DHCPACKNOWLEDGEMENT. This process are often abbreviated as DORA (for Discover, Offer, Request, Acknowledgement).

After receiving DHCPACKNOWLEDGEMENT, the IP address is leased to the DHCP Client. A client will usually keep the same address by periodically contacting the DHCP server to renew the lease before the lease expires.

If the DHCP Server is not on the same subnet with the DHCP Client, we need to configure the router on the DHCP client side to act as a DHCP Relay Agent so that it can forward DHCP messages between the DHCP Client & DHCP Server. To make a router a DHCP Relay Agent, simply put the “ip helper-address <IP-address-of-DHCP-Server>” command under the interface that receives the DHCP messages from the DHCP Client.

DHCP_Relay_Agent.jpg

As we know, router does not forward broadcast packets (it drops them instead) so DHCP messages like DHCPDISCOVER message will be dropped. But with the “ip helper-address …” command, the router will accept that broadcast message and cover it into a unicast packet and forward it to the DHCP Server. The destination IP address of the unicast packet is taken from the “ip helper-address …” command.

When a DHCP address conflict occurs

During the IP assignment process, the DHCP Server uses ping to test the availability of an IP before issuing it to the client. If no one replies then the DHCP Server believes that IP has not been allocated and it can safely assign that IP to a client. If someone answers the ping, the DHCP Server records a conflict, the address is then removed from the DHCP pool and it will not be assigned to a client until the administrator resolves the conflict manually.

Configure a DHCP Server on Cisco router

Instead of using a separate computer/server as a DHCP Server, we can save the cost and configure a Cisco router (even a Layer 3 Cisco switch) to work as a DHCP Server. The following example configuration will complete this task:

Configuration Description
Router(config)#ip dhcp pool CLIENTS Create a DHCP Pool named CLIENTS
Router(dhcp-config)#network 10.1.1.0 /24 Specifies the subnet and mask of the DHCP address pool
Router(dhcp-config)#default-router 10.1.1.1 Set the default gateway of the DHCP Clients
Router(dhcp-config)#dns-server 10.1.1.1 Configure a Domain Name Server (DNS)
Router(dhcp-config)#domain-name 9tut.com Configure a domain-name
Router(dhcp-config)#lease 0 12 Duration of the lease (the time during which a client computer can use an assigned IP address). The syntax is “lease {days[hours] [minutes] | infinite}”. In this case the lease is 12 hours. The default is a one-day lease.
Before the lease expires, the client typically needs to renew its address lease assignment with the server
Router(dhcp-config)#exit  
Router(config)# ip dhcp excluded-address 10.1.1.1 10.1.1.10 The IP range that a DHCP Server should not assign to DHCP Clients. Notice this command is configured under global configuration mode
Comments (50) Comments
Comment pages
  1. ashwath
    January 18th, 2016

    thank u sir

  2. akhun
    January 20th, 2016

    hey friends im preparing for my ccna exam. Can Anyone please send me latest ccna dumps. on {email not allowed} . Many thankx

  3. akhun
    January 20th, 2016

    hey friends im preparing for my ccna exam. Can Anyone please send me latest ccna dumps. on my emaid id :{email not allowed} . Many thankx

  4. Anonymous
    January 20th, 2016

    hi, friends i am preparing for the CCNA exam so i need the latest dumps for my practice so if any one want to help me just send me the download link or suggest any tips ………………….. my mail id :{email not allowed} i am studying network engineering years 4 near end

  5. Anonymous
    January 20th, 2016

    hi, friends i am preparing for the CCNA exam so i need the latest dumps for my practice so if any one want to help me just send me the download link or suggest any tips ………………….. my mail id :{email not allowed} i am studying network engineering years 4 near end

  6. Dest
    January 29th, 2016

    Great, Thanks..

  7. Nick
    January 30th, 2016

    How we can get 100% mark in CCNA R&S exam?

  8. Nick
    January 30th, 2016

    can we use question mark(?) to see more commands in ccna exam simulator?

  9. Nick
    February 1st, 2016

    is there anyone reply for my question ?

  10. ttomazzoni
    February 1st, 2016

    Hi Nick. Yes it is possible to use question mark in the exam simulator.

  11. gab
    February 3rd, 2016

    Hi admin
    can i get ccna200-120 updated dumps?

  12. Nick
    February 5th, 2016

    thanx ttomazzoni

  13. Naf
    February 13th, 2016

    I am appearing the exam on 23rd Feb. Can anyone please send me the last moment preparation and link to : {email not allowed}

  14. Naf
    February 13th, 2016

    I am appearing the exam on 23rd Feb. Can anyone please send me the last moment preparation and link to nafis2007 at hotmail dot com

  15. Anonymous
    February 16th, 2016

    Dumps latest plZ send me link …
    {email not allowed}

  16. moi
    February 16th, 2016

    i think that the dns server’s addresse is 10.1.1.10 ! who is agree??

  17. Anonymous
    February 20th, 2016

    Hi admin

    can i get ccna200-120 updated dumps?

  18. kk
    February 20th, 2016

    hi admin
    can i get ccna200-120 updated dumps?

  19. Satish
    February 22nd, 2016

    Nicely explained …. thanks a lot

  20. Liby
    February 22nd, 2016

    thanks

  21. Anonymous
    February 24th, 2016

    Hello admin.
    Can i get the latest ccna dumps?. My id is {email not allowed}

  22. Rozen
    February 25th, 2016

    Thanks admin for ur nice post ….

  23. Anonymous
    February 26th, 2016

    passs,watson questions valid.
    lab:EIGRP,OSPF,ACL 1(choose right answer),ACL-2(interfacing)
    EIGRP is different,u need to check statements properly
    Remaining everything same as watson

  24. gaagaale
    March 1st, 2016

    hey guys, can someone send me the latest CCNA dump,
    to the {email not allowed}

  25. gaagaale
    March 1st, 2016

    hey guys, casn someone send me the latest CCNA dump,
    {email not allowed}

  26. iman
    March 3rd, 2016

    please share Watson link here .thnk u

  27. paul
    March 3rd, 2016

    hi admin,
    Can i get latest dumps for my ccna exam?

  28. Anonymous
    March 3rd, 2016

    nic tut thanks, {email not allowed}

  29. CdCl
    March 4th, 2016

    Great information, makes sense..

  30. Anonymous
    March 4th, 2016

    I am going to give a lot of thanks to the people who have created this site their materails always supported me in great extent. The way they explain is remarkable. Today i am holding this CCNA tittle so a lot of credit goes to the team of 9TUT. I love them as they played a very important role in making my journey towards CCNA wonderfull. Avilash Sharma(NerD()

  31. goie
    March 4th, 2016

    I don’t think that in DORA process, offer, request and ack msg will have layer 2 unicast address.
    i captured DHCP packet in wireshark and all DORA packet had layer address from client to router as DHCP was in different subnet

    any comment on this ?

  32. goie
    March 4th, 2016

    I don’t think that in DORA process, offer, request and ack msg will have layer 2 unicast address.
    i captured DHCP packet in wireshark and all DORA packet had layer 2 broadcast address from client to router as DHCP was in different subnet

    any comment on this ?

  33. Mangesh Gund
    March 9th, 2016

    hiii frnds,

    i’m preparing for CCNA exam n I’ve scheduled my exam on 30 March 16. so plz help me for clear my exam n send new dumps plzzz. My Mail Id :- {email not allowed}

  34. Anonymous
    March 10th, 2016

    Tnks

  35. bibi
    March 15th, 2016

    simply explained….thaaanks a lot

  36. Yousuf
    March 17th, 2016

    Thank you so much for such a nice tutorial. It is very much to the point. Each topic are very easy to understand and it is very practical. Thank you so much again.

  37. Lucas
    March 25th, 2016

    Hi everyone, i will be taking my ccna exam on march 28 please send me a copy of latest ccna dumps. please please please.

  38. Sam
    April 13th, 2016

    364 dumps still valid. Thanks 9tut for all the labs modifications. (921/1000)

  39. Anonymous
    April 30th, 2016

    Hey can i get the latest exam too, ill be taking my exam soon?

  40. Eleandro
    May 14th, 2016

    Nice.

  41. cool
    May 24th, 2016

    Guys i want to know…..for best job opportunities which course will b better either ccnp or redhat linux n microsoft servers ????

  42. Ahmad
    June 28th, 2016

    Very helpful. Thanks i copy your article

  43. Dahime
    July 10th, 2016

    Thanks

  44. lazaro
    July 15th, 2016

    kindly if anybody has the latest ccna dumps kindly send it to my gmail user name “lazarogetz. thanks in advance.

  45. lazaro
    July 15th, 2016

    why should we configure DHCP on a router? since we have a DHCP server we can configure it on a switch and a server. ?

  46. Anonymous
    July 21st, 2016

    Thanks 9tut

  47. Peterz
    July 21st, 2016

    Thanks 9tut

  48. Anonymous
    July 30th, 2016

    Hey can i get the latest exam too, ill be taking my exam soon? Please email to {email not allowed} thanks~

  49. Anonymous
    July 30th, 2016

    Thanks 9Tut????????????????????????

  50. shiroli
    August 3rd, 2016

    thanks 9tut….good explanation..

Comment pages
Add a Comment