The only way out of a network is through the Default Gateway, and there is no alternative gateway or way to change dynamically when the gateway router goes down.
There is when HSRP gets comes to help. It is able to negotiate between two or more routers who are going to be the virtual router. Provide high availability for the network through redundant routers.
Given the scenario:
Even having two routers in the same network, each has a different IP address and half of the computers go out through Router1 and the other half through Router2 (look at the configured Gateway on the PCs). In case one of the routers stops working the other will not get the traffic.
With HSRP all PCs will have the same default gateway point to a virtual router ‘192.168.1.254‘:
Switch
No configuration at all. All the ports are part of VLAN1.
PC-1
IP Address: 192.168.1.101 Default Gateway: 192.168.1.254
PC-n
IP Address: 192.168.1.1n Default Gateway: 192.168.1.254
PC-24
IP Address: 192.168.1.124 Default Gateway: 192.168.1.254
Router Internet
enable configure terminal hostname Internet no ip domain lookup line con 0 logging synchronous
interface g0/0
ip address 10.0.0.1 255.255.255.252
no shutdown
interface g0/1
ip address 10.0.1.1 255.255.255.252
no shutdown
interface lo0
ip address 8.8.8.8 255.255.255.0
no shutdown
interface lo1
ip address 8.8.4.4 255.255.255.0
no shutdown
router rip
version 2
no auto-summary
network 8.8.8.8
network 8.8.4.4
network 10.0.0.0
network 10.0.1.0
passive-interface lo0
passive-interface lo1
The Loopback interfaces simulate the internet.
Router1
enable configure terminal hostname Router1 no ip domain lookup line con 0 logging synchronous
interface g0/0
ip address 10.0.0.2 255.255.255.252
no shutdown
interface g0/1
ip address 192.168.1.1 255.255.255.0
no shutdown
router rip
version 2
no auto-summary
network 192.168.1.0
network 10.0.0.0
network 10.0.1.0
passive-interface g0/1
Router2
enable configure terminal hostname Router2 no ip domain lookup line con 0 logging synchronous
interface g0/0
ip address 10.0.1.2 255.255.255.252
no shutdown
interface g0/1
ip address 192.168.1.2 255.255.255.0
no shutdown
router rip
version 2
no auto-summary
network 192.168.1.0
network 10.0.0.0
network 10.0.1.0
passive-interface g0/1
Setting up the HSRP on Routers 1 and 2:
Router1
interface g0/1 standby version 2 standby 1 ip 192.168.1.254
Optional commands on Router1:
standby 1 priority 150 standby 1 preempt
By default, the priority is 100 but the highest priority becomes the active router for the HSRP group. If there is a tie, the router with the highest IP address becomes the active router.
Router2
interface g0/1 standby version 2 standby 1 ip 192.168.1.254
The commands above created in both routers one standby group number 1 and both have the same IP, but the priority on Router1 was defined as 150 and Router2 has the default priority 100 (the router with the highest priority becomes the Active). The command ‘preempt’ takes back the Active status when it comes back.
The route from the PCs to the Internet can be verified by issuing:
tracert 8.8.8.8
OR
tracert 8.8.4.4
To check the configuration in each Router issue the commands:
show standby show standby brief
This command informs the router what interfaces it has to monitor:
standby 1 track G0/0