学习精彩网络技术老师:华为HCIA和HCIP数通eNSP实战视频课
学习精彩网络技术老师:华为、华三、锐捷、WLAN、IPv6等全套视频课程
通过配置BGP按路由策略迭代下一跳,可以防止在路由变化时发生流量丢失。
组网需求
如图1所示,AS100内运行的IGP协议为OSPF,DeviceA分别与DeviceB、DeviceC之间通过Loopback0接口建立IBGP连接。DeviceB和DeviceC发布10.20.1.0/24的BGP路由给DeviceA。因为DeviceB的router-id较小,所以DeviceA将优选从DeviceB学到的去往10.20.1.0/24的路由,原始下一跳为2.2.2.2/32。
正常情况下,DeviceA会把去往10.20.1.0/24的BGP路由下一跳迭代到去往2.2.2.2/32的IGP路由上,迭代出接口为GE0/1/0。但是,当DeviceB发生故障时,DeviceA会很快撤销去往2.2.2.2/32的IGP路由;而由于DeviceA要等到BGP保持时间定时器超时后才能感知到BGP路由的变化,所以在此之前,DeviceA仍然优选原始下一跳为2.2.2.2/32的BGP路由。根据最长匹配原则,DeviceA会把去往10.20.1.0/24的BGP路由下一跳错误地迭代到去往2.2.2.0/24的直连路由上,迭代出接口为GE0/1/2,从而导致流量丢失。
本例中interface1,interface2,interface3,interface4分别代表GE0/1/0,GE0/1/1,GE0/1/2,Loopback0。
为了避免上述情况的发生,可以在DeviceA上配置BGP按路由策略迭代下一跳,利用指定的路由策略对迭代结果路由进行限制。在本例中,可通过路由策略将迭代结果路由限制为32位掩码的具体路由,不能通过该路由策略过滤的迭代结果将被标识为不可达,这样就能使DeviceA在DeviceB发生故障后,快速感知BGP路由的变化,进而重新选择正确的路由即原始下一跳为3.3.3.3/32的BGP路由,防止流量丢失。
配置注意事项
在配置过程中,需注意以下事项:
在配置路由策略时,请仔细确认是否所有允许被迭代到的结果路由都能通过该策略的过滤,否则可能导致BGP路由不可达,无法指导转发。
配置思路
采用如下的思路配置BGP按路由策略迭代下一跳:
在DeviceA、DeviceB和DeviceC上配置OSPF,使AS100内各设备之间能够互通。
在DeviceA和DeviceB、DeviceC之间配置通过Loopback0接口建立IBGP连接。
在DeviceB和DeviceC上分别发布BGP路由10.20.1.0/24,使DeviceA分别通过DeviceB和DeviceC学到去往10.20.1.0/24的路由。
在DeviceA上配置BGP按路由策略迭代下一跳,使DeviceA在DeviceB发生故障时,快速感知到BGP路由的变化,进而重新选择正确的BGP路由,避免流量丢失。
数据准备
为完成此配置例,需准备如下的数据:
DeviceA、DeviceB和DeviceC的Router ID分别为1.1.1.1、2.2.2.2和3.3.3.3,所在的AS号为100。
在DeviceA上配置的用于限制迭代结果路由的路由策略名称为np-by-rp。
操作步骤
- 配置各接口的IP地址,请参见配置文件
- 在AS 100内配置OSPF
# 配置DeviceA。
[~DeviceA] ospf 1
[*DeviceA-ospf-1] area 0
[*DeviceA-ospf-1-area-0.0.0.0] network 1.1.1.1 0.0.0.0
[*DeviceA-ospf-1-area-0.0.0.0] network 10.1.0.0 0.0.255.255
[*DeviceA-ospf-1-area-0.0.0.0] commit
[~DeviceA-ospf-1-area-0.0.0.0] quit
[~DeviceA-ospf-1] quit
# 配置DeviceB。
[~DeviceB] ospf 1
[*DeviceB-ospf-1] area 0
[*DeviceC-ospf-1-area-0.0.0.0] network 2.2.2.2 0.0.0.0
[*DeviceB-ospf-1-area-0.0.0.0] network 10.1.1.0 0.0.0.255
[*DeviceB-ospf-1-area-0.0.0.0] commit
[~DeviceB-ospf-1-area-0.0.0.0] quit
[~DeviceB-ospf-1] quit
# 配置DeviceC。
[~DeviceC] ospf 1
[*DeviceC-ospf-1] area 0
[*DeviceC-ospf-1-area-0.0.0.0] network 3.3.3.3 0.0.0.0
[*DeviceC-ospf-1-area-0.0.0.0] network 10.1.2.0 0.0.0.255
[*DeviceC-ospf-1-area-0.0.0.0] commit
[~DeviceC-ospf-1-area-0.0.0.0] quit
[~DeviceC-ospf-1] quit
- 配置IBGP连接
# 配置DeviceA。
[~DeviceA] bgp 100
[*DeviceA-bgp] router-id 1.1.1.1
[*DeviceA-bgp] peer 2.2.2.2 as-number 100
[*DeviceA-bgp] peer 3.3.3.3 as-number 100
[*DeviceA-bgp] peer 2.2.2.2 connect-interface Loopback 0
[*DeviceA-bgp] peer 3.3.3.3 connect-interface Loopback 0
[*DeviceA-bgp] commit
[~DeviceA-bgp] quit
# 配置DeviceB。
[~DeviceB] bgp 100
[*DeviceB-bgp] router-id 2.2.2.2
[*DeviceB-bgp] peer 1.1.1.1 as-number 100
[*DeviceB-bgp] peer 1.1.1.1 connect-interface Loopback 0
[*DeviceB-bgp] commit
[~DeviceB-bgp] quit
# 配置DeviceC。
[~DeviceC] bgp 100
[*DeviceC-bgp] router-id 3.3.3.3
[*DeviceC-bgp] peer 1.1.1.1 as-number 100
[*DeviceC-bgp] peer 1.1.1.1 connect-interface Loopback 0
[*DeviceC-bgp] commit
[~DeviceC-bgp] quit
- 在DeviceB和DeviceC上配置BGP发布路由10.20.1.0/24
# 配置DeviceB。
[~DeviceB] ip route-static 10.20.1.0 24 NULL 0
[*DeviceB] commit
[*DeviceB] bgp 100
[*DeviceB-bgp] import-route static
[*DeviceB-bgp] commit
[~DeviceB-bgp] quit
# 配置DeviceC。
[~DeviceC] ip route-static 10.20.1.0 24 NULL 0
[*DeviceC] commit
[*DeviceC] bgp 100
[*DeviceC-bgp] import-route static
[*DeviceC-bgp] commit
[~DeviceC-bgp] quit
- 在DeviceA上配置BGP按路由策略迭代下一跳
# 配置DeviceA。
[~DeviceA] bgp 100
[*DeviceA-bgp] nexthop recursive-lookup route-policy np-by-rp
[*DeviceA-bgp] commit
[~DeviceA-bgp] quit
[*DeviceA] route-policy np-by-rp permit node 0
[*DeviceA-route-policy] if-match ip-prefix np-by-rp-ip
[*DeviceA-route-policy] commit
[~DeviceA-route-policy] quit
[~DeviceA] ip ip-prefix np-by-rp-ip permit 0.0.0.0 32
[*DeviceA] commit
- 验证配置结果
# 当DeviceB运行正常时,在DeviceA上查看BGP路由10.20.1.0/24的详细信息。
[~DeviceA] display bgp routing-table 10.20.1.0 24
BGP local router ID : 1.1.1.1
Local AS number : 100
Paths: 2 available, 1 best, 1 select
BGP routing table entry information of 10.20.1.0/24:
From: 2.2.2.2 (2.2.2.2) Route Duration: 0d00h00m36s
Relay IP Nexthop: 10.1.1.2
Relay IP Out-interface: GigabitEthernet0/1/0
Original nexthop: 2.2.2.2
Qos information : 0x0
AS-path Nil, origin incomplete, MED 0, localpref 100, pref-val 0, valid, internal, best, select, pre 255
Not advertised to any peer yet
BGP routing table entry information of 10.20.1.0/24:
From: 3.3.3.3 (3.3.3.3) Route Duration: 0d02h53m45s
Relay IP Nexthop: 10.1.2.2
Relay IP Out-interface: GigabitEthernet0/1/1
Original nexthop: 3.3.3.3
Qos information : 0x0
AS-path Nil, origin incomplete, MED 0, localpref 100, pref-val 0, valid, internal, pre 255,
not preferred for router ID
Not advertised to any peers yet
# 在DeviceB的GigabitEthernet0/1/0接口下执行shutdown命令,模拟DeviceB发生故障。
[~DeviceB] interface GigabitEthernet 0/1/0
[*DeviceB-GigabitEthernet0/1/0] shutdown
[*DeviceB-GigabitEthernet0/1/0] commit
[~DeviceB-GigabitEthernet0/1/0] quit
# 在DeviceA上查看BGP路由10.20.1.0/24的详细信息。
[~DeviceA] display bgp routing-talbe 10.20.1.0 24
BGP local router ID : 1.1.1.1
Local AS number : 100
Paths: 2 available, 1 best, 1 select
BGP routing table entry information of 10.20.1.0/24:
From: 3.3.3.3 (3.3.3.3) Route Duration: 0d03h10m58s
Relay IP Nexthop: 10.1.2.2
Relay IP Out-interface: GigabitEthernet0/1/1
Original nexthop: 3.3.3.3
Qos information : 0x0
AS-path Nil, origin incomplete, MED 0, localpref 100, pref-val 0, valid, internal, best, select, pre 255
Not advertised to any peer yet
BGP routing table entry information of 10.20.1.0/24:
From: 2.2.2.2 (2.2.2.2) Route Duration: 0d00h00m50s
Relay IP Nexthop: 0.0.0.0
Relay IP Out-interface:
Original nexthop: 2.2.2.2
Qos information : 0x0
AS-path Nil, origin incomplete, MED 0, localpref 100, pref-val 0, internal, pre 255
Not advertised to any peers yet
在DeviceB发生故障后,路由10.20.1.0/24的原始下一跳2.2.2.2/32将迭代到2.2.2.10/24的直连路由上,但由于2.2.2.10/24不是32位掩码的具体路由,不能通过路由策略np-by-rp的过滤,因此将该迭代路由标识为不可达。这样就能使BGP快速重新选择正确的路由,即原始下一跳为3.3.3.3/32的路由。
配置文件
DeviceA的配置文件
#
sysname DeviceA
#
interface GigabitEthernet0/1/0
undo shutdown
ip address 10.1.1.1 255.255.255.0
#
interface GigabitEthernet0/1/1
undo shutdown
ip address 10.1.2.1 255.255.255.0
#
interface GigabitEthernet0/1/2
undo shutdown
ip address 2.2.2.10 255.255.255.0
#
interface LoopBack0
ip address 1.1.1.1 255.255.255.255
#
bgp 100
router-id 1.1.1.1
peer 2.2.2.2 as-number 100
peer 2.2.2.2 connect-interface LoopBack0
peer 3.3.3.3 as-number 100
peer 3.3.3.3 connect-interface LoopBack0
#
ipv4-family unicast
undo synchronization
nexthop recursive-lookup route-policy np-by-rp
peer 2.2.2.2 enable
peer 3.3.3.3 enable
#
ospf 1
area 0.0.0.0
network 1.1.1.1 0.0.0.0
network 10.1.0.0 0.0.255.255
#
route-policy np-by-rp permit node 10
if-match ip-prefix np-by-rp-ip
#
ip ip-prefix np-by-rp-ip index 10 permit 0.0.0.0 32
#
return
DeviceB的配置文件
#
sysname DeviceB
#
interface GigabitEthernet0/1/0
undo shutdown
ip address 10.1.1.2 255.255.255.0
#
interface LoopBack0
ip address 2.2.2.2 255.255.255.255
#
bgp 100
router-id 2.2.2.2
peer 1.1.1.1 as-number 100
peer 1.1.1.1 connect-interface LoopBack0
#
ipv4-family unicast
undo synchronization
import-route static
peer 1.1.1.1 enable
#
ospf 1
area 0.0.0.0
network 2.2.2.2 0.0.0.0
network 10.1.1.0 0.0.0.255
#
ip route-static 10.20.1.0 24 NULL 0
#
return
DeviceC的配置文件
#
sysname DeviceC
#
interface GigabitEthernet0/1/1
undo shutdown
ip address 10.1.2.2 255.255.255.0
#
interface LoopBack0
ip address 3.3.3.3 255.255.255.255
#
bgp 100
router-id 3.3.3.3
peer 1.1.1.1 as-number 100
peer 1.1.1.1 connect-interface LoopBack0
#
ipv4-family unicast
undo synchronization
import-route static
peer 1.1.1.1 enable
#
ospf 1
area 0.0.0.0
network 3.3.3.3 0.0.0.0
network 10.1.2.0 0.0.0.255
#
ip route-static 10.20.1.0 24 NULL 0
#
return