更具体的 BGP 路由与不太具体的静态路由,选择哪个?

网络工程 路由 bgp
2021-08-01 03:37:43

所以在下面的两个路由表条目中:

  • BGP 路由通告 10.1.1.0/24
  • 静态路由通告 10.1.0.0/16

哪个会被选中?我知道静态路由是通过 BGP(和其他)路由选择的,更具体的路由条目是通过不太具体的路由选择的,但是,哪个优先?我想说静态路由,但是我不确定。

2个回答

更具体的路由是用于转发数据包的路由。您拥有的两个前缀实际上是两个独立的前缀,就好像它们位于完全不同的网络块中一样。您正在尝试将苹果与橙子进行比较

另一方面,如果前缀长度相等,则将使用静态路由(假设使用默认 AD)。

我将这个问题读为“如果有到 10.1.0.0/16 的静态路由和到 10.1.1.0/24 的更具体的 BGP 学习路由,将如何路由到子网 10.1.1.0/24 的流量? ”。

在那种情况下,答案将是:将选择更具体的路由,无论各个协议之间的管理距离有多大差异。

示例:路由器 junos2 向路由器 junos1 通告 10.1.1.0/24。

路由器 junos1 有一条到 10.1.0.0/16 的静态路由,丢弃到那个不太具体的前缀的流量:

junos1 配置

@junos1> show configuration | display set
set interfaces em0 unit 0 family inet address 172.16.100.1/30
set routing-options static route 10.1.0.0/16 discard
set protocols bgp local-as 111
set protocols bgp group AS-222 type external
set protocols bgp group AS-222 peer-as 222
set protocols bgp group AS-222 neighbor 172.16.100.2 family inet unicast

路由器 junos1 正在通过 BGP 从邻居 junos2 接收更具体的路由:

@junos1>show route receive-protocol bgp 172.16.100.2

inet.0: 4 destinations, 5 routes (4 active, 0 holddown, 0 hidden)
  Prefix          Nexthop          MED     Lclpref    AS path
* 10.1.1.0/24             172.16.100.2                            222 I
  172.16.100.0/30         172.16.100.2                            222 I

检查路由表,我们看到两条路由都已安装:

@junos1> show route

inet.0: 4 destinations, 5 routes (4 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both

10.1.0.0/16        *[Static/5] 00:10:58
                      Discard
10.1.1.0/24        *[BGP/170] 00:12:01, localpref 100
                      AS path: 222 I
                    > to 172.16.100.2 via em0.0

对于前缀 10.1.1.0/24 内的地址,更具体的 BGP 学习路由是首选(即使静态路由的 AD 为 170,而 AD 为 5):

@junos1> show route 10.1.1.1

inet.0: 4 destinations, 5 routes (4 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both

10.1.1.0/24        *[BGP/170] 00:13:30, localpref 100
                      AS path: 222 I
                    > to 172.16.100.2 via em0.0

这可以通过 ping 10.1.1.1 来证明 - 流量没有被丢弃:

@junos1> ping rapid 10.1.1.1
PING 10.1.1.1 (10.1.1.1): 56 data bytes
!!!!!
--- 10.1.1.1 ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.410/0.772/1.528/0.391 ms