Config Lab: DHCP Relay
Most DHCP servers sit in a centralized location. To make that work, routers need to participate in the DHCP process to a small degree using a feature called the DHCP Relay Agent. For this lab, you think about a classic case of using DHCP Relay Agent and build the configuration required to enable it in the correct places.
The Lab Exercise
Lab Requirements
This lab focuses on DHCP, specifically the DHCP Relay Agent feature of Cisco routers. To that end, the lab begins with all routers working for all features except DHCP Relay Agent. Specifically, all routers have IPv4 addresses configured on the interfaces shown in Figure 1, all running OSPF, and all learning all routes. If implemented, all routers would be able to ping all IP addresses on the other routers.
The lab also assumes that a DHCP Server is preconfigured. If you want to build this in your lab, you can, and you can even use a Cisco router as the DHCP server. The initial configurations below include the DHCP Server configuration on a router that would support this lab exercise. That configuration:
-
- Removes the first 100 addresses in each subnet from the DHCP pool so that the range of leased addresses begins with the fourth octet of .101.
- Sets the correct default gateway in each subnet.
The lab asks you to make the DHCP Clients work by deciding where to configure the DHCP Relay feature and then configuring that feature. The three PCs in the figure act as DHCP clients. The specific steps for this lab are as follows:
-
- Examine the initial configuration and topology while thinking about the DHCP Relay feature. Ask yourself:
- Should any DHCP Clients work without any DHCP Relay Agent configuration? If so, which ones?
- Do any DHCP Clients need the DHCP Relay Agent feature to work? If so, which ones?
- Plan your DHCP Relay Agent configuration.
- Once planned, create the DHCP Relay Agent configuration.
- If implementing in real gear, Cisco Packet Tracer, CML, or any other environment, check to ensure all three PCs lease an IP address.
- Examine the initial configuration and topology while thinking about the DHCP Relay feature. Ask yourself:
Figure 1: Network for this Lab
Initial Configuration
Examples 1, 2, and 3 show the initial IP addresses and OSPF configuration on the three routers. Note that none of the routers have any DHCP-related configuration.
hostname R1
!
interface GigabitEthernet0/0
ip address 172.16.1.1 255.255.255.0
!
interface GigabitEthernet0/0/0
ip address 172.16.12.1 255.255.255.0
!
interface GigabitEthernet0/1/0
ip address 172.16.13.1 255.255.255.0
!
router ospf 1
network 0.0.0.0 255.255.255.255 area 0
Example 1: R1 Initial Configuration
hostname R2
!
interface GigabitEthernet0/0
ip address 172.16.2.2 255.255.255.0
!
interface GigabitEthernet0/0/0
ip address 172.16.12.2 255.255.255.0
!
router ospf 1
network 0.0.0.0 255.255.255.255 area 0
Example 2: R2 Initial Configuration
hostname R3
!
interface GigabitEthernet0/0
ip address 172.16.3.3 255.255.255.0
!
interface GigabitEthernet0/0/0
ip address 172.16.13.3 255.255.255.0
!
router ospf 1
network 0.0.0.0 255.255.255.255 area 0
Example 3: R3 Initial Configuration
Example 4 shows how you could configure a router to act as a DHCP server. However, you do NOT need to understand the configuration in Example 4 before doing this lab. In the example, the first few configuration lines give the router IP connectivity and enable OSPF to communicate. Most of the configuration creates the DHCP server.
hostname DHCP-Server
!
interface GigabitEthernet0/0
ip address 172.16.1.9 255.255.255.0
!
router ospf 1
network 0.0.0.0 255.255.255.255 area 0
!
ip dhcp excluded-address 172.16.1.1 172.16.1.100
ip dhcp excluded-address 172.16.2.1 172.16.2.100
ip dhcp excluded-address 172.16.3.1 172.16.3.100
!
ip dhcp pool subnet1
network 172.16.1.0 255.255.255.0
dns-server 172.16.1.9
default-router 172.16.1.1
domain-name example.com
!
ip dhcp pool subnet2
network 172.16.2.0 255.255.255.0
dns-server 172.16.1.9
default-router 172.16.2.2
domain-name example.com
!
ip dhcp pool subnet3
network 172.16.3.0 255.255.255.0
dns-server 172.16.1.9
default-router 172.16.3.3
domain-name example.com
Example 4: Cisco Router as DHCP Server
Answer Options - Click Tabs to Reveal
You can learn a lot and strengthen real learning of the topics by creating the configuration – even without a router or switch CLI. In fact, these labs were originally built to be used solely as a paper exercise!
To answer, just think about the lab. Refer to your primary learning material for CCNA, your notes, and create the configuration on paper or in a text editor. Then check your answer versus the answer post, which is linked at the bottom of the lab, just above the comments section.
You can also implement the lab using the Cisco Packet Tracer network simulator. With this option, you use Cisco’s free Packet Tracer simulator. You open a file that begins with the initial configuration already loaded. Then you implement your configuration and test to determine if it met the requirements of the lab.
(Use this link for more information about Cisco Packet Tracer.)
Use this workflow to do the labs in Cisco Packet Tracer:
- Download the .pkt file linked below.
- Open the .pkt file, creating a working lab with the same topology and interfaces as the lab exercise.
- Add your planned configuration to the lab.
- Test the configuration using some of the suggestions below.
You can also implement the lab using Cisco Modeling Labs – Personal (CML-P). CML-P (or simply CML) replaced Cisco Virtual Internet Routing Lab (VIRL) software in 2020, in effect serving as VIRL Version 2.
If you prefer to use CML, use a similar workflow as you would use if using Cisco Packet Tracer, as follows:
- Download the CML file (filetype .yaml) linked below.
- Import the lab’s CML file into CML and then start the lab.
- Compare the lab topology and interface IDs to this lab, as they may differ (more detail below).
- Add your planned configuration to the lab.
- Test the configuration using some of the suggestions below.
Download this lab’s CML file!
Network Device Info:
This table lists the interfaces listed in the lab exercise documentation versus those used in the sample CML file.
Device | Lab Port | Â CML Port |
SW1 | F0/1 | G0/0 |
R1 | G0/0/0 | G0/2 |
R1 | G0/1/0 | G0/3 |
R2 | G0/0/0 | G0/1 |
R3 | G0/0/0 | G0/1 |
Lab Answers Below: Spoiler Alert
Lab Answers: Configuration (Click Tab to Reveal)
Lab Configuration
Figure 1: Network for this Lab
interface GigabitEthernet0/0
ip helper-address 172.16.1.9
Example 1: R2 Config
interface GigabitEthernet0/0
ip helper-address 172.16.1.9
Example 2: R3 Config
Commentary, Issues, and Verification Tips (Click Tabs to Reveal)
Lab Commentary
Networks need the DHCP Relay Agent feature to support clients that reside in a different subnet than the DHCP server. In this lab, PC1 resides in the same subnet as the DHCP server, so that subnet does not need a DHCP Relay Agent. However, PC2 and PC3 reside in other subnets, so at least one router in each subnet must provide the DHCP Relay Agent function.
A router needs the ip helper-address command on the interface connected to the subnet to implement the DHCP Relay Agent. This command needs to refer to the unicast IP address of the DHCP server, in this case, 172.16.1.9. Those combinations of facts mean that router R1 needs no additional configuration, but both R2 and R3 need the ip helper-address 172.16.1.9 command under their LAN interfaces.
The Relay Agent feature tells a router to listen for IP broadcasts entering the interface (packets with destination addresses like 255.255.255.255) and to change the destination address of the packet – and then forward the packet. Figure 2 shows the idea following the numbered steps in the figure. PC2 sends a DHCP message, for instance, and DHCP Discover message, as a local subnet broadcast (destined to address 255.255.255.255.)Â The DHCP Relay Agent feature causes router R2 to notice the packet and change the packet’s destination to the configured 172.16.1.9 address. At step 3, R2 routes the packet just like any other unicast packet.
Figure 2: Relay Agent Logic from R2’s Subnet
Known Issues in this Lab
This section of each Config Lab Answers post hopes to help with those issues by listing any known issues with Packet Tracer related to this lab. In this case, the issues are:
# | Summary | Detail |
1 | None | No known issues related to this lab. |
Why Would Cisco Packet Tracer Have Issues?
(Note: The below text is the same in every Config Lab.)
Cisco Packet Tracer (CPT) simulates Cisco routers and switches. However, CPT does not run the same software that runs in real Cisco routers and switches. Instead, developers wrote CPT to predict the output a real router or switch would display given the same topology and configuration – but without performing all the same tasks, an actual device has to do. On a positive note, CPT requires far less CPU and RAM than a lab full of devices so that you can run CPT on your computer as an app. In addition, simulators like CPT help you learn about the Cisco router/switch user interface – the Command Line Interface (CLI) – without having to own real devices.
CPT can have issues compared to real devices because CPT does not run the same software as Cisco devices. CPT does not support all commands or parameters of a command. CPT may supply output from a command that differs in some ways from what an actual device would give. Those differences can be a problem for anyone learning networking technology because you may not have experience with that technology on real gear – so you may not notice the differences. So this section lists differences and issues that we have seen when using CPT to do this lab.
Beyond comparing your answers to this lab’s Answers post, you can test in Cisco Packet Tracer (CPT) or Cisco Modeling Labs (CML). In fact, you can and should explore the lab once configured. For this lab, once you have completed the configuration, try these verification steps.Â
- Confirm that PC2 and PC3 successfully lease an address using DHCP.
- From the PC2 and PC3 command prompt, use the ipconfig /all command to display the current IPv4 settings.
- If the PCs do not have an address from their respective 172.16.2.0/24 and 172.16.3.0/24 subnets, then use the ipconfig /release and ipconfig /renew commands to force a new attempt for a DHCP lease.
- Confirm PC2 and PC3 can send packets:
- Discover PC1’s IP address.
- From both PC2 and PC3, use the ping command to ping PC1’s IP address.
Hi, in the packet tracer file, router 2 and 3 already have a DHCP relay agent configured.
Maroof,
Whoops. Kinda spoils the lab!
I updated the .pkt file and replaced it so that it should be fixed for the future. Thanks for letting me know!
Wendell
Hi Wendell,
A quick question about Packet Tracer. The configuration of R1 in the provided file includes interfaces Gigabitethernet0/0/0 and Gigabitethernet0/1/0. Those interfaces are not included in manually added 2911 routers. How can I add those interfaces in Packet Tracer?
Hey Mike,
No problem. So, when you add the new router, and click the icon, a window appears. The window has tabs. In the hardware window, there’s an image of the back of the router. Click to magnify it. You’ll see the expansion slots. On the left are cards you can click-drag-drop onto the slots, simulating the physical insertion of a card. For comparison, look at the cards in the same tab for the ones in my pre-supplied labs, and you’ll get the idea.
Thank you, Wendell,
I had not made the connection of dragging the cards to the slots. That makes sense.
Hello,
Thank you for putting this online without need for the registration or fee.
Love your labs and explanations for them are great. You are making a difference in the world.
Thanks, Alexandr. Glad the labs can be a big help!
If you’re looking for CCNA+free, check out my YouTube channel as well… http://www.youtube.com/@NetworkUpskill
Hi Wendell, thanks again for all the great content. I have one quick questions (sorry if its an obvious one) – when I configure the DHCP servers IP for relay on R1/R2 I don’t need to add any subnet mask. Is this because its configured on an interface with a connected route to that server?
Hey Josh,
You’re welcome!
Great question, and not an obvious thought. Yes, the process requires some thought of the subnet mask, which lets some process determine the addresses in a subnet. So… The Relay agent forwards the DHCP Discover with the Relay Agent’s IP address (from that subnet), but without a mask. The DHCP server’s config has the mask. EG, For R2’s subnet, the DHCP server would list 172.16.2.0 255.255.255.0 as parameters. By seeing a DHCP request with R2’s 172.16.2.2 address in it, the DHCP server can figure out which subnet (pool) should be used to fulfill the request.
Hope this helps…
Wendell