熱備份路由器協定HSRP和虛拟路由器備援協定VRRP
HSRP:
該協定中含有多台路由器,對應一個HSRP組。該組中隻有一個路由器承擔轉發使用者流量的職責,這就是活動路由器。當活動路由器失效後,備份路由器将承擔該職責,成為新的活動路由器。這就是熱備份的原理。
我們通過一個小案例說明它的熱備份原理。
案例拓撲:

實驗原理:
R1作為vlan10使用者的的主路由器,即vlan10使用者通路inter網時,資料都走r1通過,當r1壞掉時,vlan10使用者的資料可以通過r2通路internet
R2作為vlan20使用者的的主路由器,即vlan20使用者通路inter網時,資料都走r2通過,當r2壞掉時,vlan20使用者的資料可以通過r1通路internet
當然我們還可以在sw1和sw2之間做端口聚合,再做一次備份
參考配置:
r1# show run
Building configuration...
Current configuration : 1199 bytes
!
version 12.4
hostname r1
interface FastEthernet0/0
ip address 1.1.1.1 255.255.255.0
ip nat outside(作為nat的外部端口)
ip virtual-reassembly
duplex auto
speed auto
interface FastEthernet1/0
no ip address
ip nat inside(nat的内部端口)
interface FastEthernet1/0.10(劃分子接口)
encapsulation dot1Q 10(封裝dot1q)
ip address 192.168.10.1 255.255.255.0
ip nat inside
standby 10 ip 192.168.10.254
standby 10 priority 120(作為vlan10的主路由器)
standby 10 preempt
standby 10 track FastEthernet0/0 30(在fa0/0上做端口監聽,若出現故障優先級減30)
interface FastEthernet1/0.20(劃分子接口)
encapsulation dot1Q 20(封裝dot1q)
ip address 192.168.20.1 255.255.255.0
standby 20 ip 192.168.20.254(r1為vlan20的備份路由器)
ip http server
no ip http secure-server
ip route 0.0.0.0 0.0.0.0 1.1.1.2
ip nat inside source list 1 interface FastEthernet0/0 overload(nat端口複用)
access-list 1 permit any
line con 0
exec-timeout 0 0
logging synchronous
line aux 0
line vty 0 4
End
r2#show run
Current configuration : 1209 bytes
hostname r2
ip nat inside(nat内部端口)
shutdown
interface FastEthernet0/0.10(劃分子接口)
ip address 192.168.10.2 255.255.255.0
standby 10 ip 192.168.10.254(r2作為vlan10的備份路由)
interface FastEthernet0/0.20(劃分子接口)
ip address 192.168.20.2 255.255.255.0
standby 20 ip 192.168.20.254
standby 20 priority 120(r2作為vlan10的主路由)
standby 20 preempt
standby 20 track FastEthernet1/0 30(在fa1/0上監聽當路由器出現故障優先級降低30)
ip address 2.2.2.1 255.255.255.0
ip nat outside(nat外部端口)
ip route 0.0.0.0 0.0.0.0 2.2.2.2
ip nat inside source list 1 interface FastEthernet1/0 overload(nat端口複用)
sw1#show run
Current configuration : 1060 bytes
hostname sw1
interface FastEthernet0/1
switchport mode trunk
interface FastEthernet0/10
switchport access vlan 10
interface FastEthernet0/14
switchport access vlan 20
interface FastEthernet0/15
interface Vlan10
interface Vlan20
sw2#show run
Current configuration : 987 bytes
hostname sw2
interface Vlan1
end
isp#show run
Current configuration : 669 bytes
hostname isp
interface Loopback1
ip address 3.3.3.3 255.255.255.0
ip address 1.1.1.2 255.255.255.0
interface FastEthernet10
ip address 2.2.2.2 255.255.255.0
VRRP:
它是一種路由容錯協定,也可以叫做備份路由協定。一個區域網路絡内的所有主機都設定預設路由,當網内主機發出的目的位址不在本網段時,封包将被通過預設路由發往外部路由器,進而實作了主機與外部網絡的通信。當預設路由器down掉(即端口關閉)之後,内部主機将無法與外部通信,如果路由器設定了VRRP時,那麼這時,虛拟路由将啟用備份路由器,進而實作全網通信。
Sw1作為執行個體10的主路由器,來自vlan10和vlan20的資料以sw1為根選舉阻塞端口
Sw2作為執行個體10的主路由器,來自vlan30和vlan40的資料以sw2為根選舉阻塞端口
若主路由器發生故障,可以使用備份路由器進行資料轉發
Sw1
[Huawei-Vlanif40]
[Huawei-Vlanif40]dis cu
#
sysname Huawei
vlan batch 10 20 30 40
stp instance 10 root primary
stp instance 20 root secondary
cluster enable
stp region-configuration
region-name A
revision-level 1
instance 10 vlan 10 20
instance 20 vlan 30 40
active region-configuration
interface Vlanif1
interface Vlanif10
vrrp vrid 10 virtual-ip 192.168.10.254
vrrp vrid 10 priority 120
vrrp vrid 20 virtual-ip 192.168.10.253
interface Vlanif20
vrrp vrid 21 virtual-ip 192.168.20.254
vrrp vrid 22 virtual-ip 192.168.20.253
vrrp vrid 22 priority 120
interface Vlanif30
ip address 192.168.30.1 255.255.255.0
vrrp vrid 31 virtual-ip 192.168.30.254
vrrp vrid 31 priority 120
vrrp vrid 32 virtual-ip 192.168.30.253
interface Vlanif40
ip address 192.168.40.1 255.255.255.0
vrrp vrid 41 virtual-ip 192.168.40.254
vrrp vrid 42 virtual-ip 192.168.40.253
vrrp vrid 42 priority 120
interface Ethernet0/0/1
port link-type trunk
port trunk allow-pass vlan 2 to 4094
interface Ethernet0/0/2
[Huawei]dis vrrp brief
VRIDStateInterfaceTypeVirtual IP
----------------------------------------------------------------
10BackupVlanif10Normal192.168.10.253
20MasterVlanif10Normal192.168.10.254
21MasterVlanif20Normal192.168.20.253
22BackupVlanif20Normal192.168.20.254
31BackupVlanif30Normal192.168.30.253
32MasterVlanif30Normal192.168.30.254
41MasterVlanif40Normal192.168.40.253
42BackupVlanif40Normal192.168.40.254
Total:8Master:4Backup:4Non-active:0
Sw2
[Huawei]dis cu
stp instance 10 root secondary
stp instance 20 root primary
drop illegal-mac alarm
diffserv domain default
vrrp vrid 20 priority 120
vrrp vrid 21 priority 120
ip address 192.168.30.2 255.255.255.0
vrrp vrid 32 priority 120
ip address 192.168.40.2 255.255.255.0
vrrp vrid 41 priority 120
interface Ethernet0/0/21
10BackupVlanif10Normal192.168.10.254
20MasterVlanif10Normal192.168.10.253
21MasterVlanif20Normal192.168.20.254
22BackupVlanif20Normal192.168.20.253
31BackupVlanif30Normal192.168.30.254
32MasterVlanif30Normal192.168.30.253
41MasterVlanif40Normal192.168.40.254
42BackupVlanif40Normal192.168.40.253
Total:8Master:4 Backup:4Non-active:0
Sw3
interface MEth0/0/1
return
sw4
<Huawei>dis cu
驗證資訊:
Instance 10
[Huawei]dis stp instance 10
-------[MSTI 10 Global Info]-------
MSTI Bridge ID:4096.4c1f-ccb1-8c98
MSTI RegRoot/IRPC:0.4c1f-cc38-a98d / 1
MSTI RootPortId:128.21
MSTI Root Type:Secondary root
Master Bridge:32768.4c1f-cc17-56ed
Cost to Master:1
TC received:4
TC count per hello:0
Time since last TC:0 days 0h:0m:25s
Number of TC:6
Last TC occurred:Ethernet0/0/21
----[Port1(Ethernet0/0/1)][LEARNING]----
Port Role:Designated Port
Port Priority:128
Port Cost(Dot1T ):Config=auto / Active=1
Designated Bridge/Port:4096.4c1f-ccb1-8c98 / 128.1
Port Times:RemHops 19
TC or TCN send:5
TC or TCN received:0
----[Port2(Ethernet0/0/2)][LEARNING]----
Designated Bridge/Port:4096.4c1f-ccb1-8c98 / 128.2
TC or TCN received:2
----[Port21(Ethernet0/0/21)][FORWARDING]----
Port Role:Root Port
Designated Bridge/Port:0.4c1f-cc38-a98d / 128.21
Port Times:RemHops 20
TC or TCN send:2
----[Port22(Ethernet0/0/22)][DISCARDING]----
Port Role:Alternate Port
Designated Bridge/Port:0.4c1f-cc38-a98d / 128.22
TC or TCN send:0
Instance 20
[Huawei]dis stp instance 20
-------[MSTI 20 Global Info]-------
MSTI Bridge ID:0.4c1f-ccb1-8c98
MSTI RegRoot/IRPC:0.4c1f-ccb1-8c98 / 0
MSTI RootPortId:0.0
MSTI Root Type:Primary root
TC received:7
Time since last TC:0 days 0h:0m:59s
Last TC occurred:Ethernet0/0/22
----[Port1(Ethernet0/0/1)][FORWARDING]----
Designated Bridge/Port:0.4c1f-ccb1-8c98 / 128.1
TC or TCN send:8
----[Port2(Ethernet0/0/2)][FORWARDING]----
Designated Bridge/Port:0.4c1f-ccb1-8c98 / 128.2
TC or TCN send:9
TC or TCN received:3
Designated Bridge/Port:0.4c1f-ccb1-8c98 / 128.21
TC or TCN send:3
TC or TCN received:4
----[Port22(Ethernet0/0/22)][FORWARDING]----
Designated Bridge/Port:0.4c1f-ccb1-8c98 / 128.22