大学回顾复习-网络知识
HSRP-思科专有的热备份路由协议 (过一段时间不看不敲命令,还真的会忘记)
做个试验,动手敲命令,抓包看看试验
比如。。。内网DMZ区域有一台服务器,是某个公司的对我官方网站所在的服务器,外边有位客户想访问该公司的官方服务器(内网里的其他设施均已隐藏,这样看起来更直观)
先配置IP地址,再采用默认路由,静态路由,或者路由协议 RIP或者OSPF让网络互通
最后再弄HSRP,我这边直接弄RIP,再HSRP
刚刚搭建起来什么命令都没有敲,但是始终有一个个起不来,那是因为交换机默认的STP协议起了作用,阻塞一个端口防止环路生成
先配置好IP地址
Switch>enable
Switch#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#interface FastEthernet0/2
Switch(config-if)#no switchport
Switch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to up
Switch(config-if)#
Switch(config-if)#ip address 192.168.2.1 255.255.255.0
Switch(config-if)#no shutdown
Switch(config-if)#end
Switch#
%SYS-5-CONFIG_I: Configured from console by console
Switch#write
Building configuration...
[OK]
Switch#
Switch#
Switch#
Switch#
Switch#CONF T
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#hostname sw1
sw1(config)#
Switch#
Switch#CONF T
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#hostname sw1
sw1(config)#
sw1(config)#
sw1(config)#
sw1(config)#interface FastEthernet0/2
sw1(config-if)#
sw1(config-if)#exit
sw1(config)#interface FastEthernet0/1
sw1(config-if)#no sw
sw1(config-if)#no switchport
sw1(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
sw1(config-if)#ip add 192.168.1.252 255.255.255.0
sw1(config-if)#no shutdown
sw1(config-if)#
接着是switch2
Switch(config)#hostname sw2
sw2(config)#
sw2(config)#interface FastEthernet0/1
sw2(config-if)#
sw2(config-if)#exit
sw2(config)#interface FastEthernet0/1
sw2(config-if)#no switchport
sw2(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
sw2(config-if)#
sw2(config-if)#ip add 192.168.1.253 255.255.255.0
sw2(config-if)#no shutdown
sw2(config-if)#
sw2(config-if)#exit
sw2(config)#interface FastEthernet0/1
sw2(config-if)#exit
sw2(config)#interface fa
sw2(config)#interface fastEthernet 0/2
sw2(config-if)#no sw
sw2(config-if)#no switchport
sw2(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to up
sw2(config-if)#ip add 192.168.3.1 255.255.255.0
sw2(config-if)#no shutd
sw2(config-if)#no shutdown
sw2(config-if)#end
sw2#
%SYS-5-CONFIG_I: Configured from console by console
write
Building configuration...
[OK]
sw2#
接下来是sw3
Switch>enable
Switch#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#interface FastEthernet0/1
Switch(config-if)#ex
Switch(config)#hostname sw3
sw3(config)#
sw3(config)#interface FastEthernet0/1
sw3(config-if)#
sw3(config-if)#exit
sw3(config)#interface FastEthernet0/1
sw3(config-if)#no sw
sw3(config-if)#no switchport
sw3(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
sw3(config-if)#ip add 192.168.2.2 255.255.255.0
sw3(config-if)#no shut
sw3(config-if)#no shutdown
sw3(config-if)#
sw3(config-if)#exit
sw3(config)#interface FastEthernet0/1
sw3(config-if)#
sw3(config-if)#exit
sw3(config)#interface FastEthernet0/2
sw3(config-if)#no sw
sw3(config-if)#no switchport
sw3(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to up
sw3(config-if)#
sw3(config-if)#ip add 192.168.3.2 255.255.255.0
sw3(config-if)#no shut
sw3(config-if)#no shutdown
sw3(config-if)#ex
sw3(config)#inter
sw3(config)#interface fa
sw3(config)#interface fastEthernet 0/3
sw3(config-if)#no sw
sw3(config-if)#no switchport
sw3(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to up
sw3(config-if)#
sw3(config-if)#ip add 192.168.4.254 255.255.255.0
sw3(config-if)#no sh
sw3(config-if)#no shutdown
sw3(config-if)#end
sw3#
%SYS-5-CONFIG_I: Configured from console by console
sw3#
sw3#write
Building configuration...
[OK]
sw3#
接着是配置路由协议
sw1(config)#router rip
sw1(config-router)#vers
sw1(config-router)#version 2
sw1(config-router)#no auto-sumarry
^
% Invalid input detected at '^' marker.
sw1(config-router)#no auto-summary
sw1(config-router)#network 192.168.1.0
sw1(config-router)#network
sw1(config-router)#network 192.168.2.0
sw1(config-router)#
sw1(config-router)#end
sw1#
%SYS-5-CONFIG_I: Configured from console by console
sw1#
sw1#write
Building configuration...
[OK]
sw1#
sw2>
sw2>enable
sw2#conf t
Enter configuration commands, one per line. End with CNTL/Z.
sw2(config)#
sw2(config)#
sw2(config)#router
sw2(config)#router rip
IP routing not enabled
sw2(config)#ip routing
sw2(config)#router rip
sw2(config-router)#version 2
sw2(config-router)#no auto-summary
sw2(config-router)#network 192.168.1.0
sw2(config-router)#net
sw2(config-router)#network 192.168.3.0
sw2(config-router)#end
sw2#
%SYS-5-CONFIG_I: Configured from console by console
sw2#write
Building configuration...
[OK]
sw2#
sw3>
sw3>
sw3>enable
sw3#conf t
Enter configuration commands, one per line. End with CNTL/Z.
sw3(config)#ip routing
sw3(config)#router rip
sw3(config-router)#version 2
sw3(config-router)#no auto-summary
sw3(config-router)#neot
sw3(config-router)#network 192.168.2.0
sw3(config-router)#network 192.168.3.0
sw3(config-router)#network 192.168.4.0
sw3(config-router)#end
sw3#
%SYS-5-CONFIG_I: Configured from console by console
sw3#
sw3#write
Building configuration...
[OK]
sw3#
接着在三层设备上show ip router
sw3#show ip route
sw3#show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
Gateway of last resort is not set
R 192.168.1.0/24 [120/1] via 192.168.3.1, 00:00:02, FastEthernet0/2
[120/1] via 192.168.2.1, 00:00:09, FastEthernet0/1
C 192.168.2.0/24 is directly connected, FastEthernet0/1
C 192.168.3.0/24 is directly connected, FastEthernet0/2
C 192.168.4.0/24 is directly connected, FastEthernet0/3
sw3#
sw1#show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
Gateway of last resort is not set
C 192.168.1.0/24 is directly connected, FastEthernet0/1
C 192.168.2.0/24 is directly connected, FastEthernet0/2
R 192.168.3.0/24 [120/1] via 192.168.1.253, 00:00:18, FastEthernet0/1
[120/1] via 192.168.2.2, 00:00:06, FastEthernet0/2
R 192.168.4.0/24 [120/1] via 192.168.2.2, 00:00:06, FastEthernet0/2
sw2>
sw2>
sw2>enable
sw2#conf t
Enter configuration commands, one per line. End with CNTL/Z.
sw2(config)#
sw2(config)#
sw2(config)#router
sw2(config)#router rip
IP routing not enabled
sw2(config)#ip routing
sw2(config)#router rip
sw2(config-router)#version 2
sw2(config-router)#no auto-summary
sw2(config-router)#network 192.168.1.0
sw2(config-router)#net
sw2(config-router)#network 192.168.3.0
sw2(config-router)#end
sw2#
%SYS-5-CONFIG_I: Configured from console by console
sw2#write
Building configuration...
[OK]
sw2#
sw2#
sw2#show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
Gateway of last resort is not set
C 192.168.1.0/24 is directly connected, FastEthernet0/1
R 192.168.2.0/24 [120/1] via 192.168.1.252, 00:00:15, FastEthernet0/1
[120/1] via 192.168.3.2, 00:00:23, FastEthernet0/2
C 192.168.3.0/24 is directly connected, FastEthernet0/2
R 192.168.4.0/24 [120/1] via 192.168.3.2, 00:00:23, FastEthernet0/2
sw2#
C是直连路由 ,R是rip路由,O是ospf路由
接着测试网络是否互通
可以看到网络通了
接着配置HSRP
sw1(config)#interface FastEthernet0/1
sw1(config-if)#standby 1 ip 192.168.1.254
sw1(config-if)#standby 1 priority 200
sw1(config-if)#
%HSRP-6-STATECHANGE: FastEthernet0/1 Grp 1 state Speak -> Standby
%HSRP-6-STATECHANGE: FastEthernet0/1 Grp 1 state Standby -> Active
sw2>enable
sw2#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
sw2(config)#interface FastEthernet0/1
sw2(config-if)#standby 1 ip 192.168.1.254
sw2(config-if)#standby 1 prio
sw2(config-if)#standby 1 priority
%HSRP-6-STATECHANGE: FastEthernet0/1 Grp 1 stat
sw2(config-if)#standby 1 priority 195
sw2(config-if)#
分别在SW1和SW2上查看HSRP信息
sw1(config-if)#
sw1(config-if)#END
sw1#
%SYS-5-CONFIG_I: Configured from console by console
sw1#
sw1#show standby brief
P indicates configured to preempt.
|
Interface Grp Pri P State Active Standby Virtual IP
Fa0/1 1 200 Active local 192.168.1.253 192.168.1.254
sw1#
sw2(config-if)#exit
sw2(config)#do show standby brief
P indicates configured to preempt.
|
Interface Grp Pri P State Active Standby Virtual IP
Fa0/1 1 195 Standby 192.168.1.252 local 192.168.1.254
sw2(config)#
我们可以看到,一个虚拟路由器已经形成,虚拟IP 192.168.1.254 HSRP热备份组中的活动路由器是192.168.1.252 也就是SW1
接着,我们尝试访问webserver(192.168.1.1/24),看看是否起作用了,这里的web-server的网关就是192.168.1.254
我们可以看到已经互通了
接着我们来抓包(用192.168.4.1来ping一下web-server192.168.1.1这台服务器),看看数据是不是从sw1流过 (可以使用思科自带的,或者使用wireshark)
可以看到数据包流量确实是从sw1经过。
等到包到达server后,server再转发到二层交换机,看看二层交换机是怎么样转发的
我们可以看到,这个二层交换机视乎把SW1和SW2都当成了server的网关设备,即SW1和SW2组成的热备份虚拟路由器,而且,因为sw2是备份路由器,所以SW2默认会把包丢弃掉,只会让SW1这个活动路由器转发这个ICMP数据包
我们近距离来看看这个数据包的内容
源物理地址和IP地址都是对的上的
接着SW1转发给SW3,确实是只有SW1这一条路
当ICMP数据包到达PC0后,我们可以看到,对应的第三个ICMP回应包收到了
接着,我们来模拟活动路由器down掉的情况,看看备份路由器是不是会主动转变成为活动路由器
我们可以看到,数量流量是从SW2经过的,但是,SW2任然是备份,这是因为SW2没有配置占先权,而且SW1也没完全down,只是上游端口不通,但是SW1的优先级已经从200降到190了
所以,我们在SW2的fa0/1配置占先权,把SW1的fa0/2端口开起来,重新模拟(不把端口开起来,就算配置了占先权也没用,因为只有活跃路由器down掉才会重新选举)
我们可以看到活跃路由器已经成为备份路由器,而备份路由器已经变成活跃路由器
取消SW2接口的占先权,把SW1接口配置占先权,并且把fa0/2接口开启,可以看到又重新变回原来的样子了
接下来,我们两个SW都配置了占先权,我们来看看,再次模拟SW1的fa0/2接口down掉,看看活动路由器的选举是谁
我们可以看到SW2再次变为活动路由器了,而且SW1的priority从195再次减少变成190了,而SW2的优先级不变,还是195
总结: standby 1 preempt 占先权必须要配置,不然即使活跃路由器down掉,备份路由器也不会主动变成活跃路由器,都配置占先权的情况下,优先级高的成为活跃路由器