【實(shí)驗(yàn)環(huán)境】
C3640-IK9O3S-M Version 12.4(10) + NM-16ESW模塊
【實(shí)驗(yàn)?zāi)康摹?/span>
通過多組的HSRP實(shí)現(xiàn)網(wǎng)關(guān)的自動(dòng)切換和負(fù)載分擔(dān)。正常情況下R1作為VLAN 100的網(wǎng)關(guān),R2作為VLAN 200的網(wǎng)關(guān),以此作為負(fù)載分擔(dān),當(dāng)上行鏈路或者下行鏈路Down掉之后,自動(dòng)切換到備份網(wǎng)關(guān),如果之前的鏈路恢復(fù),則自動(dòng)恢復(fù)原網(wǎng)關(guān)。
【實(shí)驗(yàn)拓?fù)洹?/span>
【實(shí)驗(yàn)描述】
1、SW1使用3640+NM-16ESW模塊模擬交換機(jī),關(guān)閉路由功能,只作為2層交換機(jī)使用,將f0/3和f0/4分別加入VLAN 100和VLAN 200,f0/1和f0/2配置為trunk端口
2、PC1使用虛擬網(wǎng)關(guān)192.168.1.254,PC2使用虛擬網(wǎng)關(guān)192.168.2.254
3、為了保證VLAN間通信,在R1和R2上使用單臂路由技術(shù)
4、為了保證實(shí)驗(yàn)結(jié)果不會(huì)因?yàn)镮GP影響,因此在R1和R2上使用NAPT技術(shù)將私有IP地址轉(zhuǎn)換為公網(wǎng)IP地址,所有路由器上均不配置IGP。在R1和R2上配置默認(rèn)路由即可
5、在R1和R2上配置HSRP熱備份協(xié)議
【實(shí)驗(yàn)步驟】
1、使用VPCS配置PC1和PC2
PC1: ip 192.168.1.100/24 192.168.1.254
PC2: ip 192.168.2.200/24 192.168.2.254
2、配置SW1
使用GNS3創(chuàng)建VLAN時(shí)需要在VLAN database模式下,記得最后要"exit"應(yīng)用配置
SW1#vlan database
SW1(vlan)#vlan 100
VLAN 500 added:
Name: VLAN0100
SW1(vlan)#vlan 200
VLAN 600 added:
Name: VLAN0200
SW1(vlan)#exit
APPLY completed.
Exiting....
SW1#
將端口劃入相應(yīng)VLAN
!
interface FastEthernet0/1
switchport mode trunk
!
interface FastEthernet0/2
switchport mode trunk
!
interface FastEthernet0/3
switchport access vlan 100
!
interface FastEthernet0/4
switchport access vlan 200
!
3、配置R3
!
interface Loopback0
ip address 3.3.3.3 255.255.255.255
!
interface FastEthernet0/0
ip address 13.1.1.3 255.255.255.0
!
interface FastEthernet1/0
ip address 23.1.1.3 255.255.255.0
!
4、配置R1的端口、單臂路由
R1(config)#interface FastEthernet0/0
R1(config-if)#no shutdown
R1(config-if)#interface FastEthernet0/0.1
R1(config-if)#encapsulation dot1Q 100
R1(config-if)#ip address 192.168.1.1 255.255.255.0
R1(config-if)#interface FastEthernet0/0.2
R1(config-if)#encapsulation dot1Q 200
R1(config-if)#ip address 192.168.2.1 255.255.255.0
R1(config-if)#interface FastEthernet1/0
R1(config-if)#ip address 13.1.1.1 255.255.255.0
R1(config-if)#no shutdown
5、配置R2的端口、單臂路由
R2(config)#interface FastEthernet0/0
R2(config-if)#no shutdown
R2(config-if)#interface FastEthernet0/0.1
R2(config-if)#encapsulation dot1Q 100
R2(config-if)#ip address 192.168.1.2 255.255.255.0
R2(config-if)#interface FastEthernet0/0.2
R2(config-if)#encapsulation dot1Q 200
R2(config-if)#ip address 192.168.2.2 255.255.255.0
R2(config-if)#interface FastEthernet1/0
R2(config-if)#ip address 23.1.1.2 255.255.255.0
R2(config-if)#no shutdown
6、在R1上配置NAPT和默認(rèn)路由
R1(config)#access-list 11 permit 192.168.1.0 0.0.0.255
R1(config)#access-list 11 permit 192.168.2.0 0.0.0.255
R1(config)#ip nat inside source list 11 interface FastEthernet1/0 overload
R1(config)#interface FastEthernet0/0.1
R1(config-if)#ip nat inside
R1(config-if)#interface FastEthernet0/0.2
R1(config-if)#ip nat inside
R1(config-if)#interface FastEthernet1/0
R1(config-if)#ip nat outside
R1(config-if)#exit
R1(config)#ip route 0.0.0.0 0.0.0.0 13.1.1.3
7、在R2上配置NAPT和默認(rèn)路由
R2(config)#access-list 22 permit 192.168.1.0 0.0.0.255
R2(config)#access-list 22 permit 192.168.2.0 0.0.0.255
R2(config)#ip nat inside source list 22 interface FastEthernet1/0 overload
R2(config)#interface FastEthernet0/0.1
R2(config-if)#ip nat inside
R2(config-if)#interface FastEthernet0/0.2
R2(config-if)#ip nat inside
R2(config-if)#interface FastEthernet1/0
R2(config-if)#ip nat outside
R2(config-if)#exit
R2(config)#ip route 0.0.0.0 0.0.0.0 23.1.1.3
8、在R1上配置HSRP,使得VLAN 100優(yōu)先走R1
R1(config)#interface FastEthernet0/0.1
R1(config-if)#standby 1 ip 192.168.1.254 //配置組1,虛擬網(wǎng)關(guān)192.168.1.254
R1(config-if)#standby 1 priority 105 //將優(yōu)先級(jí)從默認(rèn)的100提高到105
R1(config-if)#standby 1 preempt //配置搶占模式
R1(config-if)#standby 1 track FastEthernet1/0 //配置上行鏈路跟蹤,一旦down掉默認(rèn)將優(yōu)先級(jí)降低10,后面可跟數(shù)字自定義
R1(config-if)#interface FastEthernet0/0.2
R1(config-if)#standby 2 ip 192.168.2.254 //配置組2,虛擬網(wǎng)關(guān)192.168.2.254
R1(config-if)#standby 2 preempt //配置搶占模式
//組2沒有配置優(yōu)先級(jí)和跟蹤,因?yàn)榻M2只是作為備份,默認(rèn)優(yōu)先級(jí)為100,就算上行鏈路不down,也比R2上的組2優(yōu)先級(jí)低,因此也不需要track
9、在R2上配置HSRP,使得VLAN 200優(yōu)先走R2
R2(config)#interface FastEthernet0/0.1
R2(config-if)#standby 1 ip 192.168.1.254
R2(config-if)#standby 1 preempt
R2(config-if)#interface FastEthernet0/0.2
R2(config-if)#standby priority 105
R2(config-if)#standby 2 ip 192.168.2.254
R2(config-if)#standby 2 priority 105
R2(config-if)#standby 2 preempt
R2(config-if)#standby 2 track FastEthernet1/0
//道理同R1,不解釋了。組1在R1上優(yōu)先級(jí)高,組2在R2上優(yōu)先級(jí)高,只要他們各自的鏈路是up的,就一定可以保證是Active
10、在R1上查看HSRP,發(fā)現(xiàn)組1為Active,組2為Standby,正確
R1#sh standby brief
Interface Grp Prio P State Active Standby Virtual IP
Fa0/0.1 1 105 P Active local 192.168.1.2 192.168.1.254
Fa0/0.2 2 100 P Standby 192.168.2.2 local 192.168.2.254
11、在R2上查看HSRP,發(fā)現(xiàn)組1為Standby,組2為Active,正確
R2#sh standby brief
Interface Grp Prio P State Active Standby Virtual IP
Fa0/0.1 1 100 P Standby 192.168.1.1 local 192.168.1.254
Fa0/0.2 2 105 P Active local 192.168.2.1 192.168.2.254
12、在PC1上驗(yàn)證鏈路沒有down時(shí)的tracert
VPCS[1]> tracert 3.3.3.3
1 192.168.1.1 20.000 ms 11.000 ms 11.000 ms
2 *13.1.1.3 77.000 ms (ICMP type:3, code:3, Destination port unreachable)
可以看到選擇的是R1
13、在PC2上驗(yàn)證鏈路沒有down時(shí)的tracert
VPCS[2]> tracert 3.3.3.3
1 192.168.2.2 29.000 ms 29.000 ms 9.000 ms
2 *23.1.1.3 84.000 ms (ICMP type:3, code:3, Destination port unreachable)
可以看到選擇的是R2,這樣就實(shí)現(xiàn)了負(fù)載分擔(dān)
14、在PC1上觀察當(dāng)R1下行鏈路down掉時(shí)的熱備份切換(這里down掉R1的f0/0.1接口)
結(jié)果不看了,持續(xù)ping一點(diǎn)停頓都沒有,一個(gè)包都沒掉,平滑過度到R2上了...
15、在PC1上觀察當(dāng)R1上行鏈路down掉時(shí)的熱備份切換(這里down掉R1的f1/0接口)
VPCS[1]> ping 3.3.3.3 -t
3.3.3.3 icmp_seq=1 ttl=254 time=56.000 ms
3.3.3.3 icmp_seq=2 ttl=254 time=68.000 ms
3.3.3.3 icmp_seq=3 timeout //shutdown以后
3.3.3.3 icmp_seq=4 ttl=254 time=136.000 ms
3.3.3.3 icmp_seq=5 ttl=254 time=52.000 ms
3.3.3.3 icmp_seq=6 ttl=254 time=51.000 ms
3.3.3.3 icmp_seq=7 timeout //no shutdown以后
3.3.3.3 icmp_seq=8 ttl=254 time=59.000 ms
3.3.3.3 icmp_seq=9 ttl=254 time=50.000 ms
可以看到在down/up之間分別掉了1個(gè)包,效果非常好。熱備份生效時(shí)R1和R2上的HSRP狀態(tài)如下,R1的優(yōu)先級(jí)降低了10,并且Standby了,R2都是Active了,當(dāng)R1的鏈路恢復(fù)時(shí),又會(huì)搶占回來。
R1#sh stan bri
Interface Grp Prio P State Active Standby Virtual IP
Fa0/0.1 1 95 P Standby 192.168.1.2 local 192.168.1.254
Fa0/0.2 2 100 P Standby 192.168.2.2 local 192.168.2.254
R2#sh stan bri
Interface Grp Prio P State Active Standby Virtual IP
Fa0/0.1 1 100 P Active local unknown 192.168.1.254
Fa0/0.2 2 105 P Active local 192.168.2.1 192.168.2.254
到這里實(shí)驗(yàn)就完成了。