Page Nav

HIDE

Grid

GRID_STYLE

HSRP Configuration for Gateway Redundancy (Packet Tracer Lab)

A PC can have only one default gateway. If that router fails, every user on the LAN loses access to other networks, even when a second route...

A PC can have only one default gateway. If that router fails, every user on the LAN loses access to other networks, even when a second router is sitting right next to it. In this lab you will configure Hot Standby Router Protocol (HSRP) on two routers so they share one virtual gateway address, then pull the plug on the active router and watch the standby take over.

How HSRP works

HSRP is a Cisco first-hop redundancy protocol. Two or more routers on the same LAN join an HSRP group and agree on a virtual IP address and a virtual MAC address. PCs use the virtual IP as their default gateway. One router is elected active and answers ARP requests for the virtual IP and forwards traffic. Another is standby and listens. If the standby stops hearing hello messages from the active router for the hold time, it becomes active and starts using the same virtual MAC, so the PCs never notice the change.

ItemHSRP version 1HSRP version 2
DefaultYesNo (standby version 2)
Group numbers0–2550–4095
Multicast address224.0.0.2224.0.0.102
Virtual MAC0000.0C07.ACxx (xx = group in hex)0000.0C9F.Fxxx (xxx = group in hex)
IPv6 supportNoYes

The default timers are a 3-second hello and a 10-second hold time. The default priority is 100, and the highest priority wins the active role. If priorities are equal, the router with the highest real IP address on that interface wins.

Lab topology

R1 and R2 both connect to the LAN switch on G0/0 and to an upstream router R3 on G0/1. R3 has a loopback that stands in for the internet. OSPF runs between all three routers so that R3 always knows a working path back to the LAN.

Simulated internet 203.0.113.1/24 PC1 PC2 SW1 R1 Pri 110 Active R2 Pri 100 Standby R3 RID 3.3.3.3 HSRP group 1 VIP 192.168.1.254 Fa0 Fa0 192.168.1.10 GW 192.168.1.254 192.168.1.11 GW 192.168.1.254 LAN 192.168.1.0/24 G0/0 .2 G0/0 .3 G0/1 .1 G0/1 .1 G0/0 .2 G0/1 .2 Lo0 10.0.13.0/30 10.0.23.0/30
Figure: HSRP lab topology with R1 and R2 sharing the virtual gateway 192.168.1.254.
DeviceInterfaceIP address / maskNotes
R1G0/0192.168.1.2/24HSRP group 1, priority 110 (active)
R1G0/110.0.13.1/30To R3 G0/0
R2G0/0192.168.1.3/24HSRP group 1, priority 100 (standby)
R2G0/110.0.23.1/30To R3 G0/1
R3G0/010.0.13.2/30To R1
R3G0/110.0.23.2/30To R2
R3Loopback0203.0.113.1/24Simulated internet
Virtual gateway-192.168.1.254Shared by R1 and R2
PC1Fa0192.168.1.10/24Gateway 192.168.1.254
PC2Fa0192.168.1.11/24Gateway 192.168.1.254

Use three 2911 routers and one 2960 switch. Leave the switch at its default configuration; all ports are in VLAN 1.

Step 1: IP addressing and OSPF

R1(config)#interface g0/0
R1(config-if)#ip address 192.168.1.2 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#interface g0/1
R1(config-if)#ip address 10.0.13.1 255.255.255.252
R1(config-if)#no shutdown
R1(config-if)#exit
R1(config)#router ospf 1
R1(config-router)#router-id 1.1.1.1
R1(config-router)#network 192.168.1.0 0.0.0.255 area 0
R1(config-router)#network 10.0.13.0 0.0.0.3 area 0

R2(config)#interface g0/0
R2(config-if)#ip address 192.168.1.3 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#interface g0/1
R2(config-if)#ip address 10.0.23.1 255.255.255.252
R2(config-if)#no shutdown
R2(config-if)#exit
R2(config)#router ospf 1
R2(config-router)#router-id 2.2.2.2
R2(config-router)#network 192.168.1.0 0.0.0.255 area 0
R2(config-router)#network 10.0.23.0 0.0.0.3 area 0

R3(config)#interface g0/0
R3(config-if)#ip address 10.0.13.2 255.255.255.252
R3(config-if)#no shutdown
R3(config-if)#interface g0/1
R3(config-if)#ip address 10.0.23.2 255.255.255.252
R3(config-if)#no shutdown
R3(config-if)#interface loopback0
R3(config-if)#ip address 203.0.113.1 255.255.255.0
R3(config-if)#exit
R3(config)#router ospf 1
R3(config-router)#router-id 3.3.3.3
R3(config-router)#network 10.0.13.0 0.0.0.3 area 0
R3(config-router)#network 10.0.23.0 0.0.0.3 area 0
R3(config-router)#network 203.0.113.0 0.0.0.255 area 0

R3 will learn 192.168.1.0/24 from both R1 and R2 with equal cost, and R1 and R2 learn 203.0.113.1/32 from R3 (OSPF advertises a loopback as a /32 host route by default). Check with show ip route ospf before you continue. HSRP only solves the first hop; the rest of the routing still has to be correct.

Step 2: Configure HSRP on R1 (active)

R1(config)#interface g0/0
R1(config-if)#standby 1 ip 192.168.1.254
R1(config-if)#standby 1 priority 110
R1(config-if)#standby 1 preempt
  • standby 1 ip 192.168.1.254 – joins HSRP group 1 and sets the virtual IP. It must be in the interface's subnet and must not belong to any real device.
  • standby 1 priority 110 – higher than the default 100, so R1 should be active.
  • standby 1 preempt – lets R1 take the active role back after it recovers. Without preempt, the current active router keeps the role even if a higher-priority router comes online.

Step 3: Configure HSRP on R2 (standby)

R2(config)#interface g0/0
R2(config-if)#standby 1 ip 192.168.1.254
R2(config-if)#standby 1 preempt

R2 keeps the default priority of 100. I enable preempt on R2 as well; it does no harm, and it matters if you later change priorities. Within a few seconds R2 will log a state change to Standby, and R1 to Active.

%HSRP-6-STATECHANGE: GigabitEthernet0/0 Grp 1 state Speak -> Standby

Step 4: Verify HSRP

R1#show standby brief
                     P indicates configured to preempt.
                     |
Interface   Grp  Pri P State    Active          Standby         Virtual IP
Gig0/0      1    110 P Active   local           192.168.1.3     192.168.1.254

R2#show standby brief
                     P indicates configured to preempt.
                     |
Interface   Grp  Pri P State    Active          Standby         Virtual IP
Gig0/0      1    100 P Standby  192.168.1.2     local           192.168.1.254

Read it from each router's point of view: R1 says it is Active ("local") and R2 at 192.168.1.3 is standby. R2 says the opposite. If both routers show Active, they are not hearing each other's hellos; check the switch ports and VLANs.

R1#show standby
GigabitEthernet0/0 - Group 1
  State is Active
    2 state changes, last state change 00:03:41
  Virtual IP address is 192.168.1.254
  Active virtual MAC address is 0000.0C07.AC01
    Local virtual MAC address is 0000.0C07.AC01 (v1 default)
  Hello time 3 sec, hold time 10 sec
    Next hello sent in 1.296 secs
  Preemption enabled
  Active router is local
  Standby router is 192.168.1.3, priority 100 (expires in 8.744 sec)
  Priority 110 (configured 110)
  Group name is "hsrp-Gi0/0-1" (default)

The virtual MAC 0000.0C07.AC01 ends in 01 because this is group 1 in HSRP version 1. On PC1, run ping 192.168.1.254 and then arp -a; you should see 192.168.1.254 mapped to 0000.0c07.ac01, not to R1's physical MAC.

C:\>arp -a
  Internet Address      Physical Address      Type
  192.168.1.254         0000.0c07.ac01        dynamic

Step 5: Failover test

From PC1, start a continuous ping to the simulated internet:

C:\>ping -t 203.0.113.1

While it runs, run tracert 203.0.113.1 from PC2. The first hop is 192.168.1.2, which proves traffic is going through R1. (Traceroute shows R1's real address, not the virtual one, because the router replies from its own interface IP.)

Now simulate a failure. On R1:

R1(config)#interface g0/0
R1(config-if)#shutdown

On R2 you will see:

%HSRP-6-STATECHANGE: GigabitEthernet0/0 Grp 1 state Standby -> Active

PC1 may show one or two "Request timed out" lines, then replies resume. Because shutdown is a graceful event, R1 sends an HSRP resign message and R2 takes over almost at once. A sudden failure, such as pulling R1's power cable, takes longer: R2 waits for the 10-second hold time to expire, and R3 needs a moment for OSPF to stop using the path through R1. A new tracert from PC2 now shows 192.168.1.3 as hop 1. The PCs did not change their gateway or their ARP entry; R2 simply took over the virtual MAC.

R2#show standby brief
                     P indicates configured to preempt.
                     |
Interface   Grp  Pri P State    Active          Standby         Virtual IP
Gig0/0      1    100 P Active   local           unknown         192.168.1.254

"unknown" in the Standby column means there is no backup right now. In production, that should trigger an alert.

Recovery and preemption

Bring R1 back with no shutdown. Because R1 has the higher priority and preempt is enabled, it takes over again after it moves through its Listen and Speak states (the exact sequence of messages can vary slightly between IOS and Packet Tracer versions):

R1:
%HSRP-6-STATECHANGE: GigabitEthernet0/0 Grp 1 state Speak -> Standby
%HSRP-6-STATECHANGE: GigabitEthernet0/0 Grp 1 state Standby -> Active

R2:
%HSRP-6-STATECHANGE: GigabitEthernet0/0 Grp 1 state Active -> Speak
%HSRP-6-STATECHANGE: GigabitEthernet0/0 Grp 1 state Speak -> Standby

Remove standby 1 preempt from R1 and repeat the test: this time R2 stays active after R1 recovers. That is the clearest way to see what preempt really does.

The continuous ping on PC1 during the failover looks like this:

Reply from 203.0.113.1: bytes=32 time<1ms TTL=254
Reply from 203.0.113.1: bytes=32 time<1ms TTL=254
Request timed out.
Reply from 203.0.113.1: bytes=32 time<1ms TTL=254
Reply from 203.0.113.1: bytes=32 time<1ms TTL=254

Optional: track the uplink

The test above shut the LAN interface. But what if R1's uplink to R3 fails while its LAN side stays up? R1 remains active and has to send everything sideways to R2 or drop it. Interface tracking lowers R1's priority when the uplink goes down:

R1(config)#interface g0/0
R1(config-if)#standby 1 track GigabitEthernet0/1 20

If G0/1 goes down, R1's priority drops from 110 to 90. R2 at 100 is now higher and, because R2 also has preempt, it takes over. Shut R1's G0/1 and confirm with show standby brief. Newer IOS versions prefer track objects (track 1 interface GigabitEthernet0/1 line-protocol with standby 1 track 1 decrement 20); check which form your Packet Tracer version accepts.

Prefer video? Watch more hands-on labs on the Technical Hakim YouTube channel.

Common mistakes

  • PC gateway set to a real router address. If PC1 points to 192.168.1.2, HSRP does nothing for it. The gateway must be the virtual IP.
  • Different group numbers on the two routers. R1 in group 1 and R2 in group 10 are two separate groups, and both become active.
  • Equal priorities and surprise elections. With both at 100, R2 wins because 192.168.1.3 is higher than 192.168.1.2. Set the priority you want explicitly.
  • Forgetting preempt. The preferred router recovers but never takes back the active role, and traffic stays on the backup path indefinitely.
  • Version mismatch. One router on standby version 2 and the other on version 1 will not form a group, because they use different multicast addresses.
  • Tracking decrement too small. A decrement of 5 takes R1 from 110 to 105, which is still above 100, so failover never happens.

Summary

HSRP gives a LAN one virtual gateway that is backed by two routers. You set the virtual IP on both routers, raised the priority on the preferred one, enabled preempt so it takes back control, and proved failover with a continuous ping and show standby brief. Add interface tracking so an uplink failure moves the active role too.

Related tutorials

  • OSPF Single-Area Configuration: Full Lab with Verification
  • Inter-VLAN Routing with Router-on-a-Stick (Packet Tracer Lab)
  • Static Routes vs Default Routes: When to Use Each (with Lab)
  • Network Troubleshooting with ping, traceroute and show Commands

Sources

  • RFC 2281 – Cisco Hot Standby Router Protocol (HSRP): https://www.rfc-editor.org/rfc/rfc2281
  • Cisco IOS First Hop Redundancy Protocols Configuration Guide – Configuring HSRP
  • Cisco IOS IP Application Services Command Reference – standby commands
  • RFC 2328 – OSPF Version 2: https://www.rfc-editor.org/rfc/rfc2328

No comments