Вы находитесь на странице: 1из 12

Home > DHCP Tutorial

DHCP Tutorial
June 18th, 2015Go 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.

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).

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).

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.
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).

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.
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 Create a DHCP Pool named CLIENTS


pool CLIENTS

Router(dhcp- Specifies the subnet and mask of the DHCP address pool
config)#network 10.1.1.0
/24

Router(dhcp- Set the default gateway of the DHCP Clients


config)#default-router
10.1.1.1

Router(dhcp-config)#dns- Configure a Domain Name Server (DNS)


server 10.1.1.1

Router(dhcp- Configure a domain-name


config)#domain-name
9tut.com

Router(dhcp-config)#lease Duration of the lease (the time during which a client computer
0 12 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 The IP range that a DHCP Server should not assign to DHCP
excluded-address 10.1.1.1 Clients. Notice this command is configured under global
10.1.1.10 configuration mode

Comments (50) Comments


Comment pages
« Previous 1 2 3 4 5 Next »

1. eliemacho
September 22nd, 2015

thx. very helpfull


2. dara
September 23rd, 2015

This website is very good


3. sony
September 24th, 2015

perfect, thanks 9tut


4. destty
September 24th, 2015

COOL!!
5. Diego Giuseppe
September 25th, 2015

Tanks 9Tut!!
6. YL
September 28th, 2015

Thanks for all Nine Tut !


I just have a question : is it normal that default router and dns-server both have the same IP adress
10.1.1.1 ?
Shouldn’t it be 10.1.1.1 for the router and 10.1.1.10 for the dns ? as we can see after these two
adresses in the excluded adress range…
Thanks for your feedback !
7. Vlad
October 2nd, 2015

awesome tutorials.thank you


8. Anonymous
October 4th, 2015

if lease has finish then router will automatically assign ip address or not?
what happen then
9. Pramod
October 4th, 2015

Nice One….keep it up.


10. issai
October 5th, 2015

why i can’t configure the domain-name 9tut.com when i press enter said invalid input detected at
””’market
11. Pramod
October 6th, 2015

@issai
Aru you using any special charecter or inverted comma?
You have to simply type the domain name
12. BK
October 17th, 2015

It is the most precise way of putting a topic.


good job 9tut
13. Amit
October 18th, 2015

the command should be “ip domain-name 9tut.com


14. Manfred Wolf
October 24th, 2015

I checked the following via PacketTracer v6.2 and could not prove it:

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.

In Simulation mode I also saw an MAC Broadcast when the DHCP Server was sending a DHCPOFFER!

Rene Molenaar states the same occurrence in his book CCNA pages 33 – 39 by showing the processes
via WireShark.
15. Yaseen Zafar
November 3rd, 2015

i am going to give CCNA 200-120. Is there any discount voucher avaiable?


16. Anonymous
November 9th, 2015

SDF
17. Anonymous
November 10th, 2015

Absolutely fantastic explanation. Lucid language used. Many thanks for explaining in detail
18. Dhananjay
November 10th, 2015

Absolutely fantastic explanation. Lucid language used. Many thanks for explaining in detail
19. prince licudops
November 10th, 2015

orayt! <3
20. Brother Gary Neter
November 18th, 2015

THE LAST TIME I REALLY STUDIED MY CCNA BOOK WAS BACK IN AUGUST AND I GOT A CERTIFICATE
@ THAT…..nOW HERE IT IS NOVEMBER AND i NEED TO KNOW WHERE SHOULD I BEGIN FROM OR
ANY SUGGESTIONS SO I CAN TAKE MY CCNA TEST AND PROPERLY PREPARE MYSELF ?? EMAIL ME
@ GARYLOVELITTLEK@YAHOO.COM THANKS TO YOU VERY MUCH
21. thirupathi
November 20th, 2015

tel me basic interview questions on ip concepts


22. Syed
November 20th, 2015

Nice tutorial, keep up the good work


23. Daniel Koroma
November 21st, 2015

Am unable to configure the domain name and lease both showed


Invalid input detected at ‘^’ marker
Router(dhcp-config)#domain-name 9tut.com
Router(dhcp-config)#lease 0 12

please help
24. Gurulingappa Patil
November 22nd, 2015

Thanks 9tut
25. perlux
November 27th, 2015

Please I don’t see the questions, I just see the explanations. somebody helps me please
26. 9tut
November 28th, 2015

@perlux: We had to move all the questions and answers out of 9tut because of copyrighted issues. We
can only keep the explanation. You can download the questions and answers
at: http://www.9tut.com/ccna-questions-and-answers
27. Tabe Rudith A Ashu
November 28th, 2015

Please why do we have only answers but no questions? the questions are so essential for a better
comprehension of the solution. Thanks
28. Dhananjay
November 29th, 2015

Best ever explaination. Thanks


29. Jackson
December 10th, 2015

Very informative and comprehensive


Thank you so much
30. avi
December 10th, 2015

thank you very much for this great explanation… it helped me a lot to better understand the DHCP
process THANKS!!
31. Shirin
December 11th, 2015

Thank you so much for the helpful information. Your website is really a great source for understanding
the network concepts :)
32. Nizhu
December 13th, 2015

Hi unable to config network Router(dhcp-config)#network 10.1.1.0/24


^
% Invalid input detected at ‘^’ marker.
33. Ranjith Shetty
December 14th, 2015

can u help me to get notes for account manager exam. thank u


34. Yahya Leo
December 15th, 2015

Really nice explanation of DHCP so far on internet.


35. Carol
December 18th, 2015

Any doubt we can discuss about DHCP


36. Ammar Alfatlawe
December 18th, 2015

Thank you for the explanations.


Do you think the excluded-address, should be the first command ?
37. greatful
December 20th, 2015

thank you !!
38. Than Htike
December 22nd, 2015

great! Thank you!


39. Ashok
December 24th, 2015
New 100% valid Dumps with 364 Q released and available her.
Remove Asteriks
ccna-dumps200-120.blogs*p*o*t*.*c*o*m
40. jackson
December 28th, 2015

Hello Good day


Would it be possible to have more later CCNA exam question and answer, later than July 2015
Thank you.
41. fraz
December 31st, 2015

mean latest ccna dump ?


42. ahmed
January 1st, 2016

Hi, I am going to take my CCNA R and S exam soon. I need latest dumps for CCNA R and S. Can
anyone help me or send me there dumps or any link where i can find latest and valid. Send me here in
my email.
{email not allowed}
I would really appiciate it. Thanks
43. tousifqammar
January 1st, 2016

need ccna latest dumps <>


44. mohamedkhaial
January 4th, 2016

awesome explanation
45. alex
January 4th, 2016

Thank you, sir.


46. dannie
January 8th, 2016

Is really nys explanation.


Thank you very much.
47. luis diego
January 12th, 2016

buena explicacion
48. ahmed
January 14th, 2016

thank…..its really helpful !!!!


49. soiree
January 15th, 2016
Hi to All,
can someone knows about the CCNA Voice certification? I heard that cisco has taken it out, thanks for
your details on the voice certification.
50. yirga
January 18th, 2016

thank You so much


Comment pages
« Previous 1 2 3 4 5 Next »

Add a Comment
Name

Submit Comment

Subscribe to comments feed


Troubleshooting Lab Challenge 1 (OSPF)CCNA – Basic Questions
Premium Membership
Become a member to interact with all questions and read all tutorials, labs!

Find out more or Sign In

CCNA 200-125
 CCNA Lab Sim
 Basic Questions
 Basic Questions 2
 OSI TCP/IP Model Questions
 Cloud & Virtual Services
 WAN Questions
 PPP Questions
 QoS Questions
 PPPoE Questions
 MPLS Questions
 DMVPN Questions
 CDP & LLDP Questions
 IP Address Questions
 Switch Questions
 Switch Questions 2
 VLAN Questions
 VLAN Questions 2
 Trunking Questions
 Trunking Questions 2
 STP Questions
 STP Questions 2
 STP Questions 3
 RSTP Questions
 VTP Questions
 Port Security Questions
 Port Security Questions 2
 SPAN Questions
 EtherChannel Questions
 InterVLAN Routing
 Router Questions
 Switch Stacking & Chassis Aggregation
 Access list Questions
 IP Routing
 IP Routing 2
 IP Routing 3
 Subnetting Questions
 RIP Questions
 OSPF Questions
 OSPF Questions 2
 EIGRP Questions
 BGP Questions
 IP SLA Questions
 NAT/PAT Questions
 HSRP Questions
 IPv6 Questions
 IPv6 Questions 2
 IPv6 Questions 3
 IPv6 Questions 4
 Security Questions
 Security Questions 2
 Troubleshooting Questions
 DHCP Questions
 DHCP Questions 2
 Syslog Questions
 SNMP Questions
 NTP Questions
 SDN Solution
 Wireless Questions
 Miscellaneous Questions
 Drag and Drop
 Drag and Drop 2
 Drag and Drop 3
 Drag and Drop 4
 CCNA FAQs & Tips
 Share your CCNA v3.0 Experience

CCNA Self-Study
 Practice CCNA GNS3 Labs
 CCNA Knowledge
 CCNA Lab Challenges

Network Resources
 Free Router Simulators
 ICND1/ICND2 Website
 CCNP - ROUTE Website
 CCNP - SWITCH Website
 CCNP - TSHOOT Website
 CCNA Security Website
 CCNA Voice Website
 CCNA Wireless Website
 CCIE Website

Top

Copyright © 2016 CCNA Training


Site Privacy Policy. Valid XHTML 1.1 and CSS 3.BH