DHCP
Synchronized Transcript
175 cues indexed • Click dialogue or words to jumpWelcome to Jeremy’s IT Lab. This is a free, complete course for the CCNA. If you like these videos, please subscribe to follow along with the series.
Also, please like and leave a comment, and share the video to help spread this free series of videos. Thanks for your help. In this video we will cover DHCP, Dynamic Host Configuration Protocol.
Just like DNS, DHCP is a protocol that you’re certainly using every day, even if you’re not aware of it. DHCP allows DHCP clients, usually end devices like PCs, phones, etc, to automatically learn which IP address to use from a DHCP server, instead
of us having to manually configure it. However DHCP allows devices to learn much more than just their IP address, as you’ll see in this video.
DHCP is part of exam topics 4.3, explain the role of DHCP and DNS within the network, and 4.6, configure and verify DHCP client and relay.
Actually DHCP is also mentioned in section 5.0, security fundamentals, however we’ll leave security for a separate section of the course.
Here’s what we’ll cover in this video. First I’ll outline the basic purpose of DHCP, and why we use it. Then I’ll introduce the basic functions of DHCP, specifically the four-message exchange that clients use to get an IP address from a DHCP server.
Then I’ll show you how to configure DHCP in Cisco IOS. A Cisco router can be a DHCP server, a DHCP client, or something called a ‘DHCP relay agent’.
I’ll show you how to configure all of those. Make sure to watch until the end of the video for a bonus practice question from Boson Software’s ExSim for CCNA, the best practice exams for the CCNA.
Here’s a brief overview of DHCP. DHCP is used to allow hosts to automatically and dynamically learn various aspects of their network configuration such as IP address, subnet mask, default gateway, DNS server, etc, without manual and static configuration.
It is an essential part of modern networks, I’m certain you’re using it everyday. For example, when you connect a phone to WiFi, do you ask the network admin, whoever’s running the network, which IP address, subnet mask, default gateway, etc, the phone or laptop should use?
Probably not, we all expect that once we connect to WiFi we’ll automatically have access to the network and the Internet. It’s probably the same in your home network.
If you connect your PC to your home router, you probably don’t need to manually configure your PC’s IP address, default gateway, etc. Of course, you can do that if you want, and some of you probably do.
In a small network manual configuration isn’t such a difficult task. However in large networks DHCP’s role is very important.
Note that DHCP is typically used for ‘client’ devices such as workstations, PCs, phones, etc. Devices such as routers, servers, etc, are usually manually configured.
This is because they need to have a fixed IP address to perform their function. If the default gateway of the network kept changing it would obviously not be ideal.
In small networks (such as home networks) the router typically acts as the DHCP server for hosts in the LAN. If you have a router in your home, it’s probably acting as the DHCP server for all of your devices.
However in larger networks, such as a large enterprise network, the DHCP server is usually a Windows or Linux server.
Now I’ll give a brief demonstration of DHCP’s function using my own PC, which is running Windows 10. If your PC is running Windows, I recommend following along.
This is the ‘network and sharing center’, which can be accessed from the control panel. I’m going to select my PC’s Ethernet0 connection, which is connected to my home router via an Ethernet cable.
This is what you’ll see after opening it. Here I select the properties of my PC’s Ethernet connection, Ethernet0. Then the properties are displayed.
I select the IPv4 properties here. This window opens up. Here I can confirm that my PC is using DHCP. Here it says ‘obtain an IP address automatically’.
And down here it says ‘obtain DNS server address automatically’. ‘Automatically’ means that my PC will use DHCP to learn which IP address, subnet mask, default gateway, and DNS server it should use.
Let’s take a look at what was automatically configured. I used the IPCONFIG /ALL command, which you already know. First off, notice that it tells us that DHCP is enabled.
If I had manually configured my PC’s IP address in the previous menu, ‘No’ would display here. And here is the IPv4 address my PC was assigned, 192.168.0.167 with a /24 subnet mask.
Notice that it says ‘preferred’ here. What does that mean? It means that this PC was previously assigned this IP address by the DHCP server.
Then, when it asked the server for an IP address again, it asked to receive the same address again. If this address was no longer available, my PC would have been assigned a different address.
However, the address was available, so my PC got its preferred IP address. Here’s an important part of DHCP, the lease time. IPCONFIG /ALL displays what time the lease was obtained, and what time it will expire.
What exactly does this mean? DHCP servers ‘lease’ IP addresses to clients. These leases are usually not permanent, and the client must give up the IP address at the end of the lease.
A client can also release the address before the lease is up, if it no longer needs it. Now, I said ‘usually’ not permanent, because it is possible to configure the DHCP server to permanently assign IP addresses.
However, it’s almost always best to set a lease time. For example, think about a cafe that provides WiFi network access to its customers.
If the IP address leases were permanent, every time a new customer comes into the cafe and connects to the WiFi, the customer’s devices would be permanently assigned IP addresses, unless the client device releases it.
Or how about an airport that provides WiFi? I think you can see why it’s best to limit the lease time, to preserve the available IP addresses. If the customer stays longer than the lease time, their device will simply automatically request a new IP address, but if they stop using the network the IP addresses
will be free for someone else to use. Okay, here at the bottom we can see some other info my PC learned from the DHCP server.
The default gateway, DHCP server, and DNS server are all 192.168.0.1, which is my home router. This is common in home networks, the home router provides all of these services to devices on the local network.
I want to demonstrate the process that a DHCP client goes through to get an IP address from a DHCP server, but first I need to make my PC release its IP address, so it can ask the server again.
The command in the Windows command prompt to release the DHCP-learned IP address is IPCONFIG /RELEASE. Now no information is displayed for the Ethernet0 interface.
So, let me demonstrate what just happened. My PC sent a DHCP Release message to the DHCP server, my router, telling it that the IP address isn’t needed anymore.
So, 192.168.0.167 is now free to assign to another client. I used Wireshark to capture that DHCP release message.
For the CCNA you should focus on learning the four message process used to lease an IP address from a DHCP server, which I will show you next.
But let’s look at the DHCP release message anyway. Of course, the message is an Ethernet frame so here’s the Ethernet header.
An IPv4 header is inside, from source IP address 192.168.0.167, the PC, to destination IP 192.168.0.1, the router.
Inside is a UDP header, and notice the ports. Source port 68, destination port 67. DHCP servers use UDP port 67 and DHCP clients use UDP port 68.
So, the source port is 68 because it’s the DHCP client, and the destination port is 67 because it’s the DHCP server.
This is different than DNS, for example, in which only the port of the server is decided and the client uses a random ephemeral port.
Finally, inside of the UDP segment we have the DHCP release message. The client IP is indicated here. And notice these ‘options’ down here.
DHCP has various options used for different purposes. For example option 53, at the top, indicates what kind of DHCP message it is.
And before moving on, let me point out my favorite part of DHCP messages, the magic cookie. Do a Google search if you want to learn about that one.
Now that I’ve released the IP address of my PC, let’s take a look at how my PC can get an IP address from the DHCP server. From the Windows command prompt I used the command IPCONFIG /RENEW.
My PC contacts the DHCP server, and now my PC has the same configuration as before. This process involves four messages, let me introduce them now.
The first message is the DHCP Discover message. It is a broadcast message from the client. Basically, it’s asking if there are any DHCP servers in the local network, telling them it needs an IP address.
Let’s use Wireshark to take a look at the DHCP Discover message my PC sent. Here it is. Here’s the Ethernet header.
Notice the destination broadcast MAC address of all Fs. My PC doesn’t know the IP address or MAC address of the DHCP server. In fact it doesn’t even know if there is a DHCP server on the network, so it has no choice but to broadcast the message.
Here’s the IPv4 header. Notice the source IP address of 0.0.0.0. Basically, this means my PC doesn’t have an IP address yet.
The destination is 255.255.255.255, so it’s a broadcast message. Once again, since this is a message from the DHCP client to the server, the source port is UDP 68 and the destination is UDP 67.
And here’s the actual DHCP message. You don’t need to know the contents of any of these messages in detail, just know their basic purpose.
But here are a few of the fields. First off, the ‘Bootp flags’ field. Bootp is actually the predecessor of DHCP, but you don’t need to learn Bootp for the CCNA.
I just want to point out the value of ‘unicast’ here, represented by 0000. This may seem odd, the message is broadcast but this field says unicast.
I’ll explain it when we look at the next message. Then we can see here that the client IP address is 0.0.0.0, since my PC doesn’t have an IP address yet.
The client MAC is also displayed here. And here are the options, notice they are different than the ones used in the DHCP Release message we looked at before.
Let me just point out this option, Requested IP Address. Because my PC previously had the IP address 192.168.0.167, it requested that address again.
If the address is available, the server might grant it that same IP address again. But if it’s not, my PC would get a different IP address.
If this is the first time my PC is using DHCP it won’t request an IP address like this, it will simply leave it up to the server to decide.
The next message is the DHCP Offer message, it is sent from the DHCP server to the client, offering an address for the client to use, as well as other information like default gateway, DNS server, etc.
So let’s check out the DHCP Offer my router sent to my PC. First off, notice the Offer is sent as a unicast frame to the client’s MAC address, since the server learned the client’s MAC address from the Discover message.
It’s also unicast at Layer 3, the destination is the IP address being offered to the client. This time the source and destination port number are reversed, since it’s a message from the server to the client.
The source is UDP 67 and the destination is UDP 68. And here’s the Offer message. Let’s look at this field again, ‘Bootp flags’.
Once again, it says unicast. When my PC sent the DHCP Discover message this field was also set to 0000, unicast. This means that the server will send its messages using unicast, as I just showed you above.
However, that’s not always the case. The DHCP Offer message can be sent to the client using either broadcast or unicast. It depends on the client.
In this case my PC told the router to send the Offer using unicast, so it did. If my PC told the router to send the Offer using broadcast, the destination MAC of this message would be all F’s and the destination IP would be 255.255.255.255.
At this point in the DHCP process, the client’s IP address isn’t actually configured. Some clients won’t accept unicast messages before their IP address is actually configured, so that’s why sometimes broadcast must be used instead of unicast.
And finally here are the options. For example option 51 indicates the lease time, option 6 is ‘domain name server’ that’s the DNS server, and option 3 is ‘router’, which tells the client the default gateway.
By the way, you don’t have to memorize these option numbers, definitely not at the CCNA level, I’m just pointing them out. Okay, the next message is the DHCP Request message.
It is sent from the DHCP client to the server, telling the server that it wants to use the IP address it was offered. This is important, there may be multiple DHCP servers on the local network, and all of them will reply to the client’s Discover message with an Offer.
So, the client has to tell which server it is accepting the offer from and request to use that IP address. Typically, the client will accept the first Offer it receives.
Let’s look at that Request message in Wireshark. The destination MAC is all Fs, so this is once again a broadcast message. If there are multiple DHCP servers on the network, all of them will receive this message.
One of the later fields will indicate which server the PC accepted the offer from. The source IP is still 0.0.0.0, since the offered IP address hasn’t actually been configured yet.
The destination is broadcast, 255.255.255.255. Since it’s a message from the client to the server, the source port is UDP 68 and the destination is UDP 67.
And here’s the request message. Here’s the flags field again, telling the server to send its messages using unicast, even though the client itself uses broadcast.
And here are the options for this Request message. Notice that the server’s IP address is indicated using option 54. If there are multiple DHCP servers on the local network, this is how the client says which server it selected.
Now the final message in the process, the DHCP Ack, acknowledgement. This is sent from the server to the client, confirming that the client may use the requested IP address.
Once this message is received the client finally configures the IP address on its network interface. Here’s that Ack message in Wireshark.
Notice that these messages from the server to the client are once again sent to unicast addresses, not broadcast. Let me point out once again that the server uses UDP port 67, so that’s the source port, and the client uses UDP port 68, so that’s the destination port.
And here’s the Ack message. The Bootp flags field once again indicates unicast, because the client requested unicast messages. Just like the DHCP Offer message, the DHCP Ack message can be either broadcast or unicast, depending on what the client requests.
And these are the options for this Ack message. There are many different DHCP options, if you want to check out a list, the DHCP Wikipedia page lists a bunch of them, and a quick Google search will give you many explanations of their various functions.
But that’s just extra, not necessary for the CCNA exam. Here’s a quick summary of that process. A common way to remember the messages is D-O-R-A, DORA, for Discover, Offer, Request, and Ack.
Make sure you know which messages are sent from client to server, server to client, and also which messages must be sent broadcast and which can be sent either broadcast or unicast.
Also, here’s the Release message I showed first, it’s sent unicast from the client to the server. There are actually many more DHCP message types than these, but if you know these message types you’ll be ready for the CCNA.
Next let me introduce the concept of DHCP Relay. Some network engineers might choose to configure each router to act as the DHCP server for its connected LANs.
However, large enterprises often choose to use a centralized DHCP server, which will assign IP addresses to DHCP clients in all subnets throughout the enterprise network.
If the server is centralized, it won’t receive the DHCP clients’ broadcast DHCP messages. Remember, broadcast messages don’t leave the local subnet, routers don’t forward them.
However to fix this you can configure a router to act as a ‘DHCP relay agent’. If you do that, the router will forward the clients’ broadcast DHCP messages to the remote DHCP server as unicast messages.
Let me use this network to demonstrate. PC1 is a DHCP client, so it will broadcast a DHCP Discover message to ask DHCP servers on the local network to assign it an IP address.
However, in this case R1 isn’t a DHCP server. SRV1 is the central DHCP server for this network, so R1 will need to forward any DHCP messages from PC1 to SRV1.
Let me demonstrate that visually. SRV1 is a DHCP server, and R1 is a DHCP relay agent. PC1 broadcasts a DHCP Discover message to get an IP address.
R1, a DHCP relay agent, relays the message to SRV1. Notice that the source address changes to the address of R1’s G0/1 interface, and the destination is SRV1’s IP address.
So, it is a unicast message. Then SRV1 replies with the DHCP Offer, sending it to the address of R1’s G0/1 interface, 192.168.1.1.
R1 then forwards it to PC1. The source is R1’s IP address, and the message is either sent unicast to PC1 or broadcast.
Then PC1 broadcasts a request message, and R1 relays it to SRV1. Finally SRV1 replies with a DHCP Ack, and R1 forwards that to PC1, which configures the IP address it was assigned, for example 192.168.1.100.
So, that’s a quick overview of how DHCP relay agents work. It’s quite easy to configure a DHCP relay agent, you just need one command, and I’ll show you how to do it.
In the next section I’ll show you how to configure DHCP. First, I’ll show you how to configure a Cisco router as a DHCP server, and then how to configure a Cisco router as a DHCP relay agent.
Finally I’ll show you how to configure a Cisco router as a DHCP client. So, let me show you how to configure a Cisco router to function as a DHCP server.
Let’s use these two devices here, R1 and PC1. Here are the commands. First up, you can use the IP DCHP EXCLUDED-ADDRESS command to specify a range of addresses that WON’T be given to DHCP clients.
These are addresses you want to reserve, perhaps for network devices or servers in the local subnet. The first address in the command is the low end of the range, and then the second is the top of the range.
So, this reserves all addresses from 192.168.1.1 through 192.168.1.10. This command isn’t necessary, but it’s a good idea to reserve some addresses which can be statically assigned to servers, network devices, or whatever.
Then use the command IP DHCP POOL, followed by the pool name, to create a DHCP pool. What is a DHCP pool? It’s basically a subnet of addresses that can be assigned to DHCP clients, as well as other info such as DNS server and default gateway.
You should create a separate DHCP pool for each network the router is acting as a DHCP server for. In this case R1 is only acting as the DHCP server for 192.168.1.0/24, so I only need to create one pool.
Here’s where you actually configure the range of addresses to be assigned to clients. The command is NETWORK, followed by the network address and then either the network mask or prefix length.
So, you can write /24 or 255.255.255.0, either works. So, I told R1 to assign addresses from 192.168.1.0/24 to clients, although it won’t assign the addresses I reserved above.
Then you can configure the DNS server that clients in the network should use. So, in this case R1 would tell PC1 to use Google’s DNS server at 8.8.8.8 for its DNS queries.
You can also configure the domain name of the network. In this case R1 will tell PC1 that it is part of the domain ‘jeremysitlab.com’.
Then there’s the DEFAULT-ROUTER command. What’s this? It’s the default gateway. So, R1 will tell clients to use its address, 192.168.1.1, as their default gateway.
You can also configure the lease time. I specified 0 5 30, which is 0 days, 5 hours, and 30 minutes. You can also enter LEASE INFINITE, although as I have said before that’s not recommended.
So, when PC1 comes online and sends its DHCP Discover message, perhaps it will be assigned .11, the first available address since .1 through .10 are reserved.
Let’s confirm. Here’s a really useful command on a Cisco router acting as a DHCP server, SHOW IP DHCP BINDING. It shows all of the DHCP clients that are currently assigned IP addresses.
Here’s PC1, with an IP address of 192.168.1.11. Its MAC address is also displayed, and the lease expiration date and time, and the binding type.
DHCP bindings can be manually configured, but we didn’t do that in this case. So let’s check on PC1. Here’s the domain name, jeremysitlab.com.
Here’s the IP address and subnet mask it was assigned. Here we can see when the lease was obtained and when it will expire.
Notice that the lease period is 5 hours and 30 minutes, as I configured. The lease expiration times on PC1 and R1 are different, but that’s just because I didn’t configure the time zone.
And finally we can see the default gateway, DHCP server, and DNS server. So, we successfully configured R1 as a DHCP server.
Now, how about DHCP relay agent configuration? Here’s that same network as before, SRV1 is a DHCP server and R1 will be a DHCP relay agent after we configure it.
To configure it as a relay agent, first enter interface config mode for the interface connected to the client devices. PC1 is connected to R1’s g0/1, so we will configure that interface.
Then all you need is one command, IP HELPER-ADDRESS, followed by the IP address of the DHCP server. Of course, make sure R1 actually has a route to the DHCP server.
If it doesn’t have a route, configure a static route or use a dynamic routing protocol like OSPF. After configuring that I checked the interface with SHOW IP INTERFACE G0/1.
Notice that the ‘helper address’ is listed here, 192.168.10.10, which is SRV1. And that’s it, that’s all you need to do to configure a router as a DHCP relay agent.
IP HELPER-ADDRESS, then the DHCP server address. Okay, one last thing you need to be able to configure for the CCNA.
A Cisco router can be a DHCP client, meaning it can use DHCP to configure the IP address of its interfaces. This is rare, as I mentioned earlier usually network devices will be configured with a fixed IP address.
However here’s how you can do it. Let’s make R2 a DHCP client on its G0/1 interface. From interface config mode for G0/1, use the command IP ADDRESS DHCP.
That’s it, now R2 will broadcast a DHCP Discover message and get an IP address from SRV1. Indeed it did, I checked with SHOW IP INTERFACE G0/1.
It states clearly, ‘address determined by DHCP’. Note that its G0/0 interface is still manually configured, its not a DHCP client.
Here’s a summary of the commands we covered in this video. A couple commands for the Windows command prompt, then Cisco IOS commands to configure a DHCP server, a DHCP relay agent, and a DHCP client.
If you don’t remember any of these commands, go back in the video to review. You can also get practice with some of these commands in today’s practice lab, which will be in the next video.
Before moving on to the quiz, let’s review what we covered in this video. First, I introduced the purpose of DHCP. It allows devices to automatically learn various configuration parameters, such as their IP address, subnet mask, default gateway, etc.
I introduced the basic functions of DHCP. Make sure you remember DORA, Discover, Offer, Request, and Ack. You should also know the basic purpose and functions of a DHCP relay agent.
Finally I showed you how to configure DHCP in Cisco IOS. First, how to configure a Cisco router as a DHCP server, then a DHCP relay agent, and finally a DHCP client.
Make sure to watch until the end of the quiz for a bonus question from Boson Software’s ExSim for CCNA, the best practice exams for the CCNA.
Okay, let’s go to quiz question 1. What is the correct order of messages when a DHCP client gets an IP address from a server?
Here are the options. Pause the video to think about the answer. The answer is B, Discover, Offer, Request, Ack.
If you’re having trouble remembering the order, remember D-O-R-A, DORA. Okay, let’s go to question 2.
Which of the following Windows command prompt commands will cause a PC to broadcast a DHCP Discover message? Here are the options. Pause the video to think about the answer.
The answer is D, IPCONFIG /RENEW. This will cause the PC to send a DHCP Discover message to get an IP address from any DHCP servers it can reach.
C, IPCONFIG /RELEASE will make the PC send a DHCP Release message, to release its current IP address. A and B are not real commands.
Okay, let’s go to question 3. Examine the following DHCP Offer message that SRV1 sent to R2.
What destination IP address did SRV1 send it to? Here are the options. Pause the video to select the correct answer.
The answer is D, 255.255.255.255. How can we know this from this output, even though I didn’t show the IP header? It’s here, the broadcast flag in the Bootp flags field is set.
In the previous examples, this field was unicast, so the server would send unicast messages to the client. However in this case it is broadcast, so the server will broadcast messages to the client.
Therefore, the destination IP address is 255.255.255.255. Okay, let’s go to question 4.
Which of the following DHCP messages can be sent using unicast? (select all that apply) Here are the options. Note that this includes messages that can be sent either unicast or broadcast, as well as messages that are always sent unicast.
Okay, pause the video to think about the answers. The answers are A, DHCP Ack, C, DHCP Release, and E, DHCP Offer.
A and E are messages sent from the DHCP server to the client, and they can be sent using unicast if the client indicates it in the ‘bootp flags’ field.
C is sent by a DHCP client to its DHCP server, to tell the server it no longer needs its IP address. It is sent unicast.
B and D are always broadcast messages. Okay, let’s go to question 5. In which of the following situations would you configure a router as a DHCP relay agent?
Here are the options. Read them carefully, and select the best answer. Pause the video now.
Okay the answer is A, when the router is not a DHCP server, there are DHCP clients in the router’s connected LAN, and there is no other DHCP server in the connected LAN.
B, C, and D do not require the router to be a DHCP relay agent. Okay, that’s all for the quiz. Now let’s take a look at a bonus question in Boson Software’s ExSim for CCNA.
Okay here's today's Boson ExSim practice question. You are the administrator for the network shown above. DHCP services for the network are provided by the DHCP server on NetworkB.
DHCP services are not running on the routers. Which of the following commands should you issue to enable clients on NetworkA to receive IP addresses from the DHCP server?
Select the best answer. Okay, so these are the options. IP HELPER-ADDRESS commands, so which router should you use the command on, and what should be the IP address you enter in the command?
Okay, pause the video now to think about your answer. Okay let's check.
So, these clients here in NetworkA are DHCP clients, or they want to be DHCP clients. So they need to access the DHCP server here.
So they will broadcast DHCP Discover messages which RouterA will receive. Now, RouterA is not a DHCP server, but we have to configure it as a DHCP relay agent.
So, among the answers, C, D, and F have you issuing the command on RouterA. So the correct answer is one of these three.
Okay, so what should be the IP address? The command is IP HELPER-ADDRESS, and then the IP address of the DHCP server. So that is 10.10.3.5, therefore the answer should be F.
So let's check. And that is correct. So, you can read Boson's explanation down here, including some explanation about the IP HELPER-ADDRESS command, it's not only for DHCP.
Okay and that's Boson's explanation, and they have a reference here to some Cisco documentation about the IP HELPER-ADDRESS command.
Okay so that's Boson ExSim for the CCNA. These are without a doubt the best practice exams for the CCNA, and they're the ones I used to get my certification.
If you want to get Boson ExSim, follow the link in the video description. There are supplementary materials for this video.
There is a flashcard deck to use with the software ‘Anki’. There will also be a packet tracer practice lab so you can get some hands-on practice. That will be in the next video.
Sign up for my mailing list via the link in the description, and I’ll send you all of the flashcards and packet tracer lab files for the course.
Before finishing today’s video I want to thank my JCNP-level channel members. To join, please click the ‘Join’ button under the video.
Thank you to Brandon, Samil, Aaron, Tech Alameda, Marcel, Magrathea, Kone, Donald, C Mohd, Gustavo, Anthony, Biraj, Junhong, Njabulo, Benjamin, Tshepiso, Justin, Prakaash, Nasir, Erlison, Apogee, Marko, Daming, Jhilmar, Ed, Value, John, Funnydart, Velvijaykum,
Mark, Yousif, Boson Software, Devin, Lito, Yonatan, and Vance. Sorry if I pronounced your name incorrectly, but thank you so much for your support.
This is the list of JCNP-level members at the time of recording by the way, January 24th 2021. If you signed up recently and your name isn’t on here don’t worry, you’ll be in future videos.
Thank you for watching. Please subscribe to the channel, like the video, leave a comment, and share the video with anyone else studying for the CCNA. If you want to leave a tip, check the links in the description.
I'm also a Brave verified publisher and accept BAT, or Basic Attention Token, tips via the Brave browser. That's all for now.