华为配置浮动路由和双向转发检测BFD(Bidirectional Forwarding Detection)
拓扑图
电脑配置
pc1:192.168.10.1/24
pc2:192.168.20.1/24
AR1路由器配置
配置4个接口的地址
ge0/0/0:192.168.10.254/24
ge0/0/1:192.168.20.254/24
ge0/0/2:12.1.1.1/30
ge4/0/0:13.1.1.1/30
<Huawei>system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]undo info-center enable
Info: Information center is disabled.
[Huawei]sysname AR1
[AR1]interface gigabitethernet 0/0/0
[AR1-GigabitEthernet0/0/0]ip address 192.168.10.254 24
[AR1-GigabitEthernet0/0/0]q
[AR1]interface gigabitethernet 0/0/1
[AR1-GigabitEthernet0/0/1]ip address 192.168.20.254 24
[AR1-GigabitEthernet0/0/1]q
[AR1]interface gigabitethernet 0/0/2
[AR1-GigabitEthernet0/0/2]ip address 12.1.1.1 30
[AR1-GigabitEthernet0/0/2]q
[AR1]interface gigabitethernet 4/0/0
[AR1-GigabitEthernet4/0/0]ip address 13.1.1.1 30
[AR1-GigabitEthernet4/0/0]q
[AR1]
配置出口路由地址
[AR1]acl 2000
[AR1-acl-basic-2000]rule 1 permit source 192.168.10.0 0.0.0.255
[AR1-acl-basic-2000]rule 2 permit source 192.168.20.0 0.0.0.255
[AR1-acl-basic-2000]quit
[AR1]interface gigabitethernet 0/0/2
[AR1-GigabitEthernet0/0/2]nat outbound 2000
[AR1-GigabitEthernet0/0/2]
[AR1-GigabitEthernet0/0/2]quit
[AR1]interfa gigabitethernet 4/0/0
[AR1-GigabitEthernet4/0/0]nat outbound 2000
[AR1-GigabitEthernet4/0/0]qui
[AR1]
配置静态路由
电信,联通两条路都可以走
[AR1]
[AR1]ip route-static 0.0.0.0 0.0.0.0 12.1.1.2
[AR1]ip route-static 0.0.0.0 0.0.0.0 13.1.1.2
[AR1]
这时候优先级都是默认60
但是它走的下面联通路线,我们要求优先走电信上面的路线
给联通的优先级调大一点(90),数字越小越优先
[AR1]
[AR1]ip route-static 0.0.0.0 0.0.0.0 13.1.1.2 preference 90
Info: Succeeded in modifying route.
Apr 11 2023 15:04:53-08:00 AR1 %%01RM/4/IPV4_DEFT_RT_CHG(l)[0]:IPV4 default Rout
e is changed. (ChangeType=Delete, InstanceId=0, Protocol=Static, ExitIf=GigabitE
thernet4/0/0, Nexthop=13.1.1.2, Neighbour=0.0.0.0, Preference=1509949440, Label=
NULL, Metric=0)
[AR1]
这时候默认走上面电信,当上面的线路出现故障才走下面的联通
AR2路由器配置
配置两边端口的ip
ge0/0/0:12.1.1.2/30
ge0/0/1:100.1.1.1/30
<Huawei>
<Huawei>system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]undo info-center enable
Info: Information center is disabled.
[Huawei]sysname AR2
[AR2]interface gigabitethernet 0/0/0
[AR2-GigabitEthernet0/0/0]ip address 12.1.1.2 30
[AR2-GigabitEthernet0/0/0]quit
[AR2]interface gigabitethernet 0/0/1
[AR2-GigabitEthernet0/0/1]ip address 100.1.1.1 30
[AR2-GigabitEthernet0/0/1]q
[AR2]
OSPF宣告所有网段
[AR2]
[AR2]ospf 1
[AR2-ospf-1]area 0
[AR2-ospf-1-area-0.0.0.0]network 0.0.0.0 0.0.0.0
[AR2-ospf-1-area-0.0.0.0]quit
[AR2-ospf-1]quit
AR3路由器配置
ge0/0/1:13.1.1.2/30
ge0/0/0:200.1.1.1/30
<Huawei>system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]undo info-center enable
Info: Information center is disabled.
[Huawei]sysname AR3
[AR3]interface gigabitethernet 0/0/1
[AR3-GigabitEthernet0/0/1]ip address 13.1.1.2 30
[AR3-GigabitEthernet0/0/1]quit
[AR3]interface gigabitethernet 0/0/0
[AR3-GigabitEthernet0/0/0]ip address 200.1.1.1 30
[AR3-GigabitEthernet0/0/0]quit
[AR3]
OSPF宣告所有网段
[AR3]
[AR3]ospf 1
[AR3-ospf-1]area 0
[AR3-ospf-1-area-0.0.0.0]network 0.0.0.0 0.0.0.0
[AR3-ospf-1-area-0.0.0.0]quit
[AR3-ospf-1]quit
[AR3]
AR4路由器配置
ge0/0/0:100.1.1.2/30
ge0/0/1:200.1.1.2/30
le0:22.22.22.22/32
<Huawei>system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]undo info-center enable
Info: Information center is disabled.
[Huawei]sysname AR4
[AR4]interface gigabitethernet 0/0/1
[AR4-GigabitEthernet0/0/1]ip address 100.1.1.2 30
[AR4-GigabitEthernet0/0/1]quit
[AR4]interface gigabitethernet 0/0/0
[AR4-GigabitEthernet0/0/0]ip address 200.1.1.2 30
[AR4-GigabitEthernet0/0/0]quit
[AR4]interface loopback 0
[AR4-LoopBack0]ip address 22.22.22.22 32
[AR4-LoopBack0]quit
[AR4]
OSPF宣告所有网段
[AR4]
[AR4]
[AR4]ospf 1
[AR4-ospf-1]area 0
[AR4-ospf-1-area-0.0.0.0]network 0.0.0.0 0.0.0.0
[AR4-ospf-1-area-0.0.0.0]quit
[AR4-ospf-1]
BFD检测配置
在路由和电信中间新增一台不做配置的交换机
这时候依然优先走上面电信线路
但是如果LSW1这台新增交换机的ge 0/0/2接口或电脑的ge 0/0/0接口出现故障,网络就会瘫痪,除非是LSW1的ge 0/0/2端口出现故障才会自动切换走联通路线。
这时候使用BFD,快速检测设备发送和接收两端的通信故障,可以避免发生此类事件。
AR1路由器BFD配置
[AR1]
[AR1]bfd
[AR1-bfd]bfd 1 bind peer-ip 12.1.1.2 source-ip 12.1.1.1 auto
[AR1-bfd-session-1]commit
[AR1-bfd-session-1]quit
上面这条路由跟踪刚刚设置的BFD,如果BFD不通了,就删掉上面的路由,从而实现上面线路出现故障自动走下面。
[AR1]
[AR1]ip route-static 0.0.0.0 0.0.0.0 12.1.1.2 track bfd-session 1
Info: Succeeded in modifying route.
Apr 11 2023 16:02:23-08:00 AR1 %%01RM/4/IPV4_DEFT_RT_CHG(l)[13]:IPV4 default Rou
te is changed. (ChangeType=Delete, InstanceId=0, Protocol=Static, ExitIf=Gigabit
Ethernet0/0/2, Nexthop=12.1.1.2, Neighbour=0.0.0.0, Preference=1006632960, Label
=NULL, Metric=0)
[AR1]
AR2路由器BFD配置
[AR2]
[AR2]bfd
[AR2-bfd]bfd 1 bind peer-ip 12.1.1.1 source-ip 12.1.1.2 auto
[AR2-bfd-session-1]commit
[AR2-bfd-session-1]quit
[AR2]
评论区