示例:配置 BGP 以通告非活动路由
默认情况下,BGP 仅重新播发活动路由。要让路由表将 BGP 获知的最佳路由导出到 BGP(即使 Junos OS 未将其选为活动路由),请包含以下 advertise-inactive
语句:
advertise-inactive;
在 Junos OS 中,BGP 通告已安装或处于活动状态的 BGP 路由,这些路由是根据 BGP 路径选择规则选择为最佳路由的。该 advertise-inactive
语句允许将非活动 BGP 路由通告给其他对等方。
如果路由表有两个 BGP 路由,其中一个处于活动状态,另一个处于非活动状态, advertise-inactive
则该语句不会播发非活动 BGP 前缀。当存在另一个活动的 BGP 路由时,此语句不会播发非活动 BGP 路由。但是,如果活动路由是静态路由, advertise-inactive
则该语句将播发非活动 BGP 路由。
当路由器配置为路由反射器时,该 advertise-inactive
语句无助于从 VRF 通告非活动路由。
Junos OS 还支持配置与播发路由状态匹配的 BGP 导出策略。您可以匹配活动或非活动路由,如下所示:
policy-options { policy-statement name{ from state (active|inactive); } }
此限定符仅在导出策略上下文中使用时匹配。当路由由可以通告非活动路由的协议(如 BGP)通告时,state inactive
匹配作为 (或advertise-external
) 语句结果advertise-inactive
播发的路由。
例如,以下配置可用作 BGP 导出策略,以标记由于具有用户定义的社区的设置而 advertise-inactive
播发的路由。接收路由器稍后可以使用该社区从转发表中过滤掉此类路由。此类机制可用于解决发送方未用于转发的广告路径可能导致转发循环的问题。
user@host# show policy-options policy-statement mark-inactive { term inactive { from state inactive; then { community set comm-inactive; } } term default { from protocol bgp; then accept; } then reject; } community comm-inactive members 65536:65284;
要求
配置此示例之前,不需要除设备初始化之外的特殊配置。
概述
在此示例中,设备 R2 有两个外部 BGP (EBGP) 对等方,即设备 R1 和设备 R3。
设备 R1 具有到 172.16.5/24 的静态路由。同样,设备 R2 也有到 172.16.5/24 的静态路由。设备 R1 通过 BGP 向设备 R2 发送有关其静态路由的信息。设备 R2 现在具有来自两个源的有关 172.16.5/24 的信息:它自己的静态路由和从设备 R1 接收的 BGP 获知路由。静态路由优先于 BGP 获知的路由,因此 BGP 路由在设备 R2 上处于非活动状态。通常,设备 R2 会将 BGP 获知的信息发送到设备 R3,但设备 R2 不会执行此操作,因为 BGP 路由处于非活动状态。因此,设备 R3 没有关于 172.16.5/24 的信息,除非您在设备 R2 上启用 advertise-inactive
命令,这会导致设备 R2 将获知的 BGP 发送到设备 R3。
配置
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改与您的网络配置匹配所需的任何详细信息,然后将命令复制并粘贴到层次结构级别的 CLI [edit]
中。
设备 R1
set interfaces fe-1/2/0 unit 0 family inet address 10.0.0.1/30 set interfaces lo0 unit 0 family inet address 192.168.0.1/32 set protocols bgp group to_R2 type external set protocols bgp group to_R2 export send-static set protocols bgp group to_R2 neighbor 10.0.0.2 peer-as 200 set policy-options policy-statement send-static term 1 from protocol static set policy-options policy-statement send-static term 1 then accept set routing-options static route 172.16.5.0/24 discard set routing-options static route 172.16.5.0/24 install set routing-options autonomous-system 100
设备 R2
set interfaces fe-1/2/0 unit 0 family inet address 10.0.0.2/30 set interfaces fe-1/2/1 unit 0 family inet address 10.0.0.5/30 set interfaces lo0 unit 0 family inet address 192.168.0.2/32 set protocols bgp group to_R1 type external set protocols bgp group to_R1 neighbor 10.0.0.1 peer-as 100 set protocols bgp group to_R3 type external set protocols bgp group to_R3 advertise-inactive set protocols bgp group to_R3 neighbor 10.0.0.6 peer-as 300 set routing-options static route 172.16.5.0/24 discard set routing-options static route 172.16.5.0/24 install set routing-options autonomous-system 200
设备 R3
set interfaces fe-1/2/1 unit 0 family inet address 10.0.0.6/30 set interfaces fe-1/2/0 unit 9 family inet address 10.0.0.9/30 set interfaces lo0 unit 0 family inet address 192.168.0.3/32 set protocols bgp group ext type external set protocols bgp group ext peer-as 200 set protocols bgp group ext neighbor 10.0.0.5 set routing-options autonomous-system 300
程序
分步过程
以下示例要求您在配置层次结构中导航各个级别。有关导航 CLI 的信息,请参阅《Junos OS CLI 用户指南》中的在配置模式下使用 CLI 编辑器。
要配置设备 R2:
配置设备接口。
[edit interfaces] user@R2# set fe-1/2/0 unit 0 family inet address 10.0.0.2/30 user@R2# set fe-1/2/1 unit 0 family inet address 10.0.0.5/30 user@R2# set lo0 unit 0 family inet address 192.168.0.2/32
配置与设备 R1 的 EBGP 连接。
[edit protocols bgp group to_R1] user@R2# set type external user@R2# set neighbor 10.0.0.1 peer-as 100
配置与设备 R3 的 EBGP 连接。
[edit protocols bgp group to_R3] user@R2# set type external user@R2# set neighbor 10.0.0.6 peer-as 300
将该
advertise-inactive
语句添加到与设备 R3 的 EBGP 组对等会话。[edit protocols bgp group to_R3] user@R2# set advertise-inactive
配置到 172.16.5.0/24 网络的静态路由。
[edit routing-options static] user@R2# set route 172.16.5.0/24 discard user@R2# set route 172.16.5.0/24 install
配置自治系统 (AS) 编号。
[edit routing-options] user@R2# set autonomous-system 200
结果
在配置模式下,输入 show interfaces
、show protocols
、show policy-options
和 show routing-options
命令,以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明,以便进行更正。
user@R2# show interfaces fe-1/2/0 { unit 0 { family inet { address 10.0.0.2/30; } } } fe-1/2/1 { unit 0 { family inet { address 10.0.0.5/30; } } } lo0 { unit 0 { family inet { address 192.168.0.2/32; } } }
user@R2# show protocols bgp { group to_R1 { type external; neighbor 10.0.0.1 { peer-as 100; } } group to_R3 { type external; advertise-inactive; neighbor 10.0.0.6 { peer-as 300; } } }
user@R2# show routing-options static { route 172.16.5.0/24 { discard; install; } } autonomous-system 200;
如果完成设备配置,请从配置模式输入 commit
。
验证
确认配置工作正常。
验证 BGP 活动路径
目的
在设备 R2 上,确保 172.16.5.0/24 前缀位于路由表中,并且具有预期的活动路径。
操作
user@R2> show route 172.16.5 inet.0: 7 destinations, 8 routes (7 active, 0 holddown, 0 hidden) + = Active Route, - = Last Active, * = Both 172.16.5.0/24 *[Static/5] 21:24:38 Discard [BGP/170] 21:21:41, localpref 100 AS path: 100 I, validation-state: unverified > to 10.0.0.1 via fe-1/2/0.0
意义
设备 R2 从设备 R1 及其自己的静态配置路由接收 172.16.5.0/24 路由。静态路由是活动路径,由星号 (*) 指定。与 BGP 优先级 (170) 相比,静态路由路径具有最低的路由优先级 (5)。因此,静态路由变为活动状态。
验证外部路由通告
目的
在设备 R2 上,确保向设备 R3 播发 172.16.5.0/24 路由。
操作
user@R2> show route advertising-protocol bgp 10.0.0.6 inet.0: 6 destinations, 7 routes (6 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path 172.16.5.0/24 Self 100 I
意义
设备 R2 正在向设备 R3 播发 172.16.5.0/24 路由
验证设备 R3 上的路由
目的
确保 172.16.6.0/24 前缀位于设备 R3 的路由表中。
操作
user@R3> show route 172.16.5.0/24 inet.0: 5 destinations, 5 routes (5 active, 0 holddown, 0 hidden) + = Active Route, - = Last Active, * = Both 172.16.5.0/24 *[BGP/170] 00:01:19, localpref 100 AS path: 200 100 I, validation-state: unverified > to 10.0.0.5 via fe-1/2/1.0
意义
设备 R3 具有 172.16.5.0/24 的 BGP 获知路由。
试验广告无效语句
目的
查看从设备 R2 上的 BGP 配置中删除语句 advertise-inactive
后会发生什么情况。
操作
在设备 R2 上,停用语句
advertise-inactive
。[edit protocols bgp group to_R3] user@R2# deactivate advertise-inactive user@R2# commit
在设备 R2 上,检查 172.16.5.0/24 路由是否播发到设备 R3。
user@R2> show route advertising-protocol bgp 10.0.0.6
正如预期的那样,该路由不再播发。
在设备 R3 上,确保路由表中没有 172.16.5/24 路由。
user@R3> show route 172.16.5/24
意义
设备 R1 将路由 172.16.5/24 播发至设备 R2,但设备 R2 具有为此前缀手动配置的静态路由。静态路由优先于 BGP 路由,因此设备 R2 会将 BGP 路由安装为非活动路由。由于 BGP 路由未处于活动状态,因此设备 R2 不会将 BGP 路由重新播发至设备 R3。这是 Junos OS 中的默认行为。如果将该 advertise-inactive
语句添加到设备 R2 上的 BGP 配置中,设备 R2 将重新播发非活动路由。