天天看點

HSRP熱備份路由協定配置詳解

【HSRP簡介】

熱待機路由協定的目的就是希望能在網絡内提供趨于100%的資料轉發能力,盡量保證在路由器出現故障的情況下,繼續發往該路由器的資料包不會丢失,能夠自動由其它路由器發送出去。

這是通過一個虛拟的路由器來實作的。子網内的主機以該虛拟路由器作為預設網關并向其發送資料,而各個啟動了HSRP的路由器通過競争來擔當該虛拟路由器的角色并負責這些資料的轉發。負責轉發發向虛拟路由器的資料包的那台路由器為Active狀态,其它一個或多個路由器作為Standby狀态。當Active路由器失效時,Standby路由器通過與Active路由器的資訊互動和計時器來自動取締原來的路由器,将自身變為Active,繼續負責發往虛拟路由器的資料轉發工作。然而,對使用者來說,這種網絡的變化是透明的,亦即可以達到一種。

【實驗拓撲】

(點選圖檔檢視完整大圖) 

各個路由器之間運作RIP協定

PC的預設網關為192.168.1.1 ,也就是我們虛拟出來的網關為192.168.1.1

【配置步驟】

Internet

Router>enable

Router#conf terminal

//路由器基礎配置

Router(config)#no ip domain-lookup

Router(config)#hostname Internet

Internet(config)#line con 0

Internet(config-line)#exec-timeout 0 0

Internet(config-line)#logging synchronous

Internet(config-line)#end

Internet#

Internet#conf t

// 配置路由器各個接口的IP位址

Internet(config)#int e0/0

Internet(config-if)#ip address 192.168.2.1 255.255.255.0

Internet(config-if)#no sh

Internet(config-if)#exit

Internet(config)#int e0/1

Internet(config-if)#ip address 192.168.3.1 255.255.255.0

Internet(config)#int lo0

Internet(config-if)#ip address 100.1.1.1 255.255.255.0

//啟用RIP路由協定

Internet(config)#router rip

Internet(config-router)#version 2

Internet(config-router)#no auto-summary

Internet(config-router)#network 192.168.2.0

Internet(config-router)#network 192.168.3.0

Internet(config-router)#network 100.1.1.0

Internet(config-router)#end

Internet#write

Building configuration...

R1

Router(config)#hostname R1

R1(config)#line con 0

R1(config-line)#exec-timeout 0 0

R1(config-line)#logging synchronous

R1(config-line)#end

R1#conf t

//配置接口IP位址

R1(config)#int e0/0

R1(config-if)#ip address 192.168.2.2 255.255.255.0

R1(config-if)#no sh

R1(config-if)#int e0/1

R1(config-if)#ip address 192.168.1.2 255.255.255.0

R1(config-if)#exit

R1(config)#router rip

R1(config-router)#version 2

R1(config-router)#no auto-summary

R1(config-router)#network 192.168.2.0

R1(config-router)#network 192.168.1.0

R1(config-router)#end

R1#write

//配置HSRP

R1(config)#int e0/1 

R1(config-if)#standby 1 ip 192.168.1.1

R1(config-if)#end

//檢視standby資訊

R1#show standby

Ethernet0/1 - Group 1

<b>  State is Standby   //</b><b>狀态為備份狀态</b>

    3 state changes, last state change 00:06:32

<b>  Virtual IP address is 192.168.1.1  //</b><b>虛拟出來的IP</b><b>位址</b>

  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 0.992 secs

  Preemption disabled

  Active router is 192.168.1.3, priority 100 (expires in 7.892 sec)

  Standby router is local

  Priority 100 (default 100)

  IP redundancy name is "hsrp-Et0/1-1" (default)

R1#

R2

Router#conf t

//路由器基本配置

Router(config)#hostname R2

R2(config)#line con 0

R2(config-line)#exec-timeout 0 0

R2(config-line)#logging synchronous

R2(config-line)#end

R2#conf t

//配置路由器接口IP

R2(config)#int e0/0

R2(config-if)#ip address 192.168.3.2 255.255.255.0

R2(config-if)#no sh

R2(config-if)#int e0/1

R2(config-if)#ip address 192.168.1.3 255.255.255.0

R2(config-if)#exit

R2(config)#router rip

R2(config-router)#version 2

R2(config-router)#no auto-summary

R2(config-router)#network 192.168.3.0

R2(config-router)#network 192.168.1.0

R2(config-router)#end

R2#write

R2(config)#int e0/1

R2(config-if)#standby 1 ip 192.168.1.1

//檢視Standby資訊

R2#show standby

  <b>State is Active  //</b><b>狀态為活動狀态</b>

    2 state changes, last state change 00:06:11

    Next hello sent in 0.148 secs

  Active router is local

  Standby router is 192.168.1.2, priority 100 (expires in 7.316 sec)

R2#

【測試】

HSRP的目的是提高系統的可靠性,我們關掉一個端口,模拟網絡出現故障,來看一下能否正常通信。關掉之前我們先來測試一下PC到100.1.1.1之間能否正常通信

現在我們斷開R2的E0/1,因為剛才的R2是active,也就是我們的資料是從R2經過的。

R2(config-if)#shu

R2(config-if)#shutdown 

觀察一下standby的資訊

<b>  State is Active //</b><b>狀态由standby</b><b>轉換為active</b>

    4 state changes, last state change 00:00:22

  Virtual IP address is 192.168.1.1

    Next hello sent in 1.068 secs

  Standby router is unknown

再次用PC去Ping 100.1.1.1

C:\Users\Five&gt;ping 100.1.1.1

正在 Ping 100.1.1.1 具有 32 位元組的資料:

來自 100.1.1.1 的回複: 位元組=32 時間=95ms TTL=254

來自 100.1.1.1 的回複: 位元組=32 時間=63ms TTL=254

來自 100.1.1.1 的回複: 位元組=32 時間=79ms TTL=254

來自 100.1.1.1 的回複: 位元組=32 時間=125ms TTL=254

100.1.1.1 的 Ping 統計資訊:

    資料包: 已發送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),

往返行程的估計時間(以毫秒為機關):

    最短 = 63ms,最長 = 125ms,平均 = 90ms

C:\Users\Five&gt;

發現依然可以Ping通,也就是說,系統自動為我們轉換了網關,但是整個過程對使用者來說确實透明的。這就是HSRP最大的好處。管理者可以及時修複出故障的端口,而不影響網絡的正常運作。

本文轉自 Jhuster 51CTO部落格,原文連結:http://blog.51cto.com/xwnet/170056,如需轉載請自行聯系原作者