配置直连路由联动VRRP状态示例
配置直连路由联动VRRP状态,可以防止经过VRRP备份组的上下行流量路径出现不一致。
组网需求
如图2-10所示,将Device1与Device2构成的VRRP备份组作为用户侧网关,用户访问网络的上行流量将发往VRRP主用设备Device1。同时,Device1、Device2和Device3之间运行OSPF协议以实现IP层互通。由网络返回到用户的下行流量路径将由OSPF选路决定。在本例中,Device3上存在去往用户网段10.1.1.0/24的两条等价OSPF路由,因此下行流量将出现负载分担的情况。这样就导致了上下行流量路径不一致。
为了解决上述问题,可以在Device1和Device2运行VRRP的接口下配置直连路由与VRRP状态联动,使VRRP的虚IP网段直连路由cost值增大;然后将该直连路由引入到OSPF协议中,并配置OSPF在引入外部路由时继承cost值。此时,由于经过Device1的OSPF路由cost值更小,所以Device3将优选该路由来指导下行流量的转发,从而实现上下行流量路径保持一致。
配置思路
采用如下的思路配置直连路由联动VRRP状态:
在Device1和Device2上配置VRRP备份组。
在Device1、Device2和Device3上配置OSPF,实现IP路由互通。
在Device1和Device2上配置直连路由与VRRP联动。
在Device1和Device2上配置OSPF引入直连路由,并配置继承cost。
数据准备
为完成此配置例,需准备如下的数据:
Switch上创建VLAN的编号为10。
VRRP备份组编号vrid为1、虚拟IP地址virtual-ip为10.1.1.111。
Device1在备份组中优先级为120。
VRRP的虚IP网段直连路由的cost值degrade-cost为300。
操作步骤
- 配置各接口的IP地址,请参见配置文件
- 配置VRRP备份组
# 在Switch上创建VLAN 10,并将接口GE0/1/0和GE0/1/1加入该VLAN,以便透传Device1、Device2发送的VRRP报文。
<Switch> system-view
[~Switch] interface gigabitethernet 0/1/0
[~Switch-GigabitEthernet0/1/0] portswitch
[*Switch-GigabitEthernet0/1/0] commit
[*Switch-GigabitEthernet0/1/0] quit
[*Switch] interface gigabitethernet 0/1/1
[~Switch-GigabitEthernet0/1/1] portswitch
[*Switch-GigabitEthernet0/1/1] commit
[~Switch-GigabitEthernet0/1/1] quit
[*Switch] vlan 10
[*Switch-vlan10] port gigabitethernet 0/1/0
[*Switch-vlan10] port gigabitethernet 0/1/0
[*Switch-vlan10] commit
[~Switch-vlan10] quit
# 在Device1上创建VRRP备份组1,并配置Device1在该备份组中的优先级为120(作为主用设备)。
<Device1> system-view
[~Device1] interface gigabitethernet 0/1/0
[*Device1-GigabitEthernet0/1/0] vrrp vrid 1 virtual-ip 10.1.1.111
[*Device1-GigabitEthernet0/1/0] vrrp vrid 1 priority 120
[*Device1-GigabitEthernet0/1/0] commit
[~Device1-GigabitEthernet0/1/0] quit
# 在Device2上创建VRRP备份组1。
<Device2> system-view
[~Device2] interface gigabitethernet 0/1/0
[*Device2-GigabitEthernet0/1/0] vrrp vrid 1 virtual-ip 10.1.1.111
[*Device2-GigabitEthernet0/1/0] commit
[~Device2-GigabitEthernet0/1/0] quit
- 配置OSPF
# 在Device1上配置OSPF协议。
[~Device1] ospf 1
[*Device1-ospf-1] area 0
[*Device1-ospf-1-area-0.0.0.0] network 10.1.3.0 0.0.0.255
[*Device1-ospf-1-area-0.0.0.0] commit
[~Device1-ospf-1-area-0.0.0.0] quit
[~Device1-ospf-1] quit
# 在Device2上配置OSPF协议。
[~Device2] ospf 1
[*Device2-ospf-1] area 0
[*Device2-ospf-1-area-0.0.0.0] network 10.1.2.0 0.0.0.255
[*Device2-ospf-1-area-0.0.0.0] commit
[~Device2-ospf-1-area-0.0.0.0] quit
[~Device2-ospf-1] quit
# 在Device3上配置OSPF协议。
<Device3> system-view
[~Device3] ospf 1
[*Device3-ospf-1] area 0
[*Device3-ospf-1-area-0.0.0.0] network 10.1.2.0 0.0.0.255
[*Device3-ospf-1-area-0.0.0.0] network 10.1.3.0 0.0.0.255
[*Device3-ospf-1-area-0.0.0.0] commit
[~Device3-ospf-1-area-0.0.0.0] quit
[~Device3-ospf-1] quit
- 配置直连路由与VRRP联动
# 配置Device1。
[~Device1] interface gigabitethernet 0/1/0
[*Device1-GigabitEthernet0/1/0] direct-route track vrrp vrid 1 degrade-cost 300
[*Device1-GigabitEthernet0/1/0] commit
[~Device1-GigabitEthernet0/1/0] quit
# 配置Device2。
[~Device2] interface gigabitethernet 0/1/0
[*Device2-GigabitEthernet0/1/0] direct-route track vrrp vrid 1 degrade-cost 300
[*Device2-GigabitEthernet0/1/0] commit
[~Device2-GigabitEthernet0/1/0] quit
- 配置OSPF引入直连路由
# 配置Device1。
[~Device1] ospf 1
[*Device1-ospf-1] import-route direct
[*Device1-ospf-1] default cost inherit-metric
[*Device1-ospf-1] commit
[~Device1-ospf-1] quit
# 配置Device2。
[~Device2] ospf 1
[*Device2-ospf-1] import-route direct
[*Device2-ospf-1] default cost inherit-metric
[*Device2-ospf-1] commit
[~Device2-ospf-1] quit
- 检查配置结果
# 在Device2上使用display ip routing-talbe命令查看IP路由表信息,可以看到VRRP的虚IP网段直连路由的cost值被置为300。
<Device2> display ip routing-table
Route Flags: R - relay, D - download to fib, T - to vpn-instance, B - black hole route ------------------------------------------------------------------------------ Routing Table : _public_ Destinations : 12 Routes : 12 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.1.1.0/24 Direct 0 300 D 10.1.1.2 GigabitEthernet0/1/0 10.1.1.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/1/0 10.1.1.111/32 O_ASE 150 0 D 10.1.2.2 GigabitEthernet0/1/1 10.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/1/0 10.1.2.0/24 Direct 0 0 D 10.1.2.1 GigabitEthernet0/1/1 10.1.2.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/1/1 10.1.2.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/1/1 10.1.3.0/24 OSPF 10 2 D 10.1.2.2 GigabitEthernet0/1/1 127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0 127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
# 在Device3上执行display ip routing-table 10.1.1.0命令,查看去往用户所在网段的路由信息,可以看到Device3为发往用户的下行流量选择了下一跳为10.1.3.1的路由,即经过VRRP主用设备Device1的路由。
<Device3> display ip routing-table 10.1.1.0
Route Flags: R - relay, D - download to fib, T - to vpn-instance, B - black hole route ------------------------------------------------------------------------------ Routing Table : _public_ Summary Count : 1 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.1.1.0/24 O_ASE 150 0 D 10.1.3.1 GigabitEthernet0/1/0
配置文件
Switch的配置文件
# sysname Switch # vlan batch 10 # interface GigabitEthernet0/1/0 portswitch undo shutdown port default vlan 10 # interface GigabitEthernet0/1/1 portswitch undo shutdown port default vlan 10 #
Device1的配置文件
# sysname Device1 # interface GigabitEthernet0/1/0 undo shutdown ip address 10.1.1.1 255.255.255.0 vrrp vrid 1 virtual-ip 10.1.1.111 vrrp vrid 1 priority 120 direct-route track vrrp vrid 1 degrade-cost 300 # interface GigabitEthernet0/1/1 undo shutdown ip address 10.1.3.1 255.255.255.0 # ospf 1 default cost inherit-metric import-route direct area 0.0.0.0 network 10.1.3.0 0.0.0.255 #
Device2的配置文件
# sysname Device2 # interface GigabitEthernet0/1/0 undo shutdown ip address 10.1.1.2 255.255.255.0 vrrp vrid 1 virtual-ip 10.1.1.111 direct-route track vrrp vrid 1 degrade-cost 300 # interface GigabitEthernet0/1/1 undo shutdown ip address 10.1.2.1 255.255.255.0 # ospf 1 default cost inherit-metric import-route direct area 0.0.0.0 network 10.1.2.0 0.0.0.255 #
Device3的配置文件
# sysname Device3 # interface GigabitEthernet0/1/0 undo shutdown ip address 10.1.3.2 255.255.255.0 # interface GigabitEthernet0/1/1 undo shutdown ip address 10.1.2.2 255.255.255.0 # ospf 1 area 0.0.0.0 network 10.1.2.0 0.0.0.255 network 10.1.3.0 0.0.0.255 #