本页内容
基本 BGP 路由策略
了解路由策略
每个路由策略都由策略名称标识。名称可以包含字母、数字和连字符 (-),长度不超过 255 个字符。要在名称中包含空格,请用双引号将整个名称括起来。每个路由策略名称在配置中都必须是唯一的。
创建并命名策略后,必须先应用策略,然后才能激活。在配置层级使用protocols protocol-name和importexport语句应用路由策略。
在语 import 句中,您列出了在将路由从路由协议导入路由表时要评估的路由策略的名称。
在该 export 语句中,您列出了在将路由从路由表导出到动态路由协议时要评估的路由策略的名称。仅从路由表导出活动路由。
要指定多个策略并创建策略链,请使用空格作为分隔符列出策略。如果指定了多个策略,则将按指定的顺序评估策略。一旦执行接受或拒绝操作,策略链评估就会结束。
显式配置的路由
显式配置的路由是您配置的路由。直接路由未显式配置。它们是由于在接口上配置了 IP 地址而创建的。显式配置的路由包括聚合路由、生成路由、本地路由和静态路由。(聚合路由是将具有公共地址的路由组提取为一个路由的路由。生成的路由是当路由表没有关于如何到达特定目标的信息时使用的路由。本地路由是分配给路由器接口的 IP 地址。静态路由是到达目标的不变路由。)
策略框架软件将直接和显式配置的路由视为通过路由协议学习的路由;因此,可以将它们导入到路由表中。路由不能从路由表导出到伪协议,因为该协议不是真正的路由协议。但是,聚合路由、直接路由、生成路由和静态路由可以从路由表导出到路由协议,而本地路由则不能。
默认情况下,BGP 仅导出 BGP 获知的路由。除非路由策略明确允许,否则不会导出从其他协议(如静态、直接或 IGP)获知的路由。
显式策略覆盖隐式偏好。配置路由策略时,它将优先于隐式行为。如果尚未配置路由策略,则 BGP 会应用隐式优先级行为。根据设计,BGP 首选本地配置的显式策略,而不是任何隐式优先级。
也可以看看
示例:在 BGP 层次结构的不同级别应用路由策略
此示例显示了在简单网络拓扑中配置的 BGP,并说明了在 BGP 配置的不同级别上应用路由策略时如何生效。
要求
配置此示例之前,不需要除设备初始化之外的特殊配置。
概述
对于 BGP,您可以按如下方式应用策略:
-
BGP 全局
import和export语句 — 在层次结构级别包含[edit protocols bgp]这些语句(对于路由实例,在层次结构级别包含[edit routing-instances routing-instance-name protocols bgp]这些语句)。 -
组
import和export语句 — 在层次结构级别包含[edit protocols bgp group group-name]这些语句(对于路由实例,在层次结构级别包含[edit routing-instances routing-instance-name protocols bgp group group-name]这些语句)。 -
对等方
import和export语句 — 在层次结构级别包含[edit protocols bgp group group-name neighbor address]这些语句(对于路由实例,在层次结构级别包含[edit routing-instances routing-instance-name protocols bgp group group-name neighbor address]这些语句)。 -
family
import和exportstatements — 在层次结构级别包含[edit protocols bgp family nlri]这些语句(对于路由实例,在层次结构级别包含[edit routing-instances routing-instance-name protocols bgp family nlri]这些语句)。
对等级别importexport或语句将覆盖组import或export语句。组级import或export语句将覆盖全局 BGP import 或export语句。
在此示例中,将在全局级别应用名为的策略 send-direct ,在组级别应用另一个名为 send-192.168.0.1 的策略,并在邻接方级别应用第三个名为 send-192.168.20.1 的策略。
user@host# show protocols
bgp {
local-address 172.16.1.1;
export send-direct;
group internal-peers {
type internal;
export send-192.168.0.1;
neighbor 172.16.2.2 {
export send-192.168.20.1;
}
neighbor 172.16.3.3;
}
group other-group {
type internal;
neighbor 172.16.4.4;
}
}
一个关键点(也经常被误解并可能导致问题)是在这样的配置中,仅应用最明确的策略。邻接方级别策略比组级别策略更明确,而组级别策略又比全局策略更明确。
邻接方 172.16.2.2 仅受 send-192.168.20.1 策略的约束。邻居 172.16.3.3 缺少任何更具体的内容,仅受 send-192.168.0.1 策略的约束。同时,组other-group中的邻接方172.16.4.4没有组或邻接方级策略,因此使用发送直接策略。
如果需要让邻居 172.16.2.2 执行所有三个策略的功能,您可以编写并应用包含其他三个策略功能的新邻居级策略,也可以将所有三个现有策略作为链应用于邻居 172.16.2.2。
配置
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,然后将命令复制并粘贴到层次结构级别的 [edit] CLI 中。
设备 R1
set interfaces fe-1/2/0 unit 0 description to-R2 set interfaces fe-1/2/0 unit 0 family inet address 10.10.10.1/30 set interfaces lo0 unit 0 family inet address 172.16.1.1/32 set protocols bgp local-address 172.16.1.1 set protocols bgp export send-direct set protocols bgp group internal-peers type internal set protocols bgp group internal-peers export send-static-192.168.0 set protocols bgp group internal-peers neighbor 172.16.2.2 export send-static-192.168.20 set protocols bgp group internal-peers neighbor 172.16.3.3 set protocols bgp group other-group type internal set protocols bgp group other-group neighbor 172.16.4.4 set protocols ospf area 0.0.0.0 interface lo0.0 passive set protocols ospf area 0.0.0.0 interface fe-1/2/0.0 set policy-options policy-statement send-direct term 1 from protocol direct set policy-options policy-statement send-direct term 1 then accept set policy-options policy-statement send-static-192.168.0 term 1 from protocol static set policy-options policy-statement send-static-192.168.0 term 1 from route-filter 192.168.0.0/24 orlonger set policy-options policy-statement send-static-192.168.0 term 1 then accept set policy-options policy-statement send-static-192.168.20 term 1 from protocol static set policy-options policy-statement send-static-192.168.20 term 1 from route-filter 192.168.20.0/24 orlonger set policy-options policy-statement send-static-192.168.20 term 1 then accept set routing-options static route 192.168.0.1/32 discard set routing-options static route 192.168.20.1/32 discard set routing-options router-id 172.16.1.1 set routing-options autonomous-system 17
设备 R2
set interfaces fe-1/2/0 unit 0 description to-R1 set interfaces fe-1/2/0 unit 0 family inet address 10.10.10.2/30 set interfaces fe-1/2/1 unit 0 description to-R3 set interfaces fe-1/2/1 unit 0 family inet address 10.10.10.5/30 set interfaces lo0 unit 0 family inet address 172.16.2.2/32 set protocols bgp group internal-peers type internal set protocols bgp group internal-peers local-address 172.16.2.2 set protocols bgp group internal-peers neighbor 172.16.3.3 set protocols bgp group internal-peers neighbor 172.16.1.1 set protocols bgp group internal-peers neighbor 172.16.4.4 set protocols ospf area 0.0.0.0 interface lo0.0 passive set protocols ospf area 0.0.0.0 interface fe-1/2/0.0 set protocols ospf area 0.0.0.0 interface fe-1/2/1.0 set routing-options router-id 172.16.2.2 set routing-options autonomous-system 17
设备 R3
set interfaces fe-1/2/1 unit 0 description to-R2 set interfaces fe-1/2/1 unit 0 family inet address 10.10.10.6/30 set interfaces fe-1/2/2 unit 0 description to-R4 set interfaces fe-1/2/2 unit 0 family inet address 10.10.10.9/30 set interfaces lo0 unit 0 family inet address 172.16.3.3/32 set protocols bgp group internal-peers type internal set protocols bgp group internal-peers local-address 172.16.3.3 set protocols bgp group internal-peers neighbor 172.16.2.2 set protocols bgp group internal-peers neighbor 172.16.1.1 set protocols bgp group internal-peers neighbor 172.16.4.4 set protocols ospf area 0.0.0.0 interface lo0.0 passive set protocols ospf area 0.0.0.0 interface fe-1/2/1.0 set protocols ospf area 0.0.0.0 interface fe-1/2/2.0 set routing-options router-id 172.16.3.3 set routing-options autonomous-system 17
设备 R4
set interfaces fe-1/2/2 unit 0 description to-R3 set interfaces fe-1/2/2 unit 0 family inet address 10.10.10.10/30 set interfaces lo0 unit 0 family inet address 172.16.4.4/32 set protocols bgp group internal-peers type internal set protocols bgp group internal-peers local-address 172.16.4.4 set protocols bgp group internal-peers neighbor 172.16.2.2 set protocols bgp group internal-peers neighbor 172.16.1.1 set protocols bgp group internal-peers neighbor 172.16.3.3 set protocols ospf area 0.0.0.0 interface lo0.0 passive set protocols ospf area 0.0.0.0 interface fe-1/2/2.0 set routing-options router-id 172.16.4.4 set routing-options autonomous-system 17
过程
分步程序
下面的示例要求您在各个配置层级中进行导航。有关导航 CLI 的信息,请参阅 《CLI 用户指南》中的在配置模式下使用 CLI 编辑器。
要配置 IS-IS 默认路由策略,请执行以下操作:
配置设备接口。
[edit interfaces] user@R1# set fe-1/2/0 unit 0 description to-R2 user@R1# set fe-1/2/0 unit 0 family inet address 10.10.10.1/30 user@R1# set lo0 unit 0 family inet address 172.16.1.1/32
在接口上启用 OSPF 或其他内部网关协议 (IGP)。
[edit protocols OSPF area 0.0.0.0] user@R1# set interface lo0.0 passive user@R1# set interface fe-1/2/0.0
配置静态路由。
[edit routing-options] user@R1# set static route 192.168.0.1/32 discard user@R1# set static route 192.168.20.1/32 discard
启用路由策略。
[edit protocols policy-options] user@R1# set policy-statement send-direct term 1 from protocol direct user@R1# set policy-statement send-direct term 1 then accept user@R1# set policy-statement send-static-192.168.0 term 1 from protocol static user@R1# set policy-statement send-static-192.168.0 term 1 from route-filter 192.168.0.0/24 orlonger user@R1# set policy-statement send-static-192.168.0 term 1 then accept user@R1# set policy-statement send-static-192.168.20 term 1 from protocol static user@R1# set policy-statement send-static-192.168.20 term 1 from route-filter 192.168.20.0/24 orlonger user@R1# set policy-statement send-static-192.168.20 term 1 then accept
配置 BGP 并应用导出策略。
[edit protocols bgp] user@R1# set local-address 172.16.1.1 user@R1# set protocols bgp export send-direct user@R1# set group internal-peers type internal user@R1# set group internal-peers export send-static-192.168.0 user@R1# set group internal-peers neighbor 172.16.2.2 export send-static-192.168.20 user@R1# set group internal-peers neighbor 172.16.3.3 user@R1# set group other-group type internal user@R1# set group other-group neighbor 172.16.4.4
配置路由器 ID 和自治系统 (AS) 编号。
[edit routing-options] user@R1# set router-id 172.16.1.1 user@R1# set autonomous-system 17
如果完成设备配置,请提交配置。
[edit] user@R1# commit
结果
在配置模式下,发出 、 show protocols、 show policy-options和show routing-options命令以show interfaces确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明以更正配置。
user@R1# show interfaces
fe-1/2/0 {
unit 0 {
description to-R2;
family inet {
address 10.10.10.1/30;
}
}
}
lo0 {
unit 0 {
family inet {
address 172.16.1.1/32;
}
}
}
user@R1# show protocols
bgp {
local-address 172.16.1.1;
export send-direct;
group internal-peers {
type internal;
export send-static-192.168.0;
neighbor 172.16.2.2 {
export send-static-192.168.20;
}
neighbor 172.16.3.3;
}
group other-group {
type internal;
neighbor 172.16.4.4;
}
}
ospf {
area 0.0.0.0 {
interface lo0.0 {
passive;
}
interface fe-1/2/0.0;
}
}
user@R1# show policy-options
policy-statement send-direct {
term 1 {
from protocol direct;
then accept;
}
}
policy-statement send-static-192.168.0 {
term 1 {
from {
protocol static;
route-filter 192.168.0.0/24 orlonger;
}
then accept;
}
}
policy-statement send-static-192.168.20 {
term 1 {
from {
protocol static;
route-filter 192.168.20.0/24 orlonger;
}
then accept;
}
}
user@R1# show routing-options
static {
route 192.168.0.1/32 discard;
route 192.168.20.1/32 discard;
}
router-id 172.16.1.1;
autonomous-system 17;
验证
确认配置工作正常。
验证 BGP 路由学习
目的
通过检查路由表,确保 BGP 导出策略按预期工作。
行动
user@R1> show route protocol direct
inet.0: 11 destinations, 11 routes (11 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
172.16.1.1/32 *[Direct/0] 1d 22:19:47
> via lo0.0
10.10.10.0/30 *[Direct/0] 1d 22:19:47
> via fe-1/2/0.0
user@R1> show route protocol static
inet.0: 11 destinations, 11 routes (11 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
192.168.0.1/32 *[Static/5] 02:20:03
Discard
192.168.20.1/32 *[Static/5] 02:20:03
Discard
user@R2> show route protocol bgp
inet.0: 11 destinations, 11 routes (11 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
192.168.20.1/32 *[BGP/170] 02:02:40, localpref 100, from 172.16.1.1
AS path: I, validation-state: unverified
> to 10.10.10.1 via fe-1/2/0.0
user@R3> show route protocol bgp
inet.0: 11 destinations, 11 routes (11 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
192.168.0.1/32 *[BGP/170] 02:02:51, localpref 100, from 172.16.1.1
AS path: I, validation-state: unverified
> to 10.10.10.5 via fe-1/2/1.0
user@R4> show route protocol bgp
inet.0: 9 destinations, 11 routes (9 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
172.16.1.1/32 [BGP/170] 1d 20:38:54, localpref 100, from 172.16.1.1
AS path: I, validation-state: unverified
> to 10.10.10.9 via fe-1/2/2.0
10.10.10.0/30 [BGP/170] 1d 20:38:54, localpref 100, from 172.16.1.1
AS path: I, validation-state: unverified
> to 10.10.10.9 via fe-1/2/2.0
意义
在设备 R1 上,命令 show route protocol direct 显示两个直接路由:172.16.1.1/32 和 10.10.10.0/30。命令 show route protocol static 显示两个静态路由:192.168.0.1/32 和 192.168.20.1/32。
在设备 R2 上, show route protocol bgp 命令显示设备 R2 通过 BGP 获知的唯一路由是 192.168.20.1/32 路由。
在设备 R3 上, show route protocol bgp 命令显示设备 R3 通过 BGP 获知的唯一路由是 192.168.0.1/32 路由。
在设备 R4 上,命令 show route protocol bgp 显示设备 R4 通过 BGP 获知的唯一路由是 172.16.1.1/32 和 10.10.10.0/30 路由。
验证 BGP 路由接收
目的
通过检查从设备 R1 接收的 BGP 路由,确保 BGP 导出策略按预期工作。
行动
user@R2> show route receive-protocol bgp 172.16.1.1 inet.0: 11 destinations, 11 routes (11 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 192.168.20.1/32 172.16.1.1 100 I
user@R3> show route receive-protocol bgp 172.16.1.1 inet.0: 11 destinations, 11 routes (11 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 192.168.0.1/32 172.16.1.1 100 I
user@R4> show route receive-protocol bgp 172.16.1.1 inet.0: 9 destinations, 11 routes (9 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path 172.16.1.1/32 172.16.1.1 100 I 10.10.10.0/30 172.16.1.1 100 I
意义
在设备 R2 上, route receive-protocol bgp 172.16.1.1 命令显示设备 R2 仅从设备 R1 接收一个 BGP 路由 192.168.20.1/32。
在设备 R3 上, route receive-protocol bgp 172.16.1.1 命令显示设备 R3 仅从设备 R1 接收一个 BGP 路由 192.168.0.1/32。
在设备 R4 上, route receive-protocol bgp 172.16.1.1 命令显示设备 R4 从设备 R1 接收了两个 BGP 路由 172.16.1.1/32 和 10.10.10.0/30。
总之,当在 BGP 中的不同 CLI 层次结构上应用多个策略时,仅评估最具体的应用程序,而排除其他不太具体的策略应用程序。尽管这一点似乎有道理,但在路由器配置过程中,当您错误地认为邻居级策略与全局级策略或组级策略组合在一起时,却发现策略行为与预期不符时,很容易忘记这一点。
示例:将 OSPF 路由注入 BGP 路由表
此示例说明如何创建将 OSPF 路由注入 BGP 路由表的策略。
要求
开始之前:
配置网络接口。
配置外部对等会话。请参阅 示例:配置外部 BGP 点对点对等会话。
配置对等方之间的内部网关协议 (IGP) 会话。
概述
在此示例中,您将创建一个名为 injectpolicy1 的路由策略和一个名为 injectterm1的路由术语。该策略会将 OSPF 路由注入 BGP 路由表。
拓扑结构
配置
配置路由策略
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,将命令复制并粘贴到 [edit] 层次结构级别的 CLI 中,然后从配置模式进入。commit
set policy-options policy-statement injectpolicy1 term injectterm1 from protocol ospf set policy-options policy-statement injectpolicy1 term injectterm1 from area 0.0.0.1 set policy-options policy-statement injectpolicy1 term injectterm1 then accept set protocols bgp export injectpolicy1
分步程序
下面的示例要求您在各个配置层级中进行导航。有关导航 CLI 的信息,请参阅 《CLI 用户指南》中的在配置模式下使用 CLI 编辑器。
要将 OSPF 路由注入 BGP 路由表,请执行以下操作:
创建策略术语。
[edit policy-options policy-statement injectpolicy1] user@host# set term injectterm1
将 OSPF 指定为匹配条件。
[edit policy-options policy-statement injectpolicy1 term injectterm1] user@host# set from protocol ospf
将来自 OSPF 区域的路由指定为匹配条件。
[edit policy-options policy-statement injectpolicy1 term injectterm1] user@host# set from area 0.0.0.1
指定如果与前面的条件匹配,则要接受路由。
[edit policy-options policy-statement injectpolicy1 term injectterm1] user@host# set then accept
将路由策略应用于 BGP。
[edit] user@host# set protocols bgp export injectpolicy1
结果
在配置模式下输入show policy-optionsshow protocols bgp 和命令,以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明以更正配置。
user@host# show policy-options
policy-statement injectpolicy1 {
term injectterm1 {
from {
protocol ospf;
area 0.0.0.1;
}
then accept;
}
}
user@host# show protocols bgp export injectpolicy1;
如果完成设备配置,请从配置模式进入。commit
为路由策略配置跟踪
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,将命令复制并粘贴到 [edit] 层次结构级别的 CLI 中,然后从配置模式进入。commit
set policy-options policy-statement injectpolicy1 term injectterm1 then trace set routing-options traceoptions file ospf-bgp-policy-log set routing-options traceoptions file size 5m set routing-options traceoptions file files 5 set routing-options traceoptions flag policy
分步程序
下面的示例要求您在各个配置层级中进行导航。有关导航 CLI 的信息,请参阅 《CLI 用户指南》中的在配置模式下使用 CLI 编辑器。
在策略中包括跟踪操作。
[edit policy-options policy-statement injectpolicy1 term injectterm1] user@host# then trace
配置输出的跟踪文件。
[edit routing-options traceoptions] user@host# set file ospf-bgp-policy-log user@host# set file size 5m user@host# set file files 5 user@host# set flag policy
结果
在配置模式下输入show policy-optionsshow routing-options和命令,以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明以更正配置。
user@host# show policy-options
policy-statement injectpolicy1 {
term injectterm1 {
then {
trace;
}
}
}
user@host# show routing-options
traceoptions {
file ospf-bgp-policy-log size 5m files 5;
flag policy;
}
如果完成设备配置,请从配置模式进入。commit
配置路由策略以控制 BGP 路由通告
所有路由协议都使用 Junos OS 路由表来存储它们学习的路由,并确定它们应在其协议数据包中播发哪些路由。通过路由策略,您可以控制路由协议在哪些路由中存储以及从路由表中检索。有关路由策略的信息,请参阅路由 策略、防火墙过滤器和流量监管器用户指南。
配置 BGP 路由策略时,您可以执行以下操作:
应用路由策略
您可以在层次结构级别定义 [edit policy-options] 路由策略。要应用为 BGP 定义的策略,请在 BGP 配置中包含 import and export 语句。
您可以按如下方式应用策略:
-
BGP 全局
import和export语句 — 在层次结构级别包含[edit protocols bgp]这些语句(对于路由实例,在层次结构级别包含[edit routing-instances routing-instance-name protocols bgp]这些语句)。 -
组
import和export语句 — 在层次结构级别包含[edit protocols bgp group group-name]这些语句(对于路由实例,在层次结构级别包含[edit routing-instances routing-instance-name protocols bgp group group-name]这些语句)。 -
对等方
import和export语句 — 在层次结构级别包含[edit protocols bgp group group-name neighbor address]这些语句(对于路由实例,在层次结构级别包含[edit routing-instances routing-instance-name protocols bgp group group-name neighbor address]这些语句)。 -
family
import和exportstatements — 在层次结构级别包含[edit protocols bgp family nlri]这些语句(对于路由实例,在层次结构级别包含[edit routing-instances routing-instance-name protocols bgp family nlri]这些语句)。
对等级别importexport或语句将覆盖组import或export语句。组级import或export语句将覆盖全局 BGP import 或export语句。
要应用策略,请参阅以下部分:
将策略应用于从 BGP 导入路由表的路由
要将策略应用于从 BGP 导入到路由表中的路由,请包含以下 import 语句,其中列出要评估的一个或多个策略的名称:
import [ policy-names ];
有关可包含此语句的层次结构级别列表,请参阅此语句的语句摘要部分。
如果指定多个策略,则按指定的顺序(从头到尾)对其进行评估,并将第一个匹配过滤器应用于路由。如果未找到匹配项,BGP 只会将从 BGP 路由设备获知的路由放入路由表中。
将策略应用于从路由表导出到 BGP 的路由
要将策略应用于从路由表导出到 BGP 的路由,请包含以下 export 语句,其中列出要评估的一个或多个策略的名称:
export [ policy-names ];
有关可包含此语句的层次结构级别列表,请参阅此语句的语句摘要部分。
如果指定多个策略,则按指定的顺序(从头到尾)对其进行评估,并将第一个匹配过滤器应用于路由。如果没有与过滤器匹配的路由,则路由表仅将其从 BGP 获知的路由导出到 BGP。
设置 BGP 以通告非活动路由
默认情况下,BGP 将从更新消息接收到的路由信息存储在 Junos OS 路由表中,路由表仅将活动路由导出到 BGP,然后 BGP 将其播发给对等方。要将路由表导出为BGP BGP获知的最佳路由(即使Junos OS未将其选择为活动路由),请包含以下 advertise-inactive 语句:
advertise-inactive;
有关可包含此语句的层次结构级别列表,请参阅此语句的语句摘要部分。
配置 BGP 以向内部对等方播发最佳外部路由
通常,部署的 BGP 实施不会将具有最高本地优先级值的外部路由播发给内部对等方,除非它是最佳路由。尽管 BGP 版本 4 的早期版本 RFC 1771 要求此行为,但为了尽量减少播发的信息量并防止路由环路,通常不会遵循此行为。但是,在某些情况下,通告最佳外部路由是有益的,特别是可能导致 IBGP 路由振荡的情况。
在 Junos OS 9.3 及更高版本 中,您可以配置 BGP,以便将最佳外部路由播发到内部 BGP (IBGP) 网格组、路由反射器群集或自治系统 (AS) 联合中,即使最佳路由是内部路由也是如此。
要在路由反射器上配置该 advertise-external 语句,必须使用该 no-client-reflect 语句禁用群集内反射。
将路由设备配置为群集的路由反射器后,如果路由反射器播发的路由是从具有相同群集标识符的内部对等方接收的,或者两个对等方均未配置群集标识符,则路由反射器播发的路由被视为群集标识符。从属于另一个群集的内部对等方(即使用不同的群集标识符)接收的路由被视为外部路由。
在联合体中,当向联合体边界路由器播发路由时,来自不同联合体子 AS 的任何路由都会被视为外部。
您还可以将 BGP 配置为仅在路由选择过程达到评估多出口点识别器 (MED) 指标时才通告外部路由。因此,如果外部路由的 AS 路径比活动路径更差(即更长),则不会对其进行播发。
Junos OS 还支持配置与播发路由状态匹配的 BGP 导出策略。您可以在活动或非活动路由上进行匹配。有关更多信息,请参阅路由 策略、防火墙过滤器和流量监管器用户指南。
要配置 BGP 以向内部对等方播发最佳外部路径,请包含以下 advertise-external 语句:
advertise-external;
组级别和邻接方级别都支持该 advertise-external 语句。如果在邻接方级别配置该语句,则必须为组中的所有邻接方配置该语句。否则,该组会自动拆分为不同的组。
有关可配置此语句的层次结构级别的完整列表,请参阅此语句的语句摘要部分。
要将 BGP 配置为仅在路由选择过程达到评估 MED 值的点时播发最佳外部路径,请包含以下 conditional 语句:
advertise-external {
conditional;
}
配置 BGP 使用路由表交换路由的频率
BGP将从更新消息接收到的路由信息存储在路由表中,路由表将活动路由从路由表导出到BGP中。然后,BGP 将导出的路由播发给其对等方。默认情况下,BGP 和路由表之间的路由信息交换会在收到路由后立即进行。这种路由信息的即时交换可能会导致网络可达性信息不稳定。为防止这种情况,您可以延迟 BGP 和路由表交换路由信息之间的时间。
要配置 BGP 和路由表交换路由信息的频率,请包含以下 out-delay 语句:
out-delay seconds;
默认情况下,路由表会保留从 BGP 获知的部分路由信息。要让路由表保留全部或不保留此信息,请包含以下语 keep 句:
keep (all | none);
有关可包含这些语句的层次结构级别列表,请参阅这些语句的语句摘要部分。
路由表可以通过以下方式之一保留从 BGP 获知的路由信息:
默认(省
keep略语句)— 保留从 BGP 获知的所有路由信息,AS 路径是循环的且环路中包含本地 AS 的路由除外。keep all— 保留从 BGP 获知的所有路由信息。keep none— 丢弃从对等方收到的路由,以及被导入策略或其他健全性检查(如 AS 路径或下一跃点)拒绝的路由。当您为 BGP 会话进行配置keep none并且入站策略发生更改时,Junos OS 会强制重新播发对等方播发的全套路由。
在 AS 路径修复情况下,当 AS 路径环路限制发生更改时,具有环路路径的路由理论上可以在软重新配置期间变为可用。但是,默认值和 keep all之间存在显着的内存使用差异。
请考虑以下场景:
对等方将路由重新播发至从中获知路由的对等方。
这可能发生在以下情况下:
另一家供应商的路由设备将路由播发给发送对等方。
Junos OS 对等方的默认行为是不将路由重新播发回发送对等方,配置 会覆盖
advertise-peer-as。
提供商边缘 (PE) 路由设备会丢弃任何没有任何预期路由目标的 VPN 路由。
配置后 keep all ,将覆盖在上述场景中丢弃收到的路由的行为。
禁用路由播发抑制
Junos OS 不会将从一个 EBGP 对等方获知的路由播发至同一外部 BGP (EBGP) 对等方。此外,无论路由实例如何,软件都不会将这些路由播发至与始发对等方处于相同 AS 中的任何 EBGP 对等方。您可以通过在配置中包含 advertise-peer-as 语句来修改此行为。要禁用默认播发抑制,请包含以下 advertise-peer-as 语句:
advertise-peer-as;
如果配置中包含该语句,则 as-override 路由抑制默认行为将被禁用。
如果在配置中包含该 advertise-peer-as 语句,则无论此检查如何,BGP 都会播发路由。
要恢复默认行为,请在配置中包含该 no-advertise-peer-as 语句:
no-advertise-peer-as;
如果在配置中同时包含 and no-advertise-peer-as 语as-override句,则会忽略该no-advertise-peer-as语句。您可以在多个层级包含这些语句。
有关可包含这些语句的层次结构级别列表,请参阅这些语句的语句摘要部分。
也可以看看
示例:配置路由策略以向内部对等方播发最佳外部路由
RFC 1771 中定义的 BGP 协议规范规定,BGP 对等体应向其内部对等方通告优先级更高的外部路径,即使该路径不是整体最佳路径(换句话说,即使最佳路径是内部路径)。实际上,部署的 BGP 实现不遵循此规则。偏离规范的原因如下:
最大限度地减少广告信息量。BGP 根据可用路径的数量进行扩展。
避免路由和转发环路。
但是,在几种情况下,RFC 1771 中指定的播发最佳外部路由的行为可能是有益的。限制路径信息并不总是可取的,因为路径分集可能有助于缩短还原时间。播发最佳外部路径还可以解决内部 BGP (IBGP) 路由振荡问题,如 RFC 3345, 边界网关协议 (BGP) 持久路由振荡条件中所述。
该 advertise-external 语句会修改 BGP 发言者的行为,以向 IBGP 对等方播发最佳外部路径,即使最佳整体路径是内部路径也是如此。
组级别和邻接方级别都支持该 advertise-external 语句。如果在邻接方级别配置该语句,则必须为组中的所有邻接方配置该语句。否则,该组会自动拆分为不同的组。
该 conditional 选项可限制设置 advertise-external 的行为,以便仅当路由选择过程达到评估多出口点识别器 (MED) 指标的点时,才会通告外部路由。因此,如果外部路由的 AS 路径比活动路径更差(更长),则不会对其进行播发。该 conditional 选项将外部路径播发限制为最佳外部路径和活动路径相等时,直到路由选择过程的 MED 步骤为止。请注意,无论是否配置了该 conditional 选项,用于选择最佳外部路径的标准都是相同的。
Junos OS 还支持配置与播发路由状态匹配的 BGP 导出策略。您可以匹配活动或非活动路由,如下所示:
policy-options {
policy-statement name{
from state (active|inactive);
}
}
仅当在导出策略的上下文中使用时,此限定符才匹配。当路由由可播发非活动路由(如 BGP)的协议播发时,state inactive匹配由于 and advertise-external 语句而advertise-inactive播发的路由。
例如,以下配置可用作针对内部对等方的 BGP 导出策略,以标记由于 advertise-external 使用用户定义社区的设置而播发的路由。接收路由器稍后可以使用该社区从转发表中过滤掉此类路由。此类机制可用于解决发送方未用于转发的播发路径可能导致转发环路的担忧。
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;
要求
需要 Junos OS 9.3 或更高版本。
概述
此示例显示三个路由设备。设备 R2 与设备 R1 具有外部 BGP (EBGP) 连接。设备 R2 与设备 R3 具有 IBGP 连接。
设备 R1 播发 172.16.6.0/24。设备 R2 未在导入策略中为设备 R1 的路由设置本地优先级,因此 172.16.6.0/24 的默认本地优先级为 100。
设备 R3 播发 172.16.6.0/24,本地优先级为 200。
如果设备 R2 上未配置该 advertise-external 语句,则设备 R2 不会向设备 R3 播发 172.16.6.0/24。
在针对设备 R3 的会话上在设备 R2 上配置该 advertise-external 语句后,设备 R2 将向设备 R3 播发 172.16.6.0/24。
当在设备 R2 上针对设备 R3 的会话上配置 172.16.6.0/24 时 advertise-external conditional ,设备 R2 不会向设备 R3 播发 172.16.6.0/24。如果移除 then local-preference 200 设备 R3 上的设置并在设备 R2 上添加设置 path-selection as-path-ignore (从而使路径选择标准相等,直到路由选择过程的 MED 步骤),设备 R2 将向设备 R3 播发 172.16.6.0/24。
要在路由反射器上配置该 advertise-external 语句,您必须使用该 no-client-reflect 语句禁用群集内反射,并且客户端群集必须完全网状化,以防止发送冗余路由播发。
将路由设备配置为群集的路由反射器后,如果路由反射器播发的路由是从具有相同群集标识符的内部对等方接收的,或者两个对等方均未配置群集标识符,则路由反射器播发的路由被视为群集标识符。从属于另一个群集的内部对等方(即使用不同的群集标识符)接收的路由被视为外部路由。
配置
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,然后将命令复制并粘贴到层次结构级别的 [edit] CLI 中。
设备 R1
set interfaces fe-1/2/0 unit 0 description to-R2 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 ext type external set protocols bgp group ext export send-static set protocols bgp group ext peer-as 200 set protocols bgp group ext neighbor 10.0.0.2 set policy-options policy-statement send-static term 1 from protocol static set policy-options policy-statement send-static term 1 from route-filter 172.16.6.0/24 exact set policy-options policy-statement send-static term 1 then accept set policy-options policy-statement send-static term 2 then reject set routing-options static route 172.16.6.0/24 reject set routing-options router-id 192.168.0.1 set routing-options autonomous-system 100
设备 R2
set interfaces fe-1/2/0 unit 0 description to-R1 set interfaces fe-1/2/0 unit 0 family inet address 10.0.0.2/30 set interfaces fe-1/2/1 unit 0 description to-R3 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 ext type external set protocols bgp group ext peer-as 100 set protocols bgp group ext neighbor 10.0.0.1 set protocols bgp group int type internal set protocols bgp group int local-address 192.168.0.2 set protocols bgp group int advertise-external set protocols bgp group int neighbor 192.168.0.3 set protocols ospf area 0.0.0.0 interface fe-1/2/1.0 set protocols ospf area 0.0.0.0 interface lo0.0 passive set routing-options router-id 192.168.0.2 set routing-options autonomous-system 200
设备 R3
set interfaces fe-1/2/0 unit 6 family inet address 10.0.0.6/30 set interfaces lo0 unit 0 family inet address 192.168.0.3/32 set protocols bgp group int type internal set protocols bgp group int local-address 192.168.0.3 set protocols bgp group int export send-static set protocols bgp group int neighbor 192.168.0.2 set protocols ospf area 0.0.0.0 interface fe-1/2/0.6 set protocols ospf area 0.0.0.0 interface lo0.0 passive set policy-options policy-statement send-static term 1 from protocol static set policy-options policy-statement send-static term 1 then local-preference 200 set policy-options policy-statement send-static term 1 then accept set routing-options static route 172.16.6.0/24 reject set routing-options static route 0.0.0.0/0 next-hop 10.0.0.5 set routing-options autonomous-system 200
过程
分步程序
下面的示例要求您在各个配置层级中进行导航。有关导航CLI的信息,请参阅《Junos OS CLI 用户指南》中的在配置模式下使用CLI编辑器。
要配置设备 R2:
配置设备接口。
[edit interfaces] user@R2# set fe-1/2/0 unit 0 description to-R1 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 description to-R3 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
配置 OSPF 或其他内部网关协议 (IGP)。
[edit protocols ospf area 0.0.0.0] user@R2# set interface fe-1/2/1.0 user@R2# set interface lo0.0 passive
配置到设备 R1 的 EBGP 连接。
[edit protocols bgp group ext] user@R2# set type external user@R2# set peer-as 100 user@R2# set neighbor 10.0.0.1
配置到设备 R3 的 IBGP 连接。
[edit protocols bgp group int] user@R2# set type internal user@R2# set local-address 192.168.0.2 user@R2# set neighbor 192.168.0.3
将该
advertise-external语句添加到 IBGP 组对等会话。[edit protocols bgp group int] user@R2# set advertise-external
配置自治系统 (AS) 编号和路由器 ID。
[edit routing-options ] user@R2# set router-id 192.168.0.2 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{
description to-R1;
family inet {
address 10.0.0.2/30;
}
}
}
fe-1/2/1 {
unit 0 {
description to-R3;
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 ext {
type external;
peer-as 100;
neighbor 10.0.0.1;
}
group int {
type internal;
local-address 192.168.0.2;
advertise-external;
neighbor 192.168.0.3;
}
}
ospf {
area 0.0.0.0 {
interface fe-1/2/1.0;
interface lo0.0 {
passive;
}
}
}
user@R2# show routing-options router-id 192.168.0.2; autonomous-system 200;
如果完成设备配置,请从配置模式进入。commit
验证
确认配置工作正常。
验证 BGP 活动路径
目的
在设备 R2 上,确保 172.16.6.0/24 前缀位于路由表中,并具有预期的活动路径。
行动
user@R2> show route 172.16.6
inet.0: 8 destinations, 9 routes (8 active, 1 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
172.16.6.0/24 *[BGP/170] 00:00:07, localpref 200, from 192.168.0.3
AS path: I, validation-state: unverified
> to 10.0.0.6 via fe-1/2/1.0
[BGP/170] 03:23:03, localpref 100
AS path: 100 I, validation-state: unverified
> to 10.0.0.1 via fe-1/2/0.0
意义
设备 R2 接收来自设备 R1 和设备 R3 的 172.16.6.0/24 路由。来自设备 R3 的路由是活动路径,由星号 (*) 指定。活动路径具有最高的本地优先级。即使两个路由的本地优先级相等,来自设备 R3 的路由仍将保持活动状态,因为它具有最短的 AS 路径。
验证外部路由通告
目的
在设备 R2 上,确保已向设备 R3 播发 172.16.6.0/24 路由。
行动
user@R2> show route advertising-protocol bgp 192.168.0.3 inet.0: 8 destinations, 9 routes (8 active, 1 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path 172.16.6.0/24 10.0.0.1 100 100 I
意义
设备 R2 正在向设备 R3 播发 172.16.6.0/24 路由。
验证设备 R3 上的路由
目的
确保 172.16.6.0/24 前缀位于设备 R3 的路由表中。
行动
user@R3> show route 172.16.6.0/24
inet.0: 7 destinations, 8 routes (7 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
172.16.6.0/24 *[Static/5] 03:34:14
Reject
[BGP/170] 06:34:43, localpref 100, from 192.168.0.2
AS path: 100 I, validation-state: unverified
> to 10.0.0.5 via fe-1/2/0.6
意义
设备 R3 具有 172.16.6.0/24 的静态路由和 BGP 路由。
请注意,如果路由无法访问或下一跃点无法解析,则设备 R3 上将隐藏 BGP 路由。为了满足此要求,此示例在设备 R3 ()static route 0.0.0.0/0 next-hop 10.0.0.5 上包含静态默认路由。
试验条件选项
目的
查看该 conditional 选项在 BGP 路径选择算法环境中的工作原理。
行动
在设备 R2 上,添加该
conditional选项。[edit protocols bgp group int] user@R2# set advertise-external conditional user@R2# commit
在设备 R2 上,检查是否向设备 R3 播发了 172.16.6.0/24 路由。
user@R2> show route advertising-protocol bgp 192.168.0.3
正如预期一样,不再对路由进行播发。您可能需要等待几秒钟才能看到此结果。
在设备 R3 上,停用策略
then local-preference操作。[edit policy-options policy-statement send-static term 1] user@R3# deactivate logical-systems R3 then local-preference user@R3# commit
在设备 R2 上,确保两个路径的本地优先级相等。
user@R2> show route 172.16.6.0/24 inet.0: 8 destinations, 9 routes (8 active, 0 holddown, 0 hidden) + = Active Route, - = Last Active, * = Both 172.16.6.0/24 *[BGP/170] 08:02:59, localpref 100 AS path: 100 I, validation-state: unverified > to 10.0.0.1 via fe-1/2/0.0 [BGP/170] 00:07:51, localpref 100, from 192.168.0.3 AS path: I, validation-state: unverified > to 10.0.0.6 via fe-1/2/1.0在设备 R2 上,添加语
as-path-ignore句。[edit protocols bgp] user@R2# set path-selection as-path-ignore user@R2# commit
在设备 R2 上,检查是否向设备 R3 播发了 172.16.6.0/24 路由。
user@R2> show route advertising-protocol bgp 192.168.0.3 inet.0: 8 destinations, 9 routes (8 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 172.16.6.0/24 10.0.0.1 100 100 I
正如预期一样,路由现已播发,因为 AS 路径长度被忽略,并且本地优先级相等。
优化 BGP 配置以加快 Junos 中的融合速度
Junos OS 中的 BGP 包括多项功能,旨在在发生故障或拓扑更改后快速恢复流量转发。其中包括 BGP 核心保护(PIC 边缘)、eBGP 快速重新路由 (FRR)、状态压缩和平滑重启。但是,在某些情况下,需要完全的协议融合才能恢复流量。以下建议将帮助您优化 BGP 配置,以实现最快的融合。
建议
使用相同的逻辑跨对等节点重复使用单个策略。
避免创建逻辑相同但名称不同的多个策略。相反,对多个对等方重复使用单个策略。
当对等方共享类似逻辑时,合并策略。
如果多个 BGP 对等方共享相同的核心策略逻辑,则可以通过将其规则合并到单个导出策略中(而不是维护单独的特定于对等方的策略)来优化策略管理。这种方法降低了配置复杂性,提高了可扩展性。
示例:
不要为每个对等方配置单独的导出策略:
set policy-options policy-statement <export-peer1> term 1 from community <community-1> set policy-options policy-statement <export-peer1> then accept set policy-options policy-statement <export-peer2> term 1 from community <community-1> set policy-options policy-statement <export-peer2> then accept
您可以将它们合并到单个导出策略中:
set policy-options policy-statement <export-common> term 1 from community <community-1> set policy-options policy-statement <export-common> then accept set protocols bgp group <peers> export <export-common>
在组级别配置导出策略。
- 不要为每个邻居配置导出策略,例如:
set protocols bgp group <foo> neighbor 192.168.1.1 export <policy-1> set protocols bgp group <foo> neighbor 192.168.1.2 export <policy-2>
相反,请在组级别为共享相同导出策略的所有邻接方配置策略:
set protocols bgp group <foo> export <common-policy>
注意:如果在 BGP 组中应用了不同的每个邻接方导出策略,Junos OS 将触发 组拆分,强制受影响的对等方离开组并重置其会话。这可能会中断流量并导致意外行为。为避免这种情况,请始终确保在组级别应用一致策略,除非需要显式的每个邻居覆盖。
- 不要为每个邻居配置导出策略,例如:
启用路径 MTU 发现或设置 TCP MSS 以避免 IP 分段。
要优化 BGP 会话性能并防止 IP 分段,您应该:
- 启用路径 MTU 发现 (PMTUD)。
手动将 TCP 最大分段大小 (MSS) 配置为最佳值。
配置命令:
- 为 BGP 会话启用路径 MTU 发现 (PMTUD):
set protocols bgp group <external> mtu-discovery
这允许路由器根据网络状况动态调整 BGP 会话的 MTU 大小。
为 BGP 会话设置手册 TCP MSS 值(例如 1400 字节):
set protocols bgp group <external> tcp-mss 1400
这可以手动限制 TCP 分段大小,从而防止在 PMTUD 被禁用或不可靠时出现分段。
注意:最佳做法是尽可能使用 PMTUD,但如果网络阻止 PMTUD 所需的 ICMP 消息,请根据网络 MTU 手动设置适当的 TCP MSS 值。在 BGP 对等方之间的所有接口和链路上配置较大的 MTU。
确保对等方之间的每个接口和链路都支持较大的 MTU,以优化性能。
注意事项
导出策略更改可能会触发会话重置。
-
在 Junos OS 中,如果共享 Adj-RIB-Out 中一个对等方的导出策略发生变化,Junos 会将对等方移动到其他(或新的)Adj-RIB-Out。此转换将重置该对等方的 BGP 会话。
-
此重置可能会造成破坏,特别是对于播发大量前缀的对等方(例如,上行链路提供商)。
-
建议:如果避免会话重置至关重要,请考虑通过配置单独的 BGP 组来创建专用的 Adj-RIB-out。这种权衡可以提高稳定性,但可能会影响路径处理性能。
也可以看看
示例:配置基于 BGP 前缀的出站路由过滤
此示例说明如何配置瞻博网络路由器以接受来自远程对等方的路由过滤器,并使用收到的过滤器执行出站路由过滤。
要求
开始之前:
配置路由器接口。
配置内部网关协议 (IGP)。
概述
您可以将 BGP 对等体配置为接受来自远程对等方的路由过滤器,并使用收到的过滤器执行出站路由过滤。通过过滤掉不需要的更新,发送对等方可以节省生成和传输更新所需的资源,接收对等方可以节省处理更新所需的资源。例如,在虚拟专用网 (VPN) 中,此功能可能很有用,其中客户边缘 (客户边缘) 设备的子集无法处理 VPN 中的所有路由。客户边缘设备可以使用基于前缀的出站路由过滤与提供商边缘 (PE) 路由设备通信,以便仅传输路由子集,例如仅传输到主数据中心的路由。
BGP 对等体可以接受 的最大基于前缀的出站路由过滤器数为 5000。如果远程对等方向某个对等地址发送超过 5000 个出站路由过滤器,则其他过滤器将被丢弃,并生成系统日志消息。
您可以为整个路由设备配置互操作性,也可以仅为特定的 BGP 组或对等方配置互操作性。
配置
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,然后将命令复制并粘贴到层次结构级别的 [edit] CLI 中。
PE1
set protocols bgp group cisco-peers type external set protocols bgp group cisco-peers description “to CE1” set protocols bgp group cisco-peers local-address 192.168.165.58 set protocols bgp group cisco-peers peer-as 35 set protocols bgp group cisco-peers outbound-route-filter bgp-orf-cisco-mode set protocols bgp group cisco-peers outbound-route-filter prefix-based accept inet set protocols bgp group cisco-peers neighbor 192.168.165.56 set routing-options autonomous-system 65500
过程
分步程序
下面的示例要求您在各个配置层级中进行导航。有关导航CLI的信息,请参阅《Junos OS CLI 用户指南》中的在配置模式下使用CLI编辑器。
要将路由器 PE1 配置为接受来自设备 CE1 的路由过滤器,并使用收到的过滤器执行出站路由过滤:
配置本地自治系统。
[edit routing-options] user@PE1# set autonomous-system 65500
配置与设备 CE1 的外部对等。
[edit protocols bgp group cisco-peers] user@PE1# set type external user@PE1# set description “to CE1” user@PE1# set local-address 192.168.165.58 user@PE1# set peer-as 35 user@PE1# set neighbor 192.168.165.56
将路由器 PE1 配置为接受来自设备 CE1 的 IPv4 路由过滤器,并使用收到的过滤器执行出站路由过滤。
[edit protocols bgp group cisco-peers] user@PE1# set outbound-route-filter prefix-based accept inet
(选答)与使用供应商特定兼容性代码 130 进行出站路由过滤器且代码类型 128 的路由设备实现互操作性。
IANA标准代码为 3,标准代码类型为 64。
[edit protocols bgp group cisco-peers] user@PE1# set outbound-route-filter bgp-orf-cisco-mode
结果
在配置模式下,输入和show protocolsshow routing-options命令以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明以更正配置。
user@PE1# show protocols
group cisco-peers {
type external;
description “to CE1”;
local-address 192.168.165.58;
peer-as 35;
outbound-route-filter {
bgp-orf-cisco-mode;
prefix-based {
accept {
inet;
}
}
}
neighbor 192.168.165.56;
}
user@PE1# show routing-options autonomous-system 65500;
如果完成设备配置,请从配置模式进入。commit
验证
确认配置工作正常。
验证出站路由过滤器
目的
显示有关从设备 CE1 接收的基于前缀的出站路由过滤器的信息。
行动
在操作模式下,输入命令 show bgp neighbor orf detail 。
user@PE1> show bgp neighbor orf 192.168.165.56 detail
Peer: 192.168.165.56 Type: External
Group: cisco-peers
inet-unicast
Filter updates recv: 4 Immediate: 0
Filter: prefix-based receive
Updates recv: 4
Received filter entries:
seq 10 2.2.0.0/16 deny minlen 0 maxlen 0
seq 20 3.3.0.0/16 deny minlen 24 maxlen 0
seq 30 4.4.0.0/16 deny minlen 0 maxlen 28
seq 40 5.5.0.0/16 deny minlen 24 maxlen 28
验证 BGP 邻接方模式
目的
确保命令输出中show bgp neighbor显示该选项,以ORFCiscoMode验证是否已为对等方启用该bgp-orf-cisco-mode设置。
行动
在操作模式下,输入命令 show bgp neighbor 。
user@PE1> show bgp neighbor Peer: 192.168.165.56 AS 35 Local: 192.168.165.58 AS 65500 Type: External State: Active Flags: <> Last State: Idle Last Event: Start Last Error: None Export: [ adv_stat ] Options: <Preference LocalAddress AddressFamily PeerAS Refresh> Options: <ORF ORFCiscoMode> Address families configured: inet-unicast Local Address: 192.168.165.58 Holdtime: 90 Preference: 170 Number of flaps: 0 Trace options: detail open detail refresh Trace file: /var/log/orf size 5242880 files 20
了解数据包传输路由器(PTX 系列)上的默认 BGP 路由策略
在 PTX 系列数据包传输路由器上,默认 BGP 路由策略不同于其他 Junos OS 路由设备。PTX 系列 3000 和 5000 系列路由器的默认路由策略不会在转发表中安装 BGP 路由,除非您配置其他策略来覆盖它。所有其他 PTX 系列路由器都可以将 BGP 获知的路由安装到转发信息库 (FIB) 和数据包处理引擎 (PFE),而无需制定策略。
PTX 系列路由器是执行 IP 转发的 MPLS 传输平台,通常使用内部网关协议 (IGP) 路由。PTX 系列数据包转发引擎可以容纳相对较少数量的可变长度前缀。
PTX 系列路由器可以在控制平面中支持完整的 BGP 路由,因此可用作路由反射器 (RR)。它可以执行精确长度的查找组播转发,并且可以构建组播转发平面供单播控制平面使用(例如,对组播执行反向路径转发查找)。
鉴于 PFE 限制,PTX 系列路由器的默认路由策略是不将 BGP 路由安装在转发表中。您可以覆盖默认路由策略,并选择要在转发表中安装的某些 BGP 路由。
PTX 系列路由器上负载平衡和 BGP 路由的默认行为如下。它具有以下理想的特性:
允许您覆盖默认行为,而无需直接更改默认策略
减少因意外更改而使默认值无效的可能性
不设置流控制操作,如接受和拒绝
PTX 系列路由器上的默认路由策略如下:
user@host# show policy-options | display inheritance defaults no-comments
policy-options {
policy-statement junos-ptx-series-default {
term t1 {
from {
protocol bgp;
rib inet.0;
}
then no-install-to-fib;
}
term t2 {
from {
protocol bgp;
rib inet6.0;
}
then no-install-to-fib;
}
term t3 {
then load-balance per-packet;
}
}
}
routing-options {
forwarding-table {
default-export junos-ptx-series-default;
}
}
user@host# show routing-options forwarding-table default-export | display inheritance defaults no-comments
default-export junos-ptx-series-default;
如下所示,junos-ptx-series-default策略在 中[edit policy-options]定义。使用语句在 default-export 中应用[edit routing-options forwarding-table]策略。您可以使用该标志查看| display inheritance这些默认配置。
此外,您还可以使用该 show policy 命令查看默认策略。
user@host> show policy junos-ptx-series-default
Policy junos-ptx-series-default:
Term t1:
from proto BGP
inet.0
then install-to-fib no
Term t2:
from proto BGP
inet6.0
then install-to-fib no
Term t3:
then load-balance per-packet
强烈建议不要直接更改 junos-ptx-series-default 路由策略。
Junos OS 将策略与任何用户配置的导出策略链接起来 junos-ptx-series-default 。由于策略 junos-ptx-series-default 不使用流控制操作,因此将为每个路由执行您配置的任何导出策略(通过隐式的下一个策略操作)。因此,您可以覆盖策略设置的任何 junos-ptx-series-default 操作。如果未配置导出策略,则策略设置的 junos-ptx-series-default 操作是唯一的操作。
您可以使用策略操作 install-to-fib 来覆盖该 no-install-to-fib 操作。
同样,您可以将操作设置为 load-balance per-prefix 覆盖 load-balance per-packet 操作。
也可以看看
示例:覆盖 PTX 系列数据包传输路由器上的默认 BGP 路由策略
此示例说明如何覆盖数据包传输路由器(如 PTX 系列数据包传输路由器)上的默认路由策略。
要求
此示例需要 Junos OS 12.1 或更高版本。
概述
默认情况下,PTX 系列路由器不会在转发表中安装 BGP 路由。
对于 PTX 系列路由器,使用操作配置条件then accept时from protocols bgp,不会产生与其他 Junos OS 路由设备上的通常结果。在 PTX 系列路由器上使用以下路由策略时,BGP 路由不会安装在转发表中。
user@host# show policy-options
policy-statement accept-no-install {
term 1 {
from protocol bgp;
then accept;
}
}
user@host# show routing-options
forwarding-table {
export accept-no-install;
}
user@host> show route forwarding-table Routing table: default.inet Internet: Destination Type RtRef Next hop Type Index NhRef Netif default perm 0 rjct 36 2
转发表中未安装任何 BGP 路由。这是预期行为。
此示例说明如何使用该 then install-to-fib 操作有效地覆盖默认 BGP 路由策略。
配置
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,然后将命令复制并粘贴到层次结构级别的 [edit] CLI 中。
set policy-options prefix-list install-bgp 66.0.0.1/32 set policy-options policy-statement override-ptx-series-default term 1 from prefix-list install-bgp set policy-options policy-statement override-ptx-series-default term 1 then load-balance per-prefix set policy-options policy-statement override-ptx-series-default term 1 then install-to-fib set routing-options forwarding-table export override-ptx-series-default
在转发表中安装选定的 BGP 路由
分步程序
下面的示例要求您在各个配置层级中进行导航。有关导航CLI的信息,请参阅《Junos OS CLI 用户指南》中的在配置模式下使用CLI编辑器。
要在转发表中安装选定的 BGP 路由,请执行以下操作:
配置要安装在转发表中的前缀列表。
[edit policy-options prefix-list install-bgp] user@host# set 66.0.0.1/32
配置路由策略,将前缀列表应用为条件。
[edit policy-options policy-statement override-ptx-series-default term 1] user@host# set from prefix-list install-bgp user@host# set then install-to-fib user@host# set then load-balance per-prefix
将路由策略应用于转发表。
[edit routing-options forwarding-table] user@host# set export override-ptx-series-default
结果
在配置模式下,输入和show policy-optionsshow routing-options命令以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明以更正配置。
user@host# show policy-options
prefix-list install-bgp {
66.0.0.1/32;
}
policy-statement override-ptx-series-default {
term 1 {
from {
prefix-list install-bgp;
}
then {
load-balance per-prefix;
install-to-fib;
}
}
}
user@host# show routing-options
forwarding-table {
export override-ptx-series-default;
}
如果完成设备配置,请从配置模式进入。commit
验证
确认配置工作正常。
验证所选路由是否已安装在转发表中
目的
确保配置的策略覆盖默认策略。
行动
在操作模式下,输入命令 show route forwarding-table 。
user@host> show route forwarding-table destination 66.0.0.1
Internet:
Destination Type RtRef Next hop Type Index NhRef Netif
66.0.0.1/32 user 0 indr 2097159 3
ulst 2097156 2
5.1.0.2 ucst 574 1 et-6/0/0.1
5.2.0.2 ucst 575 1 et-6/0/0.2
意义
此输出显示到 66.0.0.1/32 的路由已安装在转发表中。
条件播发,启用前缀的条件安装用例
网络通常细分为更易于管理的小型单元,称为自治系统 (AS)。当路由器使用 BGP 在同一AS中形成对等关系时,该关系称为内部BGP (IBGP)。当路由器使用 BGP 在不同的 AS 中形成对等关系时,该 BGP 称为外部 BGP (EBGP)。
执行路由完整性检查后,BGP 路由器接受从其对等方接收的路由,并将其安装到路由表中。默认情况下,IBGP 和 EBGP 会话中的所有路由器都遵循标准 BGP 播发规则。IBGP 会话中的路由器仅播发从其直接对等方获知的路由,而 EBGP 会话中的路由器会播发从其直接和间接对等方(对等方的对等方)获知的所有路由。因此,在配置了 EBGP 的典型网络中,路由器会将从 EBGP 对等方接收到的所有路由添加到其路由表中,并将几乎所有路由通告所有 EBGP 对等方。
服务提供商在互联网上与客户和对等方交换 BGP 路由,可能会面临恶意和意外威胁的风险,这些威胁可能会损害流量的正确路由以及路由器的运行。
这有几个缺点:
Non-aggregated route advertisements— 客户可能会错误地将其所有前缀(而不是其地址空间的聚合)播发给 ISP。鉴于互联网路由表的大小,必须仔细控制。边缘路由器可能还只需要一条通向互联网的默认路由,而是从其上游对等方接收整个 BGP 路由表。
BGP route manipulation— 如果恶意管理员更改了 BGP 路由表的内容,则可能会阻止流量到达其预期目标。
BGP route hijacking— BGP 对等体的恶意管理员可能会恶意通告网络的前缀,试图将用于受害网络的流量重新路由到管理员的网络,以访问流量内容或阻止受害人的在线服务。
BGP denial of service (DoS)- 如果恶意管理员向路由器发送意外或不需要的 BGP 流量,试图使用路由器的所有可用 BGP 资源,则可能会导致路由器处理有效 BGP 路由信息的能力受损。
前缀的条件安装可用于解决前面提到的所有问题。如果客户需要访问远程网络,则可以在与远程网络连接的路由器的路由表中安装特定路由。这在典型的 EBGP 网络中不会发生,因此,前缀的有条件安装变得至关重要。
AS 不但受物理关系约束,而且还受业务或其他组织关系的约束。AS 可以向其他组织提供服务,或充当其他两个 AS 之间的过渡 AS。这些中转 AS 受双方之间合同协议的约束,这些协议包括有关如何相互连接的参数,最重要的是,它们相互承载的流量类型和数量。因此,出于法律和财务原因,服务提供商必须实施相应策略来控制如何与邻接方交换 BGP 路由、从这些邻接方接受哪些路由,以及这些路由如何影响 AS 之间的流量。
有许多不同的选项可用于过滤从 BGP 对等体接收的路由,以实施 AS 间策略并降低接收潜在有害路由的风险。传统的路由过滤会检查路由的属性,并根据这些属性接受或拒绝路由。策略或过滤器可以检查 AS 路径、下一跃点值、社区值、前缀列表、路由地址族等的内容。
在某些情况下,匹配特定属性值的标准“接受条件”是不够的。服务提供商可能需要在路由本身之外使用另一个条件,例如,路由表中的另一个路由。例如,最好安装从上游对等方接收的默认路由,前提是可以验证此对等方是否可访问上游的其他网络。此条件路由安装可避免安装用于向此对等方发送流量的默认路由,此路由可能会在对等方上游丢失路由,从而导致流量黑洞化。为此,可以将路由器配置为搜索路由表中是否存在特定路由,并在此知识的基础上接受或拒绝其他前缀。
示例:为条件播发配置路由策略 在路由表中启用前缀的条件安装 说明如何配置和验证前缀的条件安装。
也可以看看
条件播发和导入策略(路由表)具有某些匹配条件
BGP 接受从邻接方获知的所有非环路路由,并将其导入 RIB-In 表中。如果 BGP 导入策略接受这些路由,则将其导入 inet.0 路由表。如果只需要导入某些路由,则可以进行调配,以便对等路由设备根据一个条件或一组条件导出路由。
导出路由的条件可以基于:
从中获知路由的对等方
在某个接口上获知了路由
其他一些必需属性
例如:
[edit]
policy-options {
condition condition-name {
if-route-exists address table table-name;
}
}
这称为前缀的条件安装,详见 示例:为条件播发配置路由策略 在路由表中启用前缀的条件安装。
可以配置路由策略中的条件,而不论它们是导出策略或导入策略的一部分,还是两者兼而有之。导出策略支持这些根据路由策略中存在其他路由继承自路由策略的条件。但是,导入策略不支持这些条件,即使存在这些条件,也不会执行这些条件。
图 4 说明了 BGP 导入和导出策略的应用位置。导入策略将应用于命令输出 show route receive-protocol bgp neighbor-address 中可见的入站路由。导出策略将应用于命令输出 show route advertising-protocol bgp neighbor-address 中可见的出站路由。
要启用前缀的条件安装,必须在必须进行前缀导出的设备上配置导出策略。导出策略评估每个路由,以验证其是否满足语句下的所有 from 匹配条件。它还会搜索是否存在在语句下 condition 定义的路由(也在语句下 from 配置)。
如果路由与策略中定义的整组必需条件不匹配,或者在该语句下 condition 定义的路由不存在于路由表中,则不会将路由导出到其 BGP 对等方。因此,条件导出策略将匹配您希望安装在对等方路由表中的所需路由或前缀的路由。
要借助导出策略配置前缀的条件安装:
创建
condition语句以检查前缀。[edit] policy-options { condition condition-name { if-route-exists address table table-name; } }使用语句使用
condition新创建的条件创建导出策略。[edit] policy-options { policy-statement policy-name { term 1 { from { protocols bgp; condition condition-name; } then { accept; } } } }将导出策略应用于仅要求从路由表导出选定前缀的设备。
[edit] protocols bgp { group group-name { export policy-name; } }
也可以看看
示例:为条件播发配置路由策略,以便在路由表中启用前缀的条件安装
此示例说明如何使用 BGP 导出策略在路由表中配置前缀的条件安装。
要求
此示例使用以下硬件和软件组件:
M Series 多服务边缘路由器、MX 系列 5G 通用路由平台或 T Series 核心路由器
Junos OS 9.0 或更高版本
概述
在此示例中,三个不同自治系统 (AS) 中的三台路由器通过 BGP 协议连接和配置。标记为Internet的路由器是上游路由器,其lo0.0环路接口上配置了五个地址(172.16.11.1/32、172.16.12.1/32、172.16.13.1/32、172.16.14.1/32和172.16.15.1/32),并将一个额外的环路地址(192.168.9.1/32)配置为路由器ID。这六个地址将导出到 BGP 中,以模拟连接到互联网的路由器的 BGP 路由表的内容,并向北方通告。
北路由器和南路由器分别使用 10.0.89.12/30 和 10.0.78.12/30 网络,并将 192.168.7.1 和 192.168.8.1 用作各自的环路地址。
图 5 显示了此示例中使用的拓扑。
的条件安装
路由器 North 将其从路由器互联网获知的 172.16.0.0/16 BGP 路由导出到路由器 South。这些路由可能表示互联网路由器的域所拥有的路由。此外,当存在特定的 172.16.11.1/32 路由时,路由器 North 也会播发默认路由。172.16.11.1 路由可能表示互联网路由器与提供完整互联网连接的第 1 层传输对等互连提供商的链接。
路由器 South 接收所有六个路由,但应仅在其路由表中安装默认路由和另一个特定路由 (172.16.11.1/32)。
总而言之,该示例满足以下要求:
-
在北上,发送所有 172.16/16 前缀。此外,仅当inet.0路由表中存在特定路由时,才将0/0发送到南(在本例中为172.16.11.1/32)。
-
在南方,接受并安装路由和转发表中的默认路由和 172.16.11.1/32 路由。丢弃所有其他路由。考虑到 South 可能是无法接受完整互联网路由表的低端设备。因此,运维人员只希望 South 具有默认路由和一个其他特定前缀。
第一个要求是通过北方的出口策略来满足的:
user@North# show policy-options
policy-statement conditional-export-bgp {
term prefix_11 {
from {
protocol bgp;
route-filter 172.16.0.0/16 orlonger;
}
then accept;
}
term conditional-default {
from {
route-filter 0.0.0.0/0 exact;
condition prefix_11;
}
then accept;
}
term others {
then reject;
}
}
condition prefix_11 {
if-route-exists {
172.16.11.1/32;
table inet.0;
}
}
条件导出策略的逻辑可以总结如下:如果存在 0/0,并且如果存在 172.16.11.1/32,则发送 0/0 前缀。这意味着如果 172.16.11.1/32 不存在,则不要发送 0/0。
第二个要求是通过对南方的进口政策来满足的:
user@South# show policy-options
policy-statement import-selected-routes {
term 1 {
from {
rib inet.0;
neighbor 10.0.78.14;
route-filter 0.0.0.0/0 exact;
route-filter 172.16.11.1/32 exact;
}
then accept;
}
term 2 {
then reject;
}
}
在此示例中,由于“南”上的导入策略而丢弃了四个路由。这是因为北侧的导出策略会泄露从互联网接收的所有路由,而南侧的导入策略会排除其中一些路由。
需要了解的是,在 Junos OS 中,尽管导入策略(入站路由过滤器)可能会拒绝路由,不将其用于流量转发,并且不将其包含在发送给其他对等方的播发中,但路由器仍会将这些路由保留为隐藏路由。这些隐藏路由无法用于策略或路由目的。但是,它们确实占用路由器上的内存空间。过滤路由以控制保留在内存中并由路由器处理的信息量的服务提供商可能希望路由器完全丢弃被导入策略拒绝的路由。
可以使用命令show route receive-protocol bgp neighbor-address hidden查看隐藏的路径。然后,通过在 or [edit protocols bgp group group-name] 层次结构级别配置[edit protocols bgp]该语句,keep all | none可以从路由表中保留或删除隐藏路由。
BGP路由保留规则如下:
-
默认情况下,从 BGP 获知的所有路由都将保留,但 AS 路径被循环的路由除外。(AS 路径包含本地 AS。)
-
通过配置该
keep all语句,从 BGP 获知的所有路由都将保留,即使在 AS 路径中有本地 AS 的路由也是如此。 -
通过配置该
keep none语句,BGP 会丢弃从对等方收到的路由,以及被导入策略或其他健全性检查拒绝的路由。配置此语句且入站策略发生变化后,Junos OS 将重新播发对等方播发的所有路由。
配置或keep none和对等方支持路由刷新时keep all,本地发送方会发送刷新消息并执行导入评估。对于这些对等方,会话不会重新启动。要确定对等方是否支持刷新,请检查命令输出show bgp neighbor中的 。Peer supports Refresh capability
如果配置 keep all 或 keep none ,并且对等方不支持会话重新启动,则关联的 BGP 会话将重新启动(翻动)。
拓扑结构
配置
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,然后将命令复制并粘贴到层次结构级别的 [edit] CLI 中。
路由器互联网
set interfaces lo0 unit 0 family inet address 172.16.11.1/32 set interfaces lo0 unit 0 family inet address 172.16.12.1/32 set interfaces lo0 unit 0 family inet address 172.16.13.1/32 set interfaces lo0 unit 0 family inet address 172.16.14.1/32 set interfaces lo0 unit 0 family inet address 172.16.15.1/32 set interfaces lo0 unit 0 family inet address 192.168.9.1/32 set interfaces fe-0/1/3 unit 0 family inet address 10.0.89.14/30 set protocols bgp group toNorth local-address 10.0.89.14 set protocols bgp group toNorth peer-as 65200 set protocols bgp group toNorth neighbor 10.0.89.13 set protocols bgp group toNorth export into-bgp set policy-options policy-statement into-bgp term 1 from interface lo0.0 set policy-options policy-statement into-bgp term 1 then accept set routing-options router-id 192.168.9.1 set routing-options autonomous-system 65300
路由器北
set interfaces fe-1/3/1 unit 0 family inet address 10.0.78.14/30 set interfaces fe-1/3/0 unit 0 family inet address 10.0.89.13/30 set interfaces lo0 unit 0 family inet address 192.168.8.1/32 set protocols bgp group toInternet local-address 10.0.89.13 set protocols bgp group toInternet peer-as 65300 set protocols bgp group toInternet neighbor 10.0.89.14 set protocols bgp group toSouth local-address 10.0.78.14 set protocols bgp group toSouth export conditional-export-bgp set protocols bgp group toSouth peer-as 65100 set protocols bgp group toSouth neighbor 10.0.78.13 set policy-options policy-statement conditional-export-bgp term prefix_11 from protocol bgp set policy-options policy-statement conditional-export-bgp term prefix_11 from route-filter 172.16.0.0/16 orlonger set policy-options policy-statement conditional-export-bgp term prefix_11 then accept set policy-options policy-statement conditional-export-bgp term conditional-default from route-filter 0.0.0.0/0 exact set policy-options policy-statement conditional-export-bgp term conditional-default from condition prefix_11 set policy-options policy-statement conditional-export-bgp term conditional-default then accept set policy-options policy-statement conditional-export-bgp term others then reject set policy-options condition prefix_11 if-route-exists 172.16.11.1/32 set policy-options condition prefix_11 if-route-exists table inet.0 set routing-options static route 0/0 reject set routing-options router-id 192.168.8.1 set routing-options autonomous-system 65200
路由器南
set interfaces fe-0/1/2 unit 0 family inet address 10.0.78.13/30 set interfaces lo0 unit 0 family inet address 192.168.7.1/32 set protocols bgp group toNorth local-address 10.0.78.13 set protocols bgp group toNorth import import-selected-routes set protocols bgp group toNorth peer-as 65200 set protocols bgp group toNorth neighbor 10.0.78.14 set policy-options policy-statement import-selected-routes term 1 from neighbor 10.0.78.14 set policy-options policy-statement import-selected-routes term 1 from route-filter 172.16.11.1/32 exact set policy-options policy-statement import-selected-routes term 1 from route-filter 0.0.0.0/0 exact set policy-options policy-statement import-selected-routes term 1 then accept set policy-options policy-statement import-selected-routes term 2 then reject set routing-options router-id 192.168.7.1 set routing-options autonomous-system 65100
配置前缀的条件安装
分步程序
下面的示例要求您在各个配置层级中进行导航。有关导航CLI的信息,请参阅《Junos OS CLI 用户指南》中的在 配置模式下使用CLI编辑器 。
要配置前缀的条件安装:
配置构成三台路由器之间链路的路由器接口。
Router Internet [edit interfaces] user@Internet# set fe-0/1/3 unit 0 family inet address 10.0.89.14/30
Router North [edit interfaces] user@North# set fe-1/3/1 unit 0 family inet address 10.0.78.14/30 user@North# set fe-1/3/0 unit 0 family inet address 10.0.89.13/30
Router South [edit interfaces] user@South# set fe-0/1/2 unit 0 family inet address 10.0.78.13/30
在路由器互联网上配置五个环路接口地址,以模拟从互联网获知的要导入到南路由器路由表中的BGP路由,并配置一个将配置为路由器ID的附加地址(192.168.9.1/32)。
Router Internet [edit interfaces lo0 unit 0 family inet] user@Internet# set address 172.16.11.1/32 user@Internet# set address 172.16.12.1/32 user@Internet# set address 172.16.13.1/32 user@Internet# set address 172.16.14.1/32 user@Internet# set address 172.16.15.1/32 user@Internet# set address 192.168.9.1/32
此外,在路由器北端和南端配置环路接口地址。
Router North [edit interfaces lo0 unit 0 family inet] user@North# set address 192.168.8.1/32
Router South [edit interfaces lo0 unit 0 family inet] user@South# set address 192.168.7.1/32
配置路由器 North 上的静态默认路由以播发至路由器 South。
[edit routing-options] user@North# set static route 0/0 reject
定义从北路由器上的路由表导出前缀的条件。
[edit policy-options condition prefix_11] user@North# set if-route-exists 172.16.11.1/32 user@North# set if-route-exists table inet.0
分别在路由器 Internet 和 North 上定义导出策略(
into-bgp和conditional-export-bgp),以向 BGP 通告路由。注意:确保在导出策略中引用
prefix_11条件(在步骤 4 中配置)。Router Internet [edit policy-options policy-statement into-bgp ] user@Internet# set term 1 from interface lo0.0 user@Internet# set term 1 then accept
Router North [edit policy-options policy-statement conditional-export-bgp] user@North# set term prefix_11 from protocol bgp user@North# set term prefix_11 from route-filter 172,16.0.0/16 orlonger user@North# set term prefix_11 then accept user@North# set term conditional-default from route-filter 0.0.0.0/0 exact user@North# set term conditional-default from condition prefix_11 user@North# set term conditional-default then accept user@North# set term others then reject
在路由器 South 上定义导入策略 (
import-selected-routes),以将路由器 North 播发的某些路由导入其路由表。[edit policy-options policy-statement import-selected-routes ] user@South# set term 1 from neighbor 10.0.78.14 user@South# set term 1 from route-filter 172.16.11.1/32 exact user@South# set term 1 from route-filter 0.0.0.0/0 exact user@South# set term 1 then accept user@South# set term 2 then reject
在所有三台路由器上配置 BGP,以实现自治系统之间的前缀流。
注意:确保将定义的导入和导出策略应用于相应的 BGP 组,以便进行前缀播发。
Router Internet [edit protocols bgp group toNorth] user@Internet# set local-address 10.0.89.14 user@Internet# set peer-as 65200 user@Internet# set neighbor 10.0.89.13 user@Internet# set export into-bgp
Router North [edit protocols bgp group toInternet] user@North# set local-address 10.0.89.13 user@North# set peer-as 65300 user@North# set neighbor 10.0.89.14
[edit protocols bgp group toSouth] user@North# set local-address 10.0.78.14 user@North# set peer-as 65100 user@North# set neighbor 10.0.78.13 user@North# set export conditional-export-bgp
Router South [edit protocols bgp group toNorth] user@South# set local-address 10.0.78.13 user@South# set peer-as 65200 user@South# set neighbor 10.0.78.14 user@South# set import import-selected-routes
为所有三个路由器配置路由器 ID 和自治系统编号。
注意:在此示例中,路由器 ID 是根据路由器的 lo0.0 接口上配置的 IP 地址配置的。
Router Internet [edit routing options] user@Internet# set router-id 192.168.9.1 user@Internet# set autonomous-system 65300
Router North [edit routing options] user@North# set router-id 192.168.8.1 user@North# set autonomous-system 65200
Router South [edit routing options] user@South# set router-id 192.168.7.1 user@South# set autonomous-system 65100
结果
在配置模式下,发出 、 show protocols bgp、 show policy-options和show routing-options命令以show interfaces确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明以更正配置。
设备互联网
user@Internet# show interfaces
fe-0/1/3 {
unit 0 {
family inet {
address 10.0.89.14/30;
}
}
}
lo0 {
unit 0 {
family inet {
address 172.16.11.1/32;
address 172.16.12.1/32;
address 172.16.13.1/32;
address 172.16.14.1/32;
address 172.16.15.1/32;
address 192.168.9.1/32;
}
}
}
user@Internet# show protocols bgp
group toNorth {
local-address 10.0.89.14;
export into-bgp;
peer-as 65200;
neighbor 10.0.89.13;
}
user@Internet# show policy-options
policy-statement into-bgp {
term 1 {
from interface lo0.0;
then accept;
}
}
user@Internet# show routing-options router-id 192.168.9.1; autonomous-system 65300;
设备北
user@North# show interfaces
fe-1/3/1 {
unit 0 {
family inet {
address 10.0.78.14/30;
}
}
}
fe-1/3/0 {
unit 0 {
family inet {
address 10.0.89.13/30;
}
}
}
lo0 {
unit 0 {
family inet {
address 192.168.8.1/32;
}
}
}
user@North# show protocols bgp
group toInternet {
local-address 10.0.89.13;
peer-as 65300;
neighbor 10.0.89.14;
}
group toSouth {
local-address 10.0.78.14;
export conditional-export-bgp;
peer-as 65100;
neighbor 10.0.78.13;
}
user@North# show policy-options
policy-statement conditional-export-bgp {
term prefix_11 {
from {
protocol bgp;
route-filter 172.16.0.0/16 orlonger;
}
then accept;
}
term conditional-default {
from {
route-filter 0.0.0.0/0 exact;
condition prefix_11;
}
then accept;
}
term others {
then reject;
}
}
condition prefix_11 {
if-route-exists {
172.16.11.1/32;
table inet.0;
}
}
user@North# show routing-options
static {
route 0.0.0.0/0 reject;
}
router-id 192.168.8.1;
autonomous-system 65200;
设备南
user@South# show interfaces
fe-0/1/2 {
unit 0 {
family inet {
address 10.0.78.13/30;
}
}
}
lo0 {
unit 0 {
family inet {
address 192.168.7.1/32;
}
}
}
user@South# show protocols bgp
bgp {
group toNorth {
local-address 10.0.78.13;
import import-selected-routes;
peer-as 65200;
neighbor 10.0.78.14;
}
}
user@South# show policy-options
policy-statement import-selected-routes {
term 1 {
from {
neighbor 10.0.78.14;
route-filter 172.16.11.1 exact;
route-filter 0.0.0.0/0 exact;
}
then accept;
}
term 2 {
then reject;
}
}
user@South# show routing-options router-id 192.168.7.1; autonomous-system 65100;
如果完成路由器配置,请从配置模式进入 commit 。
验证
确认配置工作正常。
- 验证 BGP
- 验证从路由器互联网到路由器北的前缀通告
- 验证从路由器北到路由器南的前缀广告
- 验证用于安装前缀的 BGP 导入策略
- 验证从路由器北到路由器南的条件导出
- 验证是否存在被策略隐藏的路由(可选)
验证 BGP
目的
验证是否已在三台路由器之间建立 BGP 会话。
行动
在操作模式下,运行命令 show bgp neighbor neighbor-address 。
检查路由器互联网上的 BGP 会话,以验证路由器 North 是否为邻居。
user@Internet> show bgp neighbor 10.0.89.13 Peer: 10.0.89.13+179 AS 65200 Local: 10.0.89.14+56187 AS 65300 Type: External State: Established Flags: [ImportEval Sync] Last State: OpenConfirm Last Event: RecvKeepAlive Last Error: None Export: [ into-bgp ] Options: [Preference LocalAddress PeerAS Refresh] Local Address: 10.0.89.14 Holdtime: 90 Preference: 170 Number of flaps: 0 Peer ID: 192.168.8.1 Local ID: 192.168.9.1 Active Holdtime: 90 Keepalive Interval: 30 Group index: 0 Peer index: 0 BFD: disabled, down Local Interface: fe-0/1/3.0 NLRI for restart configured on peer: inet-unicast NLRI advertised by peer: inet-unicast NLRI for this session: inet-unicast Peer supports Refresh capability (2) Stale routes from peer are kept for: 300 Peer does not support Restarter functionality NLRI that restart is negotiated for: inet-unicast NLRI of received end-of-rib markers: inet-unicast NLRI of all end-of-rib markers sent: inet-unicast Peer supports 4 byte AS extension (peer-as 65200) Peer does not support Addpath Table inet.0 Bit: 10000 RIB State: BGP restart is complete Send state: in sync Active prefixes: 0 Received prefixes: 0 Accepted prefixes: 0 Suppressed due to damping: 0 Advertised prefixes: 6 Last traffic (seconds): Received 9 Sent 18 Checked 28 Input messages: Total 12 Updates 1 Refreshes 0 Octets 232 Output messages: Total 14 Updates 1 Refreshes 0 Octets 383 Output Queue[0]: 0检查路由器北端的 BGP 会话,以验证路由器互联网是否为邻居。
user@North> show bgp neighbor 10.0.89.14 Peer: 10.0.89.14+56187 AS 65300 Local: 10.0.89.13+179 AS 65200 Type: External State: Established Flags: [ImportEval Sync] Last State: OpenConfirm Last Event: RecvKeepAlive Last Error: None Options: [Preference LocalAddress PeerAS Refresh] Local Address: 10.0.89.13 Holdtime: 90 Preference: 170 Number of flaps: 0 Peer ID: 192.168.9.1 Local ID: 192.168.8.1 Active Holdtime: 90 Keepalive Interval: 30 Group index: 0 Peer index: 0 BFD: disabled, down Local Interface: fe-1/3/0.0 NLRI for restart configured on peer: inet-unicast NLRI advertised by peer: inet-unicast NLRI for this session: inet-unicast Peer supports Refresh capability (2) Stale routes from peer are kept for: 300 Peer does not support Restarter functionality NLRI that restart is negotiated for: inet-unicast NLRI of received end-of-rib markers: inet-unicast NLRI of all end-of-rib markers sent: inet-unicast Peer supports 4 byte AS extension (peer-as 65300) Peer does not support Addpath Table inet.0 Bit: 10001 RIB State: BGP restart is complete Send state: in sync Active prefixes: 6 Received prefixes: 6 Accepted prefixes: 6 Suppressed due to damping: 0 Advertised prefixes: 0 Last traffic (seconds): Received 14 Sent 3 Checked 3 Input messages: Total 16 Updates 2 Refreshes 0 Octets 402 Output messages: Total 15 Updates 0 Refreshes 0 Octets 348 Output Queue[0]: 0
检查这些输出中的以下字段,以验证是否已建立 BGP 会话:
Peer— 检查是否列出了对等 AS 编号。
Local— 检查是否列出了本地 AS 编号。
State—确保值为
Established。如果没有,请再次检查配置并查看show bgp neighbor有关输出字段的更多详细信息。
同样,验证北路由器和南路由器是否彼此形成对等关系。
意义
在三台路由器之间建立 BGP 会话。
验证从路由器互联网到路由器北的前缀通告
目的
验证路由器 North 是否已接收从路由器 Internet 发送的路由。
行动
在路由器互联网上的操作模式下,运行
show route advertising-protocol bgp neighbor-address命令。user@Internet> show route advertising-protocol bgp 10.0.89.13 inet.0: 8 destinations, 8 routes (8 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 172.16.11.1/32 Self I * 172.16.12.1/32 Self I * 172.16.13.1/32 Self I * 172.16.14.1/32 Self I * 172.16.15.1/32 Self I * 192.168.9.1/32 Self I
输出验证路由器互联网是否将路由 172.16.11.1/32、172.16.12.1/32、172.16.13.1/32、172.16.14.1/32、172.16.15.1/32 和 192.168.9.1/32(用作路由器 ID 的环路地址)播发至路由器北。
在路由器 North 上的操作模式下,运行
show route receive-protocol bgp neighbor-address命令。user@North> show route receive-protocol bgp 10.0.89.14 inet.0: 12 destinations, 12 routes (12 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 172.16.11.1/32 10.0.89.14 65300 I * 172.16.12.1/32 10.0.89.14 65300 I * 172.16.13.1/32 10.0.89.14 65300 I * 172.16.14.1/32 10.0.89.14 65300 I * 172.16.15.1/32 10.0.89.14 65300 I * 192.168.9.1/32 10.0.89.14 65300 I
输出验证路由器 North 是否已收到路由器互联网播发的所有路由。
意义
路由器互联网发送的前缀已成功安装到路由器北上的路由表中。
验证从路由器北到路由器南的前缀广告
目的
验证从路由器 Internet 收到的路由和静态默认路由是否已由路由器 North 播发至路由器 South。
行动
在路由器 North 上的操作模式下,运行
show route 0/0 exact命令。user@North> show route 0/0 exact inet.0: 12 destinations, 12 routes (12 active, 0 holddown, 0 hidden) + = Active Route, - = Last Active, * = Both 0.0.0.0/0 *[Static/5] 00:10:22 Reject输出验证路由器北上的路由表中是否存在静态默认路由 (0.0.0.0/0)。
在路由器 North 上的操作模式下,运行
show route advertising-protocol bgp neighbor-address命令。user@North> show route advertising-protocol bgp 10.0.78.13 inet.0: 12 destinations, 12 routes (12 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 0.0.0.0/0 Self I * 172.16.11.1/32 Self 65300 I * 172.16.12.1/32 Self 65300 I * 172.16.13.1/32 Self 65300 I * 172.16.14.1/32 Self 65300 I * 172.16.15.1/32 Self 65300 I
输出验证路由器 North 是否正在向路由器 South 播发静态路由和从路由器互联网接收的 172.16.11.1/32 路由以及许多其他路由。
验证用于安装前缀的 BGP 导入策略
目的
验证 BGP 导入策略是否成功安装了所需的前缀。
行动
通过检查路由器北的静态默认路由和路由器南的 172.16.11.1/32 路由是否安装在路由器南路由表中,查看路由器南上的导入策略是否可操作。
在操作模式下,运行命令 show route receive-protocol bgp neighbor-address 。
user@South> show route receive-protocol bgp 10.0.78.14 inet.0: 10 destinations, 11 routes (6 active, 0 holddown, 4 hidden) Prefix Nexthop MED Lclpref AS path * 0.0.0.0/0 10.0.78.14 65200 I * 172.16.11.1/32 10.0.78.14 65200 65300 I
输出验证 BGP 导入策略是否在路由器 South 上运行,并且只有来自路由器 North 的静态默认路由 0.0.0.0/0 和来自路由器 Internet 的 172.16.11.1/32 路由泄漏到路由器 South 上的路由表中。
意义
由于配置了 BGP 导入策略,前缀安装成功。
验证从路由器北到路由器南的条件导出
目的
验证当设备互联网停止发送 172.16.11.1/32 路由时,设备北端是否停止发送默认的 0/0 路由。
行动
通过停用 环路 接口上的 172.16.11.1/32 地址,导致设备互联网停止发送 172.16.11.1/32 路由。
[edit interfaces lo0 unit 0 family inet] user@Internet# deactivate address 172.16.11.1/32 user@Internet# commit
在路由器 North 上的操作模式下,运行
show route advertising-protocol bgp neighbor-address命令。user@North> show route advertising-protocol bgp 10.0.78.13 inet.0: 11 destinations, 11 routes (11 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 172.16.12.1/32 Self 65300 I * 172.16.13.1/32 Self 65300 I * 172.16.14.1/32 Self 65300 I * 172.16.15.1/32 Self 65300 I
输出验证路由器 North 是否未向路由器 South 播发默认路由。当 172.16.11.1/32 路由不存在时,这是预期行为。
在设备互联网的环路接口上重新激活 172.16.11.1/32 地址。
[edit interfaces lo0 unit 0 family inet] user@Internet# activate address 172.16.11.1/32 user@Internet# commit
验证是否存在被策略隐藏的路由(可选)
目的
验证是否存在由路由器 South 上配置的导入策略隐藏的路由。
本部分演示可根据需要对配置进行各种更改的效果。
行动
通过以下方式查看从南路由器路由表中隐藏的路由:
使用
hidden命令的show route receive-protocol bgp neighbor-address选项。停用导入策略。
在操作模式下,运行命令
show route receive-protocol bgp neighbor-address hidden以查看隐藏路由。user@South> show route receive-protocol bgp 10.0.78.14 hidden inet.0: 10 destinations, 11 routes (6 active, 0 holddown, 4 hidden) Prefix Nexthop MED Lclpref AS path 172.16.12.1/32 10.0.78.14 65200 65300 I 172.16.13.1/32 10.0.78.14 65200 65300 I 172.16.14.1/32 10.0.78.14 65200 65300 I 172.16.15.1/32 10.0.78.14 65200 65300 I
输出验证路由器南端是否存在导入策略(172.16.12.1/32、172.16.13.1/32、172.16.14.1/32 和 172.16.15.1/32)隐藏的路由。
通过在层次结构级别配置
[edit protocols bgp group group-name]语句来deactivate import停用 BGP 导入策略。[edit protocols bgp group toNorth] user@South# deactivate import user@South# commit
停用导入策略后,运行
show route receive-protocol bgp neighbor-address操作模式命令以检查路由。user@South> show route receive-protocol bgp 10.0.78.14 inet.0: 10 destinations, 11 routes (10 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 0.0.0.0/0 10.0.78.14 65200 I * 172.16.11.1/32 10.0.78.14 65200 65300 I * 172.16.12.1/32 10.0.78.14 65200 65300 I * 172.16.13.1/32 10.0.78.14 65200 65300 I * 172.16.14.1/32 10.0.78.14 65200 65300 I * 172.16.15.1/32 10.0.78.14 65200 65300 I
输出验证是否存在以前隐藏的路由(172.16.12.1/32、172.16.13.1/32、172.16.14.1/32 和 172.16.15.1/32)。
激活 BGP 导入策略,并通过在层次结构级别分别
[edit protocols bgp group group-name]配置activate importandkeep none语句,从路由表中删除隐藏路由。[edit protocols bgp group toNorth] user@South# activate import user@South# set keep none user@South# commit
在操作模式下,
show route receive-protocol bgp neighbor-address hidden激活导入策略并配置keep none语句后,运行命令以检查路由。user@South> show route receive-protocol bgp 10.0.78.14 hidden inet.0: 6 destinations, 7 routes (6 active, 0 holddown, 0 hidden)
输出验证由于配置
keep none了语句,路由表中是否未保留隐藏路由。
默认 EBGP 路由传播行为的隐式过滤器(不含策略)
本节讨论如何在未配置显式策略时使用隐式过滤器来调节 EBGP 路由传播行为。
优势
此功能具有以下优势:
Regulates BGP implementation— 防止EBGP发送方成为默认情况下接受并通告所有路由的静默直通。此功能能够有效降低叶自治系统上的中转流量增长,特别是当它们与任何上游互联网服务提供商多宿主时。因此,它还可以防止流量无声丢弃、拒绝服务和全球互联网中断。
Implicit filter— 该配置有助于使用隐式过滤器,其中默认行为仍设置为默认接收和通告所有路由。配置语句仅添加一个选项,用于在需要时为 accept、reject、reject-always 子句指定 enable 或 disable。隐式过滤器可确保具有依赖于默认 BGP 策略的现有部署的用户不会遇到操作中断。
概述
BGP 是当前用于全球互联网路由的域间自治协议。它还支持各种服务,如 VPN 和链路状态,这些服务不适合全局使用。
BGP实施,包括默认的 EBGP 行为,由 RFC4271 A 边界网关协议 4 (BGP-4) 指导。但是,它没有提供任何关于指定应分发哪些路由的明确指导。这导致原始 BGP 实现是对路由进行静默直通,没有任何过滤,因此导致流量增加,从而导致全球互联网中断。
从 Junos OS 20.3R1 版开始,我们在现有[edit protocols bgp]层级引入了隐式过滤器defaults ebgp no-policy。该配置将接收和播发的默认策略分成单独的子句(accept、reject 或 reject-always),以允许行为独立变化。
如果未配置显式策略,则隐式过滤器允许您在以下三种状态之一下启用默认的 eBGP 接收和通告行为:
价值观 |
默认策略 |
功能说明 |
|---|---|---|
接受 |
接收 |
接受接收所有路由(也是默认行为)。 |
广告 |
接受通告所有路由(也是默认行为)。 |
|
丢弃 |
接收 |
拒绝接收主、VRF、虚拟路由器和非转发实例类型中的 inet 单播和 inet6 单播类型的路由。 |
广告 |
拒绝在主、VRF、虚拟路由器和非转发实例类型中播发 inet 单播和 inet6 单播类型的路由。 |
|
始终拒绝 |
接收 |
拒绝以接收所有路由。 |
广告 |
拒绝以通告所有路由。 |


