拓扑图如上,该实验需要实现LSW3和LSW4互为vlan2和vlan3的主网关,且做到热机互备,另外需要实现vlan2通过R1去AR1,vlan3通过R2去AR1。
一、二层配置
1.vlan的创建及将接口划入相应的vlan
LSW1
vlan batch 2 to 3
interface GigabitEthernet0/0/3
[s1-GigabitEthernet0/0/3] port link-type access
port default vlan 2
stp edged-port enable
interface GigabitEthernet0/0/4
[s1-GigabitEthernet0/0/3] port link-type access
port default vlan 3
stp edged-port enable
LSW2
interface GigabitEthernet0/0/3
[s1-GigabitEthernet0/0/3] port link-type access
port default vlan 2
stp edged-port enable
interface GigabitEthernet0/0/4
[s1-GigabitEthernet0/0/3] port link-type access
port default vlan 3
stp edged-port enable
2.干道及链路聚合
[s1]interface g0/0/1
port link-type trunk
port trunk allow-pass vlan 2 to 3
[s1]interface g0/0/2
port link-type trunk
port trunk allow-pass vlan 2 to 3
[s2]interface g0/0/1
port link-type trunk
port trunk allow-pass vlan 2 to 3
[s2]interface g0/0/2
port link-type trunk
port trunk allow-pass vlan 2 to 3
LSW3
[s3]interface Eth-Trunk 0
[s3-Eth-Trunk0]trunkport g0/0/1
[s3-Eth-Trunk0]trunkport g0/0/2
port link-type trunk
port trunk allow-pass vlan 2 to 3
LSW4
[s4]interface Eth-Trunk 0
[s4-Eth-Trunk0]trunkport g0/0/1
[s4-Eth-Trunk0]trunkport g0/0/2
port link-type trunk
port trunk allow-pass vlan 2 to 3
3.生成树
LSW3
[s3]stp enable
[s3]stp region-configuration
region-name HW
revision-level 1
instance 1 vlan 2
instance 2 vlan 3
active region-configuration
stp instance 0 priority 0
stp instance 1 priority 0
stp instance 2 priority 4096
LSW4
[s4]stp enable
[s4]stp region-configuration
region-name HW
revision-level 1
instance 1 vlan 2
instance 2 vlan 3
active region-configuration
stp instance 1 priority 4096
stp instance 2 priority 0
结果是LSW3是vlan 2 的主根,vlan 3的备份根;LSW4是vlan 3的主根,vlan 2 的备份根
二、三层网关互备
LSW3
[s3]interface Vlanif 2//交换机无三层口,用svi充当
ip address 192.168.2.1 255.255.255.0
vrrp vrid 1 virtual-ip 192.168.2.254
vrrp vrid 1 priority 120
vrrp vrid 1 preempt-mode timer delay 3
vrrp vrid 1 track interface GigabitEthernet0/0/5 reduced 30
[s3]interface Vlanif 3
ip address 192.168.3.1 255.255.255.0
vrrp vrid 1 virtual-ip 192.168.3.254
LSW4
[s4]interface Vlanif 3//交换机无三层口,用svi充当
ip address 192.168.3.2 255.255.255.0
vrrp vrid 1 virtual-ip 192.168.3.254
vrrp vrid 1 priority 120
vrrp vrid 1 preempt-mode timer delay 3
vrrp vrid 1 track interface GigabitEthernet0/0/5 reduced 30
[s3]interface Vlanif 2
ip address 192.168.2.2 255.255.255.0
vrrp vrid 1 virtual-ip 192.168.2.254
这样做的目的可以让LSW3成为vlan 2 的主网关,vlan 3 的备份网关;LSW4 成为vlan 3的主网关,vlan 2的备份网关
三、路由协议
R1
[r1]ospf 1
area 0.0.0.0
network 192.168.100.0 0.0.0.255
network 192.168.2.0 0.0.0.255
network 192.168.104.0 0.0.0.255
network 192.168.3.0 0.0.0.255
network 192.168.5.0 0.0.0.255
R2
[r2]ospf 1
area 0.0.0.0
network 192.168.101.0 0.0.0.255
network 192.168.2.0 0.0.0.255
network 192.168.3.0 0.0.0.255
network 192.168.102.0 0.0.0.255
network 192.168.4.0 0.0.0.255
AR1
[AR1]ospf 1
ospf 1 router-id 3.3.3.3
area 0.0.0.0
network 3.3.3.3 0.0.0.0
network 192.168.4.0 0.0.0.255
network 192.168.5.0 0.0.0.255
四、隔离及互联
1.隔离
要达到vlan 2 去AR1走R1 ;vlan 3 去AR1走R2,不隔离是做不到的,因为两者的目标相同。隔离顾名思义就是在逻辑上把vlan 2 和vlan 3的路由隔开,二者相互不可见,只有通过中间的心跳线才能进行路由的相互传递,使用隔离可以满足上述需求。
LSW3
ip vpn-instance VLAN2
ipv4-family
route-distinguisher 1:1
ip vpn-instance VLAN3
ipv4-family
route-distinguisher 2:2(创建两个vrf进行隔离)
ospf 1 router-id 1.1.1.1 vpn-instance VLAN2
area 0.0.0.0
network 192.168.100.0 0.0.0.255
area 0.0.0.1
network 192.168.2.0 0.0.0.255
把vlanif 100 和vlanif 2 也绑定在 vpn-instance VLAN2中
路由表如下
同理,创建一个vpn instance VLAN3,绑定相应的svi口,创建一个新的ospf进程,可得到关于vpn instance VLAN3的路由表
LSW4
ip vpn-instance VLAN2
ipv4-family
route-distinguisher 1:1
ip vpn-instance VLAN3
ipv4-family
route-distinguisher 2:2(创建两个vrf进行隔离)
ospf 2 router-id 2.2.2.2 vpn-instance VLAN3
area 0.0.0.0
network 192.168.101.0 0.0.0.255
area 0.0.0.1
network 192.168.3.0 0.0.0.255
绑定vlanif101和vlanif3
路由表如下
同理,创建一个vpn instance VLAN2,绑定相应的svi口,创建一个新的ospf进程,可得到关于vpn instance VLAN2的路由表
2.互联
虽然vlan 2 和vlan 3的路线不可共享,但是可以在心跳线中创一个互联的svi进行vlan间路由传递,这样做的目的是为了防止R1上链路发生故障时vlan 2 无路可走的情况
具体做法如下
在LSW3和LSW4中创建一个新的vlan,并在LSW3中将该vlan划入vpn instance VLAN2,在LSW4中将该vlan划入vpn instance VLAN3.
LSW3
vlan 112
interface Eth-Trunk0
port trunk allow-pass vlan 112
interface Vlanif112
ip binding vpn-instance VLAN2
ip address 192.168.112.1 255.255.255.0
ospf cost 1000//正常情况不会走心跳线
ospf enable 1 area 0.0.0.0
LSW4
interface Eth-Trunk0
port trunk allow-pass vlan 112
interface Vlanif112
ip binding vpn-instance VLAN3
ip address 192.168.112.2 255.255.255.0
ospf cost 1000
ospf enable 2 area 0.0.0.0
五、测试
1.正常情况
vlan 2走左边
vlan 3 走右边
2.LSW3上行链路故障,以vlan 2 为例(切网关)
3.R1上行链路故障,由于做了互联,所以会走心跳线