HSRP相關知識+模擬實驗

HSRP:熱備份路由器協議(Hot Standby Router Protocol),是cisco的私有協議。

該協議中含有多臺路由器,對應一個HSRP組。該組中只有一個路由器承擔轉發用戶流量的職責,這就是活動路由器。當活動路由器失效後,備份路由器將承擔該職責,成爲新的活動路由器。這就是熱備份的原理。

實現HSRP的條件是系統中有多臺路由器,它們組成一個“熱備份組”,這個組形成一個虛擬路由器。在任一時刻,一個組內只有一個路由器是活動的,並由它來轉發數據包,如果活動路由器發生了故障,將選擇一個備份路由器來替代活動路由器,但是在本網絡內的主機看來,虛擬路由器沒有改變。所以主機仍然保持連接,沒有受到故障的影響,這樣就較好地解決了路由器切換的問題。

爲了減少網絡的數據流量,在設置完活動路由器和備份路由器之後,只有活動路由器和備份路由器定時發送HSRP報文。如果活動路由器失效,備份路由器將接管成爲活動路由器。如果備份路由器失效或者變成了活躍路由器,將由另外的路由器被選爲備份路由器。

版本
IOS中的默認HSRP版本是HSRPv1,它允許配置最多255個組號碼。由於一臺設備可以支持4095個VLAN,因此如果需要的話,管理員要在多個接口上重複使用相同的HSRP組號碼。儘管這會引起管理員的困惑,但這種配置方法是可行的。HSRPv1使用虛擬MAC地址是0000.0C07.ACXX,XX表示HSRP組;並向組播地址224.0.0.2發送Hello數據包。

HSRPv2使用的數據包格式與HSRPv1不同。管理員要確保在同一HSRP組中的所有路由器上配置了相同的HSRP版本,因爲不同版本的設備之間無法識別Hello消息。HSRPv2的組播地址爲224.0.0.102,備份組編號爲0-4095。

HSRPv1與v2不兼容,一個HSRP組中主設備與備份設備的版本和編號必須一致。

SLA

Internetwork Performance Monitor (IPM) is a network management application that allows you to monitor the performance of multi-protocol networks. IPM monitors the network performance by configuring collectors on IP SLA (IP Service Level Agreement) capable source devices (routers) and collects the performance-related statistics from these devices(IPM通過收集SLA的數據)

SLA總體實現網絡環境穩定性的監測、讓網絡安裝自己的意圖來運行
SLA可以測量UDP響應時間、單向延遲、抖動、掉包狀況和連通性
可以結合命令行和snmp來實現前期告警 實現觸發的trap.

傳統的負載均衡、冗餘鏈路的執行是基於鏈路的中斷來完成切換、類似於HSRP的track功能。

很多時候端口的中斷、並不一定能反映網絡的真實狀況。很有可能HSRP追蹤到接口是正常的、但是數據不通。SLA可用於鏈路故障檢測。


實驗模擬
在這裏插入圖片描述
SW-1

//封裝接口
SW-1(config)#vlan 50
SW-1(config-vlan)#vlan 60
SW-1(config-vlan)#exit
SW-1(config)#interface range g0/0-2
SW-1(config-if-range)#switchport trunk encapsulation dot1q 
SW-1(config-if-range)#switchport mode trunk 
SW-1(config-if-range)#exit
//修改模式爲Rapid-PVST(思科私有)
SW-1(config)#spanning-tree mode pvst 
//修改vlan的優先級
SW-1(config)#spanning-tree vlan 50 priority 0
SW-1(config)#spanning-tree vlan 60 priority 4096

SW-1(config)#interface vlan 50
SW-1(config-if)#ip address 192.168.50.1 255.255.255.0
SW-1(config-if)#no shutdown 
SW-1(config-if)#exit
SW-1(config)#interface vlan 60
SW-1(config-if)#ip address 192.168.60.1 255.255.255.0
SW-1(config-if)#no shutdown 
SW-1(config-if)#exit
//將vlan備份到網關
SW-1(config)#interface vlan 50
SW-1(config-if)#standby version 2//版本
SW-1(config-if)#standby 50 ip 192.168.50.254
SW-1(config-if)#standby 50 priority 105//設置優先級,越大越優。默認值爲100
SW-1(config-if)#standby 50 preempt delay minimum 60//開啓搶佔並設置延遲時間.只有主設備開啓延遲時間,備用設備不開啓。只要主設備出現故障,備份設備立即搶佔,以減小對網絡的影響
SW-1(config-if)#standby 50 timers 1 3//設置hello包持有時間,全組中儘量一致
SW-1(config-if)#exit
/*SW-1#show standby brief查看備份設置,也可以使用如下命令*/
SW-1(config)#do show run interface vlan 50
Building configuration...

Current configuration : 197 bytes
!
interface Vlan50
 ip address 192.168.50.1 255.255.255.0
 standby version 2
 standby 50 ip 192.168.50.254
 standby 50 timers 1 3
 standby 50 priority 105
 standby 50 preempt delay minimum 60
end

SW-1(config)#do show run interface vlan 60
Building configuration...

Current configuration : 155 bytes
!
interface Vlan60
 ip address 192.168.60.1 255.255.255.0
 standby version 2
 standby 60 ip 192.168.60.254
 standby 60 timers 1 3
 standby 60 preempt
end

SW-1(config)#do show standby brief 
                     P indicates configured to preempt.
                     |
Interface   Grp  Pri P State   Active          Standby         Virtual IP
Vl50        50   105 P Active  local           192.168.50.2    192.168.50.254
Vl60        60   100 P Standby 192.168.60.2    local           192.168.60.254
//創建地址池
SW-1(config)#ip dhcp pool vlan50
SW-1(dhcp-config)#network 192.168.50.0 /24
SW-1(dhcp-config)#default-router 192.168.50.254
SW-1(dhcp-config)#dns-server 114.114.114.114
SW-1(dhcp-config)#exit 
SW-1(config)#ip dhcp excluded-address 192.168.50.1
SW-1(config)#ip dhcp excluded-address 192.168.60.1
SW-1(config)#ip dhcp excluded-address 192.168.50.254
SW-1(config)#ip dhcp excluded-address 192.168.60.254
SW-1(config)#ip dhcp excluded-address 192.168.50.2
SW-1(config)#ip dhcp excluded-address 192.168.60.2

SW-1(config)#do show run | section dhcp//檢查配置
ip dhcp excluded-address 192.168.50.1
ip dhcp excluded-address 192.168.60.1
ip dhcp excluded-address 192.168.50.254
ip dhcp excluded-address 192.168.60.254
ip dhcp excluded-address 192.168.50.2
ip dhcp excluded-address 192.168.60.2
ip dhcp pool vlan50
 network 192.168.50.0 255.255.255.0
 default-router 192.168.50.254 
 dns-server 114.114.114.114 
ip dhcp pool vlan60
 network 192.168.60.0 255.255.255.0
 dns-server 114.114.114.114 
SW-1(config)#vlan 10
SW-1(config-vlan)#exit
SW-1(config)#interface g0/3
SW-1(config-if)#switchport mode access 
SW-1(config-if)#switchport access vlan 10
SW-1(config-if)#exit
SW-1(config)#interface vlan 10
SW-1(config-if)#ip address 17.1.1.1 255.255.255.0
SW-1(config-if)#no shutdown 
SW-1(config-if)#exit
SW-1(config)#ip route 0.0.0.0 0.0.0.0 17.1.1.2
//定義SLA列表
SW-1(config)#ip sla 1
SW-1(config-ip-sla)#icmp-echo 9.9.9.9 source-interface vlan 50//根據源與目的地檢測鏈路狀態
SW-1(config-ip-sla-echo)#frequency 5//設置發送ping包的時間間隔
SW-1(config-ip-sla-echo)#timeout 5000//設置時間,在此時間內未收到回覆則認爲鏈路故障
SW-1(config-ip-sla-echo)#exit
SW-1(config)#ip sla schedule 1 start-time now life forever //設置ping包的發送時間及持續時間
SW-1(config)#track 50 ip sla 1 reachability//創建track測試鏈路可達性
SW-1(config-track)#exit
SW-1(config)#interface vlan 50
SW-1(config-if)#standby 50 track 50 decrement 10//若出現故障則優先級減掉設置的數值(本文設置爲10)
SW-1(config-if)#exit

SW-2

//封裝接口
SW-2(config)#vlan 50
SW-2(config-vlan)#vlan 60
SW-2(config-vlan)#exit
SW-2(config)#interface range g0/0-2
SW-2(config-if-range)#switchport trunk encapsulation dot1q 
SW-2(config-if-range)#switchport mode trunk 
SW-2(config-if-range)#exit
//修改模式爲Rapid-PVST(思科私有)
SW-2(config)#spanning-tree mode pvst 
//修改vlan的優先級
SW-2(config)#spanning-tree vlan 50 priority 4096
SW-2(config)#spanning-tree vlan 60 priority 0

SW-2(config)#interface vlan 50
SW-2(config-if)#ip address 192.168.50.2 255.255.255.0
SW-2(config-if)#no shutdown 
SW-2(config-if)#exit
SW-2(config)#interface vlan 60
SW-2(config-if)#ip address 192.168.60.2 255.255.255.0
SW-2(config-if)#no shutdown 
SW-2(config-if)#exit
//備份設備做HSRP相關配置。備份設備不用設置優先級,默認值100,只需在主設備設置比100大的值即可
SW-2(config)#interface vlan 50
SW-2(config-if)#standby version 2//版本
SW-2(config-if)#standby 50 ip 192.168.50.254
SW-2(config-if)#standby 50 preempt 
SW-2(config-if)#standby 50 timers 1 3//設置hello持有時間
SW-2(config-if)#exit
//SW-2是vlan 60的主設備,應當開啓搶佔延遲時間
SW-2(config)#interface vlan 60
SW-2(config-if)#standby version 2
SW-2(config-if)#standby 60 ip 192.168.60.254
SW-2(config-if)#standby 60 priority 105
SW-2(config-if)#standby 60 preempt 
SW-2(config-if)#standby 60 preempt delay minimum 60
SW-2(config-if)#standby 60 timers 1 3
SW-2(config-if)#exit
SW-2(config)#do show run interface vlan 50
Building configuration...

Current configuration : 155 bytes
!
interface Vlan50
 ip address 192.168.50.2 255.255.255.0
 standby version 2
 standby 50 ip 192.168.50.254
 standby 50 timers 1 3
 standby 50 preempt
end

SW-2(config)#do show run interface vlan 60//檢查vlan 60的配置
Building configuration...

Current configuration : 197 bytes
!
interface Vlan60
 ip address 192.168.60.2 255.255.255.0
 standby version 2
 standby 60 ip 192.168.60.254
 standby 60 timers 1 3
 standby 60 priority 105
 standby 60 preempt delay minimum 60
end

SW-2(config)#do show standby brief 
                     P indicates configured to preempt.
                     |
Interface   Grp  Pri P State   Active          Standby         Virtual IP
Vl50        50   100 P Standby 192.168.50.1    local           192.168.50.254
Vl60        60   105 P Active  local           192.168.60.1    192.168.60.254

SW-2(config)#vlan 20
SW-2(config-vlan)#exit
SW-2(config)#interface g0/3
SW-2(config-if)#switchport mode access   
SW-2(config-if)#switchport access vlan 20
SW-2(config-if)#exit
SW-2(config)#interface vlan 20
SW-2(config-if)#ip address 28.1.1.1 255.255.255.0
SW-2(config-if)#no shutdown 
SW-2(config-if)#exit
SW-2(config)#ip route 0.0.0.0 0.0.0.0 28.1.1.2
SW-2(config)#ip sla 1//定義SLA
SW-2(config-ip-sla)#icmp-echo 9.9.9.9 source-interface vlan 60//根據源與目的地檢測鏈路狀態
SW-2(config-ip-sla-echo)#frequency 5//設置發送ping包的時間間隔
SW-2(config-ip-sla-echo)#timeout 5000//設置時間,在此時間內未收到回覆則認爲鏈路故障
SW-2(config-ip-sla-echo)#exit
SW-2(config)#ip sla schedule 1 start-time now life forever //設置ping包的發送時間及持續時間
SW-2(config)#track 60 ip sla 1 reachability//創建track測試鏈路可達性
SW-2(config-track)#exit
SW-2(config)#interface vlan 60
SW-2(config-if)#standby 60 track 60 decrement 10//若出現故障則優先級減掉設置的數值(本文設置爲10)
SW-2(config-if)#exit

SW-3

//封裝接口
SW-3(config)#vlan 50
SW-3(config-vlan)#exit
SW-3(config)#interface g0/0
SW-3(config-if)#switchport mode access 
SW-3(config-if)#switchport access vlan 50
SW-3(config-if)#exit
SW-3(config)#interface range g0/1-2
SW-3(config-if-range)#switchport trunk encapsulation dot1q 
SW-3(config-if-range)#switchport mode trunk 
SW-3(config-if-range)#exit
//修改模式爲Rapid-PVST(思科私有)
SW-3(config)#spanning-tree mode pvst 

SW-4

//封裝接口
SW-4(config)#vlan 60
SW-4(config-vlan)#exit
SW-4(config)#interface g0/0
SW-4(config-if)#switchport mode access 
SW-4(config-if)#switchport access vlan 60
SW-4(config-if)#exit
SW-4(config)#interface range g0/1-2
SW-4(config-if-range)#switchport trunk encapsulation dot1q 
SW-4(config-if-range)#switchport mode trunk 
SW-4(config-if-range)#exit
//修改模式爲Rapid-PVST(思科私有)
SW-4(config)#spanning-tree mode pvst 

R7

R7(config)#interface g0/0
R7(config-if)#ip address 17.1.1.2 255.255.255.0
R7(config-if)#no shutdown 
R7(config-if)#exit
R7(config)#interface g0/1
R7(config-if)#ip address 79.1.1.1 255.255.255.0
R7(config-if)#no shutdown 
R7(config-if)#exit
R7(config)#ip route 0.0.0.0 0.0.0.0 79.1.1.2
R7(config)#interface g0/0
R7(config-if)#ip nat inside 
R7(config-if)#exit
R7(config)#interface g0/1
R7(config-if)#ip nat outside 
R7(config-if)#exit
//命名式擴展ACL
R7(config)#ip access-list extended NAT
R7(config-ext-nacl)#permit ip 192.168.50.0 0.0.0.255 any
R7(config-ext-nacl)#permit ip 192.168.60.0 0.0.0.255 any
R7(config-ext-nacl)#exit
R7(config)#do show access-lists //查看抓取列表
Extended IP access list NAT
    10 permit ip 192.168.50.0 0.0.0.255 any
    20 permit ip 192.168.60.0 0.0.0.255 any
R7(config)#ip nat inside source list NAT interface g0/1 overload //調用
R7(config)#ip route 192.168.0.0 255.255.0.0 17.1.1.1

R8

R8(config)#interface g0/0
R8(config-if)#ip address 28.1.1.2 255.255.255.0
R8(config-if)#no shutdown 
R8(config-if)#exit
R8(config)#interface g0/1
R8(config-if)#ip address 89.1.1.1 255.255.255.0
R8(config-if)#no shutdown 
R8(config-if)#exit
R8(config)#ip route 0.0.0.0 0.0.0.0 89.1.1.2
R8(config)#interface g0/0
R8(config-if)#ip nat inside 
R8(config-if)#exit
R8(config)#interface g0/1
R8(config-if)#ip nat outside 
R8(config-if)#exit 
//命名式擴展ACL
R8(config)#ip access-list extended NAT 
R8(config-ext-nacl)#permit ip 192.168.50.0 0.0.0.255 any
R8(config-ext-nacl)#permit ip 192.168.60.0 0.0.0.255 any
R8(config-ext-nacl)#exit
R8(config)#ip nat inside source list NAT interface g0/1 overload 
R8(config)#ip route 192.168.0.0 255.255.0.0 28.1.1.1

R9

R9(config)#interface g0/1
R9(config-if)#ip address 89.1.1.2 255.255.255.0
R9(config-if)#no shutdown 
R9(config-if)#exit
R9(config)#interface g0/0
R9(config-if)#ip address 79.1.1.2 255.255.255.0
R9(config-if)#no shutdown 
R9(config-if)#exit
R9(config)#interface loopback 0
R9(config-if)#ip address 9.9.9.9 255.255.255.255
R9(config-if)#no shutdown 
R9(config-if)#exit

至此,網關熱備份配置完成,已實現全網互通。
現在我們來讓某個設備的端口down掉,來模擬網絡鏈路出現故障的情況。觀察主設備的情況。
以PC7爲例,令PC7一直 ping 外網R3,在此期間將SW-1的G0/3接口down掉模擬鏈路故障,觀察PC7的ping 信息。
PC7:

PC7#ping 9.9.9.9 repeat 1000

SW-1

SW-1(config)#interface g0/3
SW-1(config-if)#shutdown 

在這裏插入圖片描述
可見,在ping的期間鏈路出現故障後,存在短暫的數據斷流,但由於HSRP的存在,當主設備出現故障時,備份設備立即成爲新的主設備,從而使鏈路很快的恢復通信。

查看主備設備信息可發現,主設備出現故障,優先級降低變爲95(先前配置時設置的減小值爲10),從而使備份設備變爲新的主設備:
在這裏插入圖片描述
traceroute查看路徑:
在這裏插入圖片描述
可見,數據通過的路徑已經切換,從SW-2上發送至外網。

重新打開剛剛關閉的端口,再次查看設備信息:
在這裏插入圖片描述
traceroute查看路徑:
在這裏插入圖片描述
可見,鏈路恢復後主備設備重新切換回來,數據通過的路徑也隨之恢復爲原先的路徑。


總結

HSRP具有如下特點:
1.高度的可靠性,兩臺路由器之間採用HSRP(熱備份冗餘協議)協議,來保證兩臺路由器中的任意一臺down掉,或路由器的廣域網口down,都會迅速切換到另外一臺。

2.有效的實現了負載均衡,在STAR-S1924F+上劃分出各自的VLAN,儲蓄子網VLAN在左側路由器上的HSRP的優先級較高,默認使用網通的FR線路;郵政系統(辦公、報刊、EMS、VOIP等等)子網VLAN在右側路由器上的HSRP的優先級較高,默認使用聯通的FR線路。充分利用了帶寬資源,而且實現了負載均衡。

3.充分利用了多以太口路由器在劃分多業務網段上的功能,也只有多以太口路由器在HSRP應用中才能實現兩個路由器間的負載分擔,這是具有四個以太口路由器的極大的優點。

4.在右側路由器上啓用QoS策略,VoIP業務需要較低的延時,所以將VoIP業務設置成較高的優先級。

5.通過在交換機上設置VLAN,有效的控制了兩個子網間的安全。

6.不存在單點故障問題。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章