[Packet Tracer] Configuring a DHCPv4 Server and a Relay Agent
2022-07-14
Cisco Network Academy provides plenty of learning resources in networking. I will cover how to configure basic DHCPv4 on a router and a DHCPv4 Server, and a DHCP relay agent using Packet Tracer where you can simulate network topologies and configurations.
Build Network and Configure Basic Device Settings
Topology
Addressing Table
Create a new packet tracer file and set up routers and switches, devices.
- Router: 1941
- Switch: 2960
- End device: PC
The complete set-up without cabling should look like
Since serial ports will be used between routers, the routers should have HWIC-2T which is a Cisco 2-Port Serial High-Speed WAN Interface Card, providing 2 serial ports.
Add connection
Make sure that cabling for R1 network is Copper straight-though, and cabling between the routers is Serial port (FYI, the interface Se0/0/0 at R1 and Se0/0/1 at R2 are DCE side)
Plus, double-check the topology and the addressing table so that the device and connection setting don’t go messy and you’re on the right track.
Configure basic settings for routers
When assigning IP addresses to each of the interfaces, make sure you follow the IP addressing form
Open R1’s CLI and configure the interface g0/0, g0/1 and se0/0/0 with IP addresses according to the addressing table
Addressing Table
g0/0
Router>en
Router#conf t
Router(config)#hostname R1
R1(config)#int g0/0
R1(config-if)#ip address 192.168.0.1 255.255.255.0
R1(config-if)#no shut
R1(config-if)#exit
g0/1
R1(config)#int g0/1
R1(config-if)#ip address 192.168.1.1 255.255.255.0
R1(config-if)#no shut
R1(config-if)#exit
se0/0/0
As the serial interface 0/0/0 at R1 is DCE (Data circuit-terminating equipment), clock rate must be configured. I will set it as 128000
R1(config)#int s0/0/0
R1(config-if)#ip address 192.168.2.253 255.255.255.252
R1(config-if)#clock rate 128000
R1(config-if)#no shut
R1(config-if)#exit
Open R2’s CLI and configure the interface se0/0/0 and se0/0/1 with IP addresses according to the addressing table
Addressing Table
se0/0/0
Router>en
Router#conf t
Router(config)#hostname R2
R2(config)#int s0/0/0
R2(config-if)#ip address 192.168.2.254 255.255.255.252
R2(config-if)#no shut
R2(config-if)#exit
se0/0/1
Again, as the serial interface 0/0/1 at R2 is DCE (Data circuit-terminating equipment), clock rate must be configured. I will set it as 128000
R2(config)#int s0/0/1
R2(config-if)#ip address 209.165.200.226 255.255.255.224
R2(config-if)#clock rate 128000
R2(config-if)#no shut
R2(config-if)#exit
Open ISP’s CLI and configure the interface se0/0/1 with IP addresses according to the addressing table
Addressing Table
se0/0/1
Router>en
Router#conf t
Router(config)#hostname ISP
ISP(config)#int s0/0/1
ISP(config-if)#ip address 209.165.200.225 255.255.255.224
ISP(config-if)#no shut
ISP(config-if)#exit
As you can see below, all the IP addressing is completed and the line protocols on all of the interfaces within the topology changed state to up showing green-colored up arrows (or triangles).
Configure dynamic, default, and static routing on the routers.
Before configuring a DHCPv4 Server and a DHCP Relay Agent, routing configuration over the routers should be done first in order for each of the routers to know adjacent networks based on the topology.
Configure RIPv2 for R1.
To automatically reroute the traffic around R1, configure RIPv2 on R1.
R1
R1>en
R1#conf t
R1(config)#router rip
R1(config-router)#version 2
R1(config-router)#network 192.168.0.0
R1(config-router)#network 192.168.1.0
R1(config-router)#network 192.168.2.0
R1(config-router)#no auto-summary
R1(config-router)#exit
R1(config)#exit
R1#copy run start
Destination filename [startup-config]?
Building configuration...
[OK]
router rip
enables RIP protocol on the routerversion 2
specifies the version of RIPnetwork 192.168.0.0
specifies 192.168.0.0 network at the interface g0/0network 192.168.1.0
specifies 192.168.1.0 network at the interface g0/1network 192.168.2.0
specifies 192.168.2.0 network at the interface se0/0/0no auto-summary
disables the default auto summarization of RIPv2 so as to update appropriate subnet masks in the routing table.copy run start
in privileged exe mode saves current configuration
To check the ip route commands you’ve just done, type show ip route
Configure RIPv2 for R2
Configure RIPv2 specifying RIP protocol, RIP version, network and no auto-summary.
R2
R2(config)#router rip
R2(config-router)#version 2
R2(config-router)#network 192.168.2.0
R2(config-router)#no auto-summary
Configure a default route to the ISP on R2
Being still in the RIPv2 config mode, R2 with the command default-information originate
gets ready to generate a static default route into RIPv2.
The command ip route 0.0.0.0 0.0.0.0 209.165.200.225
in the configuration mode (not in the RIPv2 mode) then enables R2 to configure a static route that matches all the packets (any IP addresses & any subnet mask) and sends all the packets out to the next hop of the ISP router.
R2(config-router)#default-information originate
R2(config-router)#exit
R2(config)#ip route 0.0.0.0 0.0.0.0 209.165.200.225
R2(config)#exit
R2#copy run start
Destination filename [startup-config]?
Building configuration...
[OK]
R2 configures a static route to the ISP first and then advertises it to the other routers with RIPv2.
Configure a static route on ISP to reach out to the networks on the R1 and R2 routers
ISP also needs to know the networks over the other routers so configure routes statically.
ISP>
ISP>en
ISP#conf t
ISP(config)#ip route 192.168.0.0 255.255.255.0 209.165.200.226
ISP(config)#ip route 192.168.1.0 255.255.255.0 209.165.200.226
Configure a DHCPv4 Server on R2
Now, make R2 work as a DHCPv4 server.
On R2, configure:
- DHCP address pools for subordinate LANs
- excluded addresses from the DHCP pools
- DNS Server (s0/0/1 on ISP)
- default router
DHCPv4 Server setting on R2 for R1’s 192.168.0.0 network
R2>en
R2#conf t
R2(config)#ip dhcp excluded-address 192.168.0.1 192.168.0.5
R2(config)#ip dhcp pool R1G0
R2(dhcp-config)#network 192.168.0.0 255.255.255.0
R2(dhcp-config)#default-router 192.168.0.1
R2(dhcp-config)#dns-server 209.165.200.225
R2(dhcp-config)#domain-name my-domain.com
R2(dhcp-config)#exit
What happens above is that you exclude the first five addresses of 192.168.0.0 network from .1 to .5 so that the rest of addresses can be available to be leased to clients. Make sure you do not exclude the network address 192.168.0.0
You then define the DHCP pool and its name for the network. You can set any other name but picking up something simple and obvious name helps your life a lot easier.
After that, define the network with its subnet mask and the default router so that client can use it as the default gateway.
You then set up DNS server (ISP) and give the domain name. You don’t have to set up domain name, but it’s available from the Packet Tracer 7.3
DHCPv4 Server setting on R2 for R1’s 192.168.1.0 network
Do the same as above with a set of the following values for 192.168.1.0 network of R1.
R2(config)#ip dhcp excluded-address 192.168.1.1 192.168.1.5
R2(config)#ip dhcp pool R1G1
R2(dhcp-config)#network 192.168.1.0 255.255.255.0
R2(dhcp-config)#default-router 192.168.1.1
R2(dhcp-config)#dns-server 209.165.200.225
R2(dhcp-config)#domain-name my-domain.com
Configure a DHCP Relay Agent
Make R1 work as an relay agent.
On R1, you will configure IP helper addresses in order to forward all DHCP requests to the DHCP server, which is R2 in our scenario.
R1>en
R1#conf t
R1(config)#int g0/0
R1(config-if)#ip helper-address 192.168.2.254
R1(config-if)#exit
R1(config)#int g0/1
R1(config-if)#ip helper-address 192.168.2.254
R1(config-if)#exit
In each of the interfaces at R1, the command ip helper-address 192.168.2.254
indicates 192.168.2.254 which is the serial port 0/0/0 at R2.
Request an IP address from the DCHP Server
Once you enable DHCP by clicking the DHCP radio button on each of the end devices (PCs), each of them receives the first available IP address except the excluded addresses.
As seen below, PC-A takes 192.168.1.6 and PC-B takes 192.168.0.6
By typing show ip dhcp binding on R2 (server), you can view current DHCP address leases.