问题
以三层交换机代替路由器作为网关设备。
方案
以三层交换机代替路由器作为网关设备,以vlan1作为网关接口
步骤
1.分别为三层交换机和路由器配置IP并开启三层交换机路由功能
SM1(config)#ip routing
SM1(config)#interface vlan 1
SM1(config-if)#ip address 192.168.1.252 255.255.255.0
SM1(config-if)#no shutdown
SM1(config-if)#eixt
SM1(config)#interface fastEthernet 0/1
SM1(config-if)#no switchport
SM1(config-if)#ip address 192.168.2.1 255.255.255.0
SM1(config-if)#no shutdown
SM2(config)#ip routing
SM2(config)#interface vlan 1
SM2(config-if)#ip add 192.168.1.253 255.255.255.0
SM2(config-if)#no shutdown
SM2(config-if)#exit
SM2(config)#interface f0/1
SM2(config-if)#no switchport
SM2(config-if)#ip address 192.168.3.1 255.255.255.0
Router(config)#interface fastEthernet 0/0
Router(config-if)#ip address 192.168.2.2 255.255.255.0
Router(config-if)#no shutdown
Router(config-if)#exit
Router(config)#interface fastEthernet 0/1
Router(config-if)#ip address 192.168.3.2 255.255.255.0
Router(config-if)#no shutdown
Router(config-if)#exit
Router(config)#interface fastEthernet 1/0
Router(config-if)#ip address 192.168.4.254 255.255.255.0
Router(config-if)#no shutdown
2.在三层交换机和路由器上配置动态路由,在路由器上查看路由表
SM1(config)#router rip
SM1(config-router)#version 2
SM1(config-router)#no auto-summary
SM1(config-router)#network 192.168.1.0
SM1(config-router)#network 192.168.2.0
SM2(config)#router rip
SM2(config-router)#version 2
SM2(config-router)#no auto-summary
SM2(config-router)#network 192.168.1.0
SM2(config-router)#network 192.168.3.0
Router(config)#router rip
Router(config-router)#version 2
Router(config-router)#no auto-summary
Router(config-router)#network 192.168.2.0
Router(config-router)#network 192.168.3.0
Router(config-router)#network 192.168.4.0
Router#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:10, FastEthernet0/1
[120/1] via 192.168.2.1, 00:00:04, FastEthernet0/0
C 192.168.2.0/24 is directly connected, FastEthernet0/0
C 192.168.3.0/24 is directly connected, FastEthernet0/1
C 192.168.4.0/24 is directly connected, FastEthernet1/0
3.在三层交换机vlan1中配置虚拟网关并设置优先级和占先权
SM1(config)#interface vlan 1
SM1(config-if)#standby 1 ip 192.168.1.254
SM1(config-if)#standby 1 priority 200
SM1(config-if)#standby1 preemp
%HSRP-6-STATECHANGE: Vlan1 Grp 1 state Speak -> Standby
%HSRP-6-STATECHANGE: Vlan1 Grp 1 state Standby -> Active
SM2(config)#interface vlan 1
SM2(config-if)#standby 1 ip 192.168.1.254
%HSRP-6-STATECHANGE: Vlan1 Grp 1 state Speak -> Standby
SM2(config-if)#standby 1 priority 195
SM2(config-if)#standby 1 preempt
4.在三层交换机vlan1中配置端口跟踪,关闭被跟踪接口并查看SM1的HSRP状态
当三层交换机SM1并没有故障,而是上连端口f0/1接口线路损坏时主备无法快速切换,所以要在主设备上配置端口跟踪,确保当主设备线路出现问题时备份设备可以快速切换身份
SM1(config)#interface vlan 1
SM1(config-if)#standby 1 track f0/1
SM1(config)#interface f0/1
SM1(config-if)#shutdown
SM1(config-if)#end
SM1#show standby brief
P indicates configured to preempt.
Interface Grp Pri P State Active Standby Virtual IP
Vl1 1 1 190 P Standby 192.168.1.253 local 192.168.1.254
5.测试网路连通性
模拟主设备故障或被跟踪的端口故障时测试网络的连通性,确保备份设备被启用
server>ping 192.168.4.1
Pinging 192.168.4.1 with 32 bytes of data:
Reply from 192.168.4.1: bytes=32 time=1ms TTL=126
Reply from 192.168.4.1: bytes=32 time=1ms TTL=126
Reply from 192.168.4.1: bytes=32 time=14ms TTL=126
Reply from 192.168.4.1: bytes=32 time=15ms TTL=126
Ping statistics for 192.168.4.1:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 1ms, Maximum = 15ms, Average = 7ms