BGP MED 属性
了解用于确定 AS 中出口点的 MED 属性
BGP 多出口鉴别器(MED 或MULTI_EXIT_DISC)是一种非传递属性,这意味着它不会传播到整个互联网,而只会传播到相邻自治系统 (AS)。MED 属性是可选的,这意味着它并不总是随 BGP 更新一起发送。MED 的目的是影响其他 AS 如何输入 AS 以到达某个前缀。
MED 属性有一个值,称为 指标。如果确定某个出口点的所有其他因素相等,则首选指标最低的出口点。
如果通过外部 BGP 链路接收 MED,则通过内部链路将其传播到 AS 中其他支持 BGP 的设备。
如果路由是从 BGP 获知并已与之关联的 MED 指标,或者如果您在配置文件中配置了 MED 指标,则 BGP 更新消息会包含一个 MED 指标。
MED 指标会根据以下常规规则与路由一起播发:
更具体的指标会覆盖不太具体的指标。也就是说,组特定指标覆盖全局 BGP 指标,对等特定指标覆盖全局 BGP 或组特定指标。
使用路由策略定义的指标将覆盖使用
metric-out
语句定义的指标。如果定义了任何指标,它将覆盖在路由中接收的指标。
如果收到的路由没有关联的 MED 指标,并且您未显式配置指标值,则不会播发任何指标。如果不显式配置指标值,则当公布活动路由时,MED 值等同于零 (0)。
由于 BGP 路由选择的主要标准是 AS 路径而不是主机之间的跃点数,因此与对等 AS 有多个连接 AS 可以具有多个等效 AS 路径。当路由表包含两个到相邻 AS 中相同主机的路由时,分配给每个路由的 MED 指标可以确定要包含在转发表中的哪个路由。您分配的 MED 指标可以强制流量通过 AS 中的特定出口点。
图 1 展示了如何使用 MED 指标来确定路由选择。

图 1 显示 AS 1 和 AS 2 通过两个独立的 BGP 链路连接到路由器 C 和 D。AS 1 中的主机 E 位于路由器 C 附近。同样位于 AS 1 中的主机 F 更靠近路由器 D。由于 AS 路径是等效的,因此每个主机都存在两个路由,一个通过路由器 C,一个通过路由器 D。要强制通过路由器 C 向主机 E 的所有流量,AS 1 的网络管理员 将每台路由器的 MED 指标分配给其出口点的主机 E。MED 指标 10 通过路由器 C 分配给到主机 E 的路由,并通过路由器 D 为至主机 E 的路由分配 MED 指标 20。AS 2 中的 BGP 路由器选择转发表 MED 指标较低的路由。
默认情况下,仅比较具有相同对等 AS 的路由的 MED。但是,您可以配置中列出的 表 1 路由表路径选择选项,以不同方式比较 MED。MED 选项不是相互排斥的,可以组合配置,也可以单独配置。要使 MED 选项生效,您必须通过网络统一配置这些选项。您配置的 MED 选项将确定所选路由。因此,在配置 MED 选项之前,我们建议您仔细评估您的网络以寻找首选路由。
选项(名称) |
功能 |
利用 |
---|---|---|
始终比较 MED ( |
确保在路由选择过程中始终比较来自不同 AS 中对等方的路径的 MED。 |
当参与网络的所有企业都就设置 MED 的统一策略达成一致时,这一点十分有用。例如,在由两个 ISP 共享的网络中,两者都必须同意某个路径是正确配置 MED 值更好的路径。 |
将 IGP 成本添加到 MED ( |
在比较路径选择的 MED 值之前,请将 BGP 下一跃点目标的 IGP 路由成本添加到 MED 中。 此选项将替换路由器的 MED 值,但不会影响 IGP 指标比较。因此,在 MED-plus-IGP 比较之后,当多个路由具有相同的值,并且路由选择继续时,也会比较 IGP 路由指标,即使它已添加到 MED 值中并在选择过程早期进行比较。 |
当下游 AS 需要通过多个 AS 接收的某个路由的完整成本时,很有用。 |
应用 Cisco IOS 非确定性行为 ( |
指定 Cisco IOS 软件的非确定行为:
|
建议不要配置此选项,因为不确定行为有时会妨碍系统正确比较路径之间的 MED。 |
另请参阅
示例:配置用于确定 AS 中的出口点的 MED 属性
此示例说明如何配置多出口鉴别器 (MED) 指标,以在 BGP 更新消息中播发。
要求
配置此示例之前,不需要除设备初始化之外的特殊配置。
概述
要直接配置 MED 指标以在 BGP 更新消息中播发,请添加以下 metric-out
语句:
metric-out (metric | minimum-igp offset | igp delay-med-update | offset);
metric
是发送至对等方的所有路由的主要指标。可以是 0 到 4,294,967,295 (232 – 1) 范围内的值。
此外,还支持以下可选设置:
minimum-igp
— 将指标设置为在内部网关协议 (IGP) 中计算的最小指标值,以到达 BGP 下一跃点。如果新计算的指标大于最小指标值,则指标值保持不变。如果新计算的指标较低,则指标值将降至该值。igp
— 将指标设置为在 IGP 中计算的最新指标值,以访问 BGP 下一跃点。delay-med-update
— MED 值增加时延迟发送 MED 更新。delay-med-update
配置语句时包括语句igp
。除非 MED 较低或与路由关联的其他属性已更改,否则发送更新的默认间隔为 10 分钟。在med-igp-update-interval minutes
层次结构级别包括语句[edit routing-options]
以修改默认间隔。offset
- 指定一个值offset
,以从 IGP 中计算的指标值中增加或减少该指标。指标值会由指定的值所抵消。如果offset
值为正,则增加 IGP 中计算的指标(通过指定任igp
一指标或igp-minimum
)。如果offset
值为负,则降低 IGP 中计算的指标(通过指定任igp
一指标或igp-minimum
)。offset
可以是 –231 到 231 – 1 范围内的值。请注意,调整后的指标决不能低于 0 或高于 232 – 1。
图 2 显示了一个典型的网络,具有内部对等会话和多个出口点到相邻自治系统 (AS)。

设备 R4 具有多个环路接口,配置为模拟播发的前缀。额外的环路接口地址为 44.44.44.44/32 和 144.144.144/32。此示例说明如何配置设备 R4,以将 MED 值 30 播发至设备 R3,并将 MED 值 20 播发至设备 R2。这会使 AS 123 中的所有设备首选通过设备 R2 的路径以到达 AS 4。
配置
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,然后将命令复制并粘贴到层次结构级别的 CLI 中 [edit]
。
设备 R1
set interfaces fe-1/2/0 unit 1 family inet address 12.12.12.1/24 set interfaces fe-1/2/1 unit 2 family inet address 13.13.13.1/24 set interfaces lo0 unit 1 family inet address 192.168.1.1/32 set protocols bgp group internal type internal set protocols bgp group internal local-address 192.168.1.1 set protocols bgp group internal export send-direct set protocols bgp group internal neighbor 192.168.2.1 set protocols bgp group internal neighbor 192.168.3.1 set protocols ospf area 0.0.0.0 interface lo0.1 passive set protocols ospf area 0.0.0.0 interface fe-1/2/0.1 set protocols ospf area 0.0.0.0 interface fe-1/2/1.2 set policy-options policy-statement send-direct term 1 from protocol direct set policy-options policy-statement send-direct term 1 then accept set routing-options autonomous-system 123 set routing-options router-id 192.168.1.1
设备 R2
set interfaces fe-1/2/0 unit 3 family inet address 12.12.12.2/24 set interfaces fe-1/2/1 unit 4 family inet address 24.24.24.2/24 set interfaces lo0 unit 2 family inet address 192.168.2.1/32 set protocols bgp group internal type internal set protocols bgp group internal local-address 192.168.2.1 set protocols bgp group internal export send-direct set protocols bgp group internal neighbor 192.168.1.1 set protocols bgp group internal neighbor 192.168.3.1 set protocols bgp group external type external set protocols bgp group external export send-direct set protocols bgp group external peer-as 4 set protocols bgp group external neighbor 24.24.24.4 set protocols ospf area 0.0.0.0 interface lo0.2 passive set protocols ospf area 0.0.0.0 interface fe-1/2/0.3 set protocols ospf area 0.0.0.0 interface fe-1/2/1.4 set policy-options policy-statement send-direct term 1 from protocol direct set policy-options policy-statement send-direct term 1 then accept set routing-options autonomous-system 123 set routing-options router-id 192.168.2.1
设备 R3
set interfaces fe-1/2/0 unit 5 family inet address 13.13.13.3/24 set interfaces fe-1/2/1 unit 6 family inet address 34.34.34.3/24 set interfaces lo0 unit 3 family inet address 192.168.3.1/32 set protocols bgp group internal type internal set protocols bgp group internal local-address 192.168.3.1 set protocols bgp group internal export send-direct set protocols bgp group internal neighbor 192.168.1.1 set protocols bgp group internal neighbor 192.168.2.1 set protocols bgp group external type external set protocols bgp group external export send-direct set protocols bgp group external peer-as 4 set protocols bgp group external neighbor 34.34.34.4 set protocols ospf area 0.0.0.0 interface lo0.3 passive set protocols ospf area 0.0.0.0 interface fe-1/2/0.5 set protocols ospf area 0.0.0.0 interface fe-1/2/1.6 set policy-options policy-statement send-direct term 1 from protocol direct set policy-options policy-statement send-direct term 1 then accept set routing-options autonomous-system 123 set routing-options router-id 192.168.3.1
设备 R4
set interfaces fe-1/2/0 unit 7 family inet address 24.24.24.4/24 set interfaces fe-1/2/1 unit 8 family inet address 34.34.34.4/24 set interfaces lo0 unit 4 family inet address 192.168.4.1/32 set interfaces lo0 unit 4 family inet address 44.44.44.44/32 set interfaces lo0 unit 4 family inet address 144.144.144.144/32 set protocols bgp group external type external set protocols bgp group external export send-direct set protocols bgp group external peer-as 123 set protocols bgp group external neighbor 34.34.34.3 metric-out 30 set protocols bgp group external neighbor 24.24.24.2 metric-out 20 set policy-options policy-statement send-direct term 1 from protocol direct set policy-options policy-statement send-direct term 1 then accept set routing-options autonomous-system 4 set routing-options router-id 192.168.4.1
配置设备 R1
逐步过程
以下示例要求您在配置层次结构中的各个级别上导航。有关导航 CLI 的信息,请参阅《Junos OS CLI 用户指南》中的在配置模式下使用 CLI 编辑器。
要配置设备 R1:
配置接口。
[edit interfaces fe-1/2/0 unit 1] user@R1# set family inet address 12.12.12.1/24 [edit interfaces fe-1/2/1 unit 2] user@R1# set family inet address 13.13.13.1/24 [edit interfaces lo0 unit 1] user@R1# set family inet address 192.168.1.1/32
配置 BGP。
[edit protocols bgp group internal] user@R1# set type internal user@R1# set local-address 192.168.1.1 user@R1# set export send-direct user@R1# set neighbor 192.168.2.1 user@R1# set neighbor 192.168.3.1
配置 OSPF。
[edit protocols ospf area 0.0.0.0] user@R1# set interface lo0.1 passive user@R1# set interface fe-1/2/0.1 user@R1# set interface fe-1/2/1.2
配置接受直接路由的策略。
此方案的其他有用选项可能是接受通过 OSPF 或本地路由获知的路由。
[edit policy-options policy-statement send-direct term 1] user@R1# set from protocol direct user@R1# set then accept
配置路由器 ID 和自治系统 (AS) 编号。
[edit routing-options] user@R1# set autonomous-system 123 user@R1# set router-id 192.168.1.1
结果
在配置模式下,输入 show interfaces
、 show policy-options
、 show protocols
和 show routing-options
命令,以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明,以更正配置。
user@R1# show interfaces fe-1/2/0 { unit 1 { family inet { address 12.12.12.1/24; } } } fe-1/2/1 { unit 2 { family inet { address 13.13.13.1/24; } } } lo0 { unit 1 { family inet { address 192.168.1.1/32; } } }
user@R1# show policy-options policy-statement send-direct { term 1 { from protocol direct; then accept; } }
user@R1# show protocols bgp { group internal { type internal; local-address 192.168.1.1; export send-direct; neighbor 192.168.2.1; neighbor 192.168.3.1; } } ospf { area 0.0.0.0 { interface lo0.1 { passive; } interface fe-1/2/0.1; interface fe-1/2/1.2; } }
user@R1# show routing-options autonomous-system 123; router-id 192.168.1.1;
完成设备配置后,请从配置模式进入 commit
。
配置设备 R2
逐步过程
以下示例要求您在配置层次结构中的各个级别上导航。有关导航 CLI 的信息,请参阅《Junos OS CLI 用户指南》中的在配置模式下使用 CLI 编辑器。
要配置设备 R2:
配置接口。
[edit interfaces fe-1/2/0 unit 3] user@R2# set family inet address 12.12.12.21/24 [edit interfaces fe-1/2/1 unit 4] user@R2# set family inet address 24.24.24.2/24 [edit interfaces lo0 unit 2] user@R2# set family inet address 192.168.2.1/32
配置 BGP。
[edit protocols bgp group internal] user@R2# set type internal user@R2# set local-address 192.168.2.1 user@R2# set export send-direct user@R2# set neighbor 192.168.1.1 user@R2# set neighbor 192.168.3.1 [edit protocols bgp group external] user@R2# set type external user@R2# set export send-direct user@R2# set peer-as 4 user@R2# set neighbor 24.24.24.4
配置 OSPF。
[edit protocols ospf area 0.0.0.0] user@R2# set interface lo0.2 passive user@R2# set interface fe-1/2/0.3 user@R2# set interface fe-1/2/1.4
配置接受直接路由的策略。
此方案的其他有用选项可能是接受通过 OSPF 或本地路由获知的路由。
[edit policy-options policy-statement send-direct term 1] user@R2# set from protocol direct user@R2# set then accept
配置路由器 ID 和自治系统 (AS) 编号。
[edit routing-options] user@R2# set autonomous-system 123 user@R2# set router-id 192.168.2.1
结果
在配置模式下,输入 show interfaces
、 show policy-options
、 show protocols
和 show routing-options
命令,以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明,以更正配置。
user@R2# show interfaces fe-1/2/0 { unit 3 { family inet { address 12.12.12.2/24; } } } fe-1/2/1 { unit 4 { family inet { address 24.24.24.2/24; } } } lo0 { unit 2 { family inet { address 192.168.2.1/32; } } }
user@R2# show policy-options policy-statement send-direct { term 1 { from protocol direct; then accept; } }
user@R2# show protocols bgp { group internal { type internal; local-address 192.168.2.1; export send-direct; neighbor 192.168.1.1; neighbor 192.168.3.1; } group external { type external; export send-direct; peer-as 4; neighbor 24.24.24.4; } } ospf { area 0.0.0.0 { interface lo0.2 { passive; } interface fe-1/2/0.3; interface fe-1/2/1.4; } }
user@R2# show routing-options autonomous-system 123; router-id 192.168.2.1;
完成设备配置后,请从配置模式进入 commit
。
配置设备 R3
逐步过程
以下示例要求您在配置层次结构中的各个级别上导航。有关导航 CLI 的信息,请参阅《Junos OS CLI 用户指南》中的在配置模式下使用 CLI 编辑器。
要配置设备 R3:
配置接口。
[edit interfaces fe-1/2/0 unit 5] user@R3# set family inet address 13.13.13.3/24 [edit interfaces fe-1/2/1 unit 6] user@R3# set family inet address 34.34.34.3/24 [edit interfaces lo0 unit 3] user@R3# set family inet address 192.168.3.1/32
配置 BGP。
[edit protocols bgp group internal] user@R3# set type internal user@R3# set local-address 192.168.3.1 user@R3# set export send-direct user@R3# set neighbor 192.168.1.1 user@R3# set neighbor 192.168.2.1 [edit protocols bgp group external] user@R3# set type external user@R3# set export send-direct user@R3# set peer-as 4 user@R3# set neighbor 34.34.34.4
配置 OSPF。
[edit protocols ospf area 0.0.0.0] user@R3# set interface lo0.3 passive user@R3# set interface fe-1/2/0.5 user@R3# set interface fe-1/2/1.6
配置接受直接路由的策略。
此方案的其他有用选项可能是接受通过 OSPF 或本地路由获知的路由。
[edit policy-options policy-statement send-direct term 1] user@R3# set from protocol direct user@R3# set then accept
配置路由器 ID 和自治系统 (AS) 编号。
[edit routing-options] user@R3# set autonomous-system 123 user@R3# set router-id 192.168.3.1
结果
在配置模式下,输入 show interfaces
、 show policy-options
、 show protocols
和 show routing-options
命令,以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明,以更正配置。
user@R3# show interfaces fe-1/2/0 { unit 5 { family inet { address 13.13.13.3/24; } } } fe-1/2/1 { unit 6 { family inet { address 34.34.34.3/24; } } } lo0 { unit 3 { family inet { address 192.168.3.1/32; } } }
user@R3# show policy-options policy-statement send-direct { term 1 { from protocol direct; then accept; } }
user@R3# show protocols bgp { group internal { type internal; local-address 192.168.3.1; export send-direct; neighbor 192.168.1.1; neighbor 192.168.2.1; } group external { type external; export send-direct; peer-as 4; neighbor 34.34.34.4; } } ospf { area 0.0.0.0 { interface lo0.3 { passive; } interface fe-1/2/0.5; interface fe-1/2/1.6; } }
user@R3# show routing-options autonomous-system 123; router-id 192.168.3.1;
完成设备配置后,请从配置模式进入 commit
。
配置设备 R4
逐步过程
以下示例要求您在配置层次结构中的各个级别上导航。有关导航 CLI 的信息,请参阅《Junos OS CLI 用户指南》中的在配置模式下使用 CLI 编辑器。
要配置设备 R4:
配置接口。
[edit interfaces fe-1/2/0 unit 7] user@R4# set family inet address 24.24.24.4/24 [edit interfaces fe-1/2/1 unit 8] user@R4# set family inet address 34.34.34.4/24 [edit interfaces lo0 unit 4] user@R4# set family inet address 192.168.4.1/32 user@R4# set family inet address 44.44.44.44/32 user@R4# set family inet address 144.144.144.144/32
设备 R4 具有多个环路接口地址,用于模拟播发的前缀。
配置接受直接路由的策略。
此方案的其他有用选项可能是接受通过 OSPF 或本地路由获知的路由。
[edit policy-options policy-statement send-direct term 1] user@R4# set from protocol direct user@R4# set then accept
配置 BGP。
[edit protocols bgp group external] user@R4# set type external user@R4# set export send-direct user@R4# set peer-as 123
为邻居设备 R3 配置 MED 值 30,为邻居设备 R2 配置 MED 值 20。
[edit protocols bgp group external] user@R4# set neighbor 34.34.34.3 metric-out 30 user@R4# set neighbor 24.24.24.2 metric-out 20
此配置会使自治系统 (AS) 123(设备 R1、设备 R2 和设备 R3 是其成员)优先选择通过设备 R2 的路径到达 AS 4。
配置路由器 ID 和 AS 编号。
[edit routing-options] user@R4# set autonomous-system 4 user@R4# set router-id 192.168.4.1
结果
在配置模式下,输入 show interfaces
、 show policy-options
、 show protocols
和 show routing-options
命令,以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明,以更正配置。
user@R4# show interfaces fe-1/2/0 { unit 7 { family inet { address 24.24.24.4/24; } } } fe-1/2/1 { unit 8 { family inet { address 34.34.34.4/24; } } } lo0 { unit 4 { family inet { address 192.168.4.1/32; address 44.44.44.44/32; address 144.144.144.144/32; } } }
user@R4# show policy-options policy-statement send-direct { term 1 { from protocol direct; then accept; } }
user@R4# show protocols bgp { group external { type external; export send-direct; peer-as 123; neighbor 34.34.34.3 { metric-out 30; } neighbor 24.24.24.2 { metric-out 20; } } }
user@R4# show routing-options autonomous-system 4; router-id 192.168.4.1;
完成设备配置后,请从配置模式进入 commit
。
验证
确认配置工作正常。
检查从设备 R1 到设备 R4 的活动路径
目的
验证活动路径是否通过设备 R2。
行动
在操作模式下,输入 show route protocol bgp
命令。
user@R1> show route protocol bgp inet.0: 13 destinations, 19 routes (13 active, 0 holddown, 0 hidden) + = Active Route, - = Last Active, * = Both 12.12.12.0/24 [BGP/170] 3d 22:52:38, localpref 100, from 192.168.2.1 AS path: I > to 12.12.12.2 via fe-1/2/0.1 13.13.13.0/24 [BGP/170] 3d 03:15:16, localpref 100, from 192.168.3.1 AS path: I > to 13.13.13.3 via fe-1/2/1.2 24.24.24.0/24 [BGP/170] 3d 22:52:38, localpref 100, from 192.168.2.1 AS path: I > to 12.12.12.2 via fe-1/2/0.1 34.34.34.0/24 [BGP/170] 3d 03:15:16, localpref 100, from 192.168.3.1 AS path: I > to 13.13.13.3 via fe-1/2/1.2 44.44.44.44/32 *[BGP/170] 01:41:11, MED 20, localpref 100, from 192.168.2.1 AS path: 4 I > to 12.12.12.2 via fe-1/2/0.1 144.144.144.144/32 *[BGP/170] 00:08:13, MED 20, localpref 100, from 192.168.2.1 AS path: 4 I > to 12.12.12.2 via fe-1/2/0.1 192.168.2.1/32 [BGP/170] 3d 22:52:38, localpref 100, from 192.168.2.1 AS path: I > to 12.12.12.2 via fe-1/2/0.1 192.168.3.1/32 [BGP/170] 3d 03:15:16, localpref 100, from 192.168.3.1 AS path: I > to 13.13.13.3 via fe-1/2/1.2 192.168.4.1/32 *[BGP/170] 01:41:11, MED 20, localpref 100, from 192.168.2.1 AS path: 4 I > to 12.12.12.2 via fe-1/2/0.1
含义
星号 (*) 表示首选路径通过设备 R2。选择路径的原因列为 MED 20。
验证设备 R4 是否正确发送其路由
目的
请确保设备 R4 向设备 R2 发送值为 20 的更新消息,向设备 R3 发送值为 30 的更新消息。
行动
在操作模式下,输入 show route advertising-protocol bgp 24.24.24.2
命令。
user@R4> show route advertising-protocol bgp 24.24.24.2 inet.0: 11 destinations, 13 routes (11 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 24.24.24.0/24 Self 20 I * 34.34.34.0/24 Self 20 I * 44.44.44.44/32 Self 20 I * 144.144.144.144/32 Self 20 I * 192.168.4.1/32 Self 20 I
user@R4> show route advertising-protocol bgp 34.34.34.3 inet.0: 11 destinations, 13 routes (11 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 24.24.24.0/24 Self 30 I * 34.34.34.0/24 Self 30 I * 44.44.44.44/32 Self 30 I * 144.144.144.144/32 Self 30 I * 192.168.4.1/32 Self 30 I
含义
MED 列显示设备 R4 正在向其两个外部 BGP (EBGP) 邻接方发送正确的 MED 值。
示例:使用路由过滤器配置 MED
此示例说明如何配置策略,使用路由过滤器修改多出口鉴别器 (MED) 指标,以在 BGP 更新消息中播发。
要求
配置此示例之前,不需要除设备初始化之外的特殊配置。
概述
要配置路由过滤器策略以修改 BGP 更新消息中播发的 MED 指标,请在策略操作中包含该 metric
语句。
图 3 显示了一个典型的网络,具有内部对等会话和多个出口点到相邻自治系统 (AS)。

设备 R4 具有多个环路接口,配置为模拟播发的前缀。额外的环路接口地址为 172.16.44.0/32 和 172.16.144.0/32。此示例说明如何配置设备 R4 以将 MED 值 30 播发至除 172.16.144.0 以外的所有路由的设备 R3。对于 172.16.144.0,将播发至设备 3 的 MED 值 10。无论路由前缀如何,MED 值 20 播发至设备 R2。
配置
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,然后将命令复制并粘贴到层次结构级别的 CLI 中 [edit]
。
设备 R1
set interfaces fe-1/2/0 unit 1 family inet address 172.16.12.1/24 set interfaces fe-1/2/1 unit 2 family inet address 172.16.13.1/24 set interfaces lo0 unit 1 family inet address 192.168.1.1/32 set protocols bgp group internal type internal set protocols bgp group internal local-address 192.168.1.1 set protocols bgp group internal export send-direct set protocols bgp group internal neighbor 192.168.2.1 set protocols bgp group internal neighbor 192.168.3.1 set protocols ospf area 0.0.0.0 interface lo0.1 passive set protocols ospf area 0.0.0.0 interface fe-1/2/0.1 set protocols ospf area 0.0.0.0 interface fe-1/2/1.2 set policy-options policy-statement send-direct term 1 from protocol direct set policy-options policy-statement send-direct term 1 then accept set routing-options autonomous-system 123 set routing-options router-id 192.168.1.1
设备 R2
set interfaces fe-1/2/0 unit 3 family inet address 172.16.12.2/24 set interfaces fe-1/2/1 unit 4 family inet address 172.16.24.2/24 set interfaces lo0 unit 2 family inet address 192.168.2.1/32 set protocols bgp group internal type internal set protocols bgp group internal local-address 192.168.2.1 set protocols bgp group internal export send-direct set protocols bgp group internal neighbor 192.168.1.1 set protocols bgp group internal neighbor 192.168.3.1 set protocols bgp group external type external set protocols bgp group external export send-direct set protocols bgp group external peer-as 4 set protocols bgp group external neighbor 172.16.24.4 set protocols ospf area 0.0.0.0 interface lo0.2 passive set protocols ospf area 0.0.0.0 interface fe-1/2/0.3 set protocols ospf area 0.0.0.0 interface fe-1/2/1.4 set policy-options policy-statement send-direct term 1 from protocol direct set policy-options policy-statement send-direct term 1 then accept set routing-options autonomous-system 123 set routing-options router-id 192.168.2.1
设备 R3
set interfaces fe-1/2/0 unit 5 family inet address 172.16.13.3/24 set interfaces fe-1/2/1 unit 6 family inet address 172.16.34.3/24 set interfaces lo0 unit 3 family inet address 192.168.3.1/32 set protocols bgp group internal type internal set protocols bgp group internal local-address 192.168.3.1 set protocols bgp group internal export send-direct set protocols bgp group internal neighbor 192.168.1.1 set protocols bgp group internal neighbor 192.168.2.1 set protocols bgp group external type external set protocols bgp group external export send-direct set protocols bgp group external peer-as 4 set protocols bgp group external neighbor 172.16.34.4 set protocols ospf area 0.0.0.0 interface lo0.3 passive set protocols ospf area 0.0.0.0 interface fe-1/2/0.5 set protocols ospf area 0.0.0.0 interface fe-1/2/1.6 set policy-options policy-statement send-direct term 1 from protocol direct set policy-options policy-statement send-direct term 1 then accept set routing-options autonomous-system 123 set routing-options router-id 192.168.3.1
设备 R4
set interfaces fe-1/2/0 unit 7 family inet address 172.16.24.4/24 set interfaces fe-1/2/1 unit 8 family inet address 172.16.34.4/24 set interfaces lo0 unit 4 family inet address 192.168.4.1/32 set interfaces lo0 unit 4 family inet address 172.16.44.0/32 set interfaces lo0 unit 4 family inet address 172.16.144.0/32 set protocols bgp group external type external set protocols bgp group external export send-direct set protocols bgp group external peer-as 123 set protocols bgp group external neighbor 172.16.34.3 export med-10 set protocols bgp group external neighbor 172.16.34.3 export med-30 set protocols bgp group external neighbor 172.16.24.2 metric-out 20 set policy-options policy-statement med-10 from route-filter 172.16.144.0/32 exact set policy-options policy-statement med-10 then metric 10 set policy-options policy-statement med-10 then accept set policy-options policy-statement med-30 from route-filter 0.0.0.0/0 longer set policy-options policy-statement med-30 then metric 30 set policy-options policy-statement med-30 then accept set policy-options policy-statement send-direct term 1 from protocol direct set policy-options policy-statement send-direct term 1 then accept set routing-options autonomous-system 4 set routing-options router-id 192.168.4.1
配置设备 R1
逐步过程
以下示例要求您在配置层次结构中的各个级别上导航。有关导航 CLI 的信息,请参阅《Junos OS CLI 用户指南》中的在配置模式下使用 CLI 编辑器。
要配置设备 R1:
配置设备接口。
[edit interfaces fe-1/2/0 unit 1] user@R1# set family inet address 172.16.12.1/24 [edit interfaces fe-1/2/1 unit 2] user@R1# set family inet address 172.16.13.1/24 [edit interfaces lo0 unit 1] user@R1# set family inet address 192.168.1.1/32
配置 BGP。
[edit protocols bgp group internal] user@R1# set type internal user@R1# set local-address 192.168.1.1 user@R1# set export send-direct user@R1# set neighbor 192.168.2.1 user@R1# set neighbor 192.168.3.1
配置 OSPF。
[edit protocols ospf area 0.0.0.0] user@R1# set interface lo0.1 passive user@R1# set interface fe-1/2/0.1 user@R1# set interface fe-1/2/1.2
配置接受直接路由的策略。
此方案的其他有用选项可能是接受通过 OSPF 或本地路由获知的路由。
[edit policy-options policy-statement send-direct term 1] user@R1# set from protocol direct user@R1# set then accept
配置路由器 ID 和自治系统 (AS) 编号。
[edit routing-options] user@R1# set autonomous-system 123 user@R1# set router-id 192.168.1.1
结果
在配置模式下,输入 show interfaces
、 show protocols
、 show policy-options
和 show routing-options
命令,以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明,以更正配置。
user@R1# show interfaces fe-1/2/0 { unit 1 { family inet { address 172.16.12.1/24; } } } fe-1/2/1 { unit 2 { family inet { address 172.16.13.1/24; } } } lo0 { unit 1 { family inet { address 192.168.1.1/32; } } }
user@R1# show protocols bgp { group internal { type internal; local-address 192.168.1.1; export send-direct; neighbor 192.168.2.1; neighbor 192.168.3.1; } } ospf { area 0.0.0.0 { interface lo0.1 { passive; } interface fe-1/2/0.1; interface fe-1/2/1.2; } }
user@R1# show policy-options policy-statement send-direct { term 1 { from protocol direct; then accept; } }
user@R1# show routing-options autonomous-system 123; router-id 192.168.1.1;
完成设备配置后,请从配置模式进入 commit
。
配置设备 R2
逐步过程
以下示例要求您在配置层次结构中的各个级别上导航。有关导航 CLI 的信息,请参阅《Junos OS CLI 用户指南》中的在配置模式下使用 CLI 编辑器。
要配置设备 R2:
配置设备接口。
[edit interfaces fe-1/2/0 unit 3] user@R2# set family inet address 172.16.12.21/24 [edit interfaces fe-1/2/1 unit 4] user@R2# set family inet address 172.16.24.2/24 [edit interfaces lo0 unit 2] user@R2# set family inet address 192.168.2.1/32
配置 BGP。
[edit protocols bgp group internal] user@R2# set type internal user@R2# set local-address 192.168.2.1 user@R2# set export send-direct user@R2# set neighbor 192.168.1.1 user@R2# set neighbor 192.168.3.1 [edit protocols bgp group external] user@R2# set type external user@R2# set export send-direct user@R2# set peer-as 4 user@R2# set neighbor 172.16.24.4
配置 OSPF。
[edit protocols ospf area 0.0.0.0] user@R2# set interface lo0.2 passive user@R2# set interface fe-1/2/0.3 user@R2# set interface fe-1/2/1.4
配置接受直接路由的策略。
此方案的其他有用选项可能是接受通过 OSPF 或本地路由获知的路由。
[edit policy-options policy-statement send-direct term 1] user@R2# set from protocol direct user@R2# set then accept
配置路由器 ID 和自治系统 (AS) 编号。
[edit routing-options] user@R2# set autonomous-system 123 user@R2# set router-id 192.168.2.1
结果
在配置模式下,输入 show interfaces
、 show protocols
、 show policy-options
和 show routing-options
命令,以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明,以更正配置。
user@R2# show interfaces fe-1/2/0 { unit 3 { family inet { address 172.16.12.2/24; } } } fe-1/2/1 { unit 4 { family inet { address 172.16.24.2/24; } } } lo0 { unit 2 { family inet { address 192.168.2.1/32; } } }
user@R2# show protocols bgp { group internal { type internal; local-address 192.168.2.1; export send-direct; neighbor 192.168.1.1; neighbor 192.168.3.1; } group external { type external; export send-direct; peer-as 4; neighbor 172.16.24.4; } } ospf { area 0.0.0.0 { interface lo0.2 { passive; } interface fe-1/2/0.3; interface fe-1/2/1.4; } }
user@R2# show policy-options policy-statement send-direct { term 1 { from protocol direct; then accept; } }
user@R2# show routing-options autonomous-system 123; router-id 192.168.2.1;
完成设备配置后,请从配置模式进入 commit
。
配置设备 R3
逐步过程
以下示例要求您在配置层次结构中的各个级别上导航。有关导航 CLI 的信息,请参阅《Junos OS CLI 用户指南》中的在配置模式下使用 CLI 编辑器。
要配置设备 R3:
配置设备接口。
[edit interfaces fe-1/2/0 unit 5] user@R3# set family inet address 172.16.13.3/24 [edit interfaces fe-1/2/1 unit 6] user@R3# set family inet address 172.16.34.3/24 [edit interfaces lo0 unit 3] user@R3# set family inet address 192.168.3.1/32
配置 BGP。
[edit protocols bgp group internal] user@R3# set type internal user@R3# set local-address 192.168.3.1 user@R3# set export send-direct user@R3# set neighbor 192.168.1.1 user@R3# set neighbor 192.168.2.1 [edit protocols bgp group external] user@R3# set type external user@R3# set export send-direct user@R3# set peer-as 4 user@R3# set neighbor 172.16.34.4
配置 OSPF。
[edit protocols ospf area 0.0.0.0] user@R3# set interface lo0.3 passive user@R3# set interface fe-1/2/0.5 user@R3# set interface fe-1/2/1.6
配置接受直接路由的策略。
此方案的其他有用选项可能是接受通过 OSPF 或本地路由获知的路由。
[edit policy-options policy-statement send-direct term 1] user@R3# set from protocol direct user@R3# set then accept
配置路由器 ID 和自治系统 (AS) 编号。
[edit routing-options] user@R3# set autonomous-system 123 user@R3# set router-id 192.168.3.1
结果
在配置模式下,输入 show interfaces
、 show protocols
、 show policy-options
和 show routing-options
命令,以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明,以更正配置。
user@R3# show interfaces fe-1/2/0 { unit 5 { family inet { address 172.16.13.3/24; } } } fe-1/2/1 { unit 6 { family inet { address 172.16.34.3/24; } } } lo0 { unit 3 { family inet { address 192.168.3.1/32; } } }
user@R3# show protocols bgp { group internal { type internal; local-address 192.168.3.1; export send-direct; neighbor 192.168.1.1; neighbor 192.168.2.1; } group external { type external; export send-direct; peer-as 4; neighbor 172.16.34.4; } } ospf { area 0.0.0.0 { interface lo0.3 { passive; } interface fe-1/2/0.5; interface fe-1/2/1.6; } }
user@R3# show policy-options policy-statement send-direct { term 1 { from protocol direct; then accept; } }
user@R3# show routing-options autonomous-system 123; router-id 192.168.3.1;
完成设备配置后,请从配置模式进入 commit
。
配置设备 R4
逐步过程
以下示例要求您在配置层次结构中的各个级别上导航。有关导航 CLI 的信息,请参阅《Junos OS CLI 用户指南》中的在配置模式下使用 CLI 编辑器。
要配置设备 R4:
配置设备接口。
[edit interfaces fe-1/2/0 unit 7] user@R4# set family inet address 172.16.24.4/24 [edit interfaces fe-1/2/1 unit 8] user@R4# set family inet address 172.16.34.4/24 [edit interfaces lo0 unit 4] user@R4# set family inet address 192.168.4.1/32 user@R4# set family inet address 172.16.44.0/32 user@R4# set family inet address 172.16.144.0/32
设备 R4 具有多个环路接口地址,用于模拟播发的前缀。
配置接受直接路由的策略。
此方案的其他有用选项可能是接受通过 OSPF 或本地路由获知的路由。
[edit policy-options policy-statement send-direct term 1] user@R4# set from protocol direct user@R4# set then accept
配置 BGP。
[edit protocols bgp group external] user@R4# set type external user@R4# set export send-direct user@R4# set peer-as 123
配置两个 MED 策略。
[edit policy-options] set policy-statement med-10 from route-filter 172.16.144.0/32 exact set policy-statement med-10 then metric 10 set policy-statement med-10 then accept set policy-statement med-30 from route-filter 0.0.0.0/0 longer set policy-statement med-30 then metric 30 set policy-statement med-30 then accept
配置两个 EBGP 邻接方,将两个 MED 策略应用于设备 R3,将 MED 值 20 应用于设备 R2。
[edit protocols bgp group external] user@R4# set neighbor 172.16.34.3 export med-10 user@R4# set neighbor 172.16.34.3 export med-30 user@R4# set neighbor 172.16.24.2 metric-out 20
配置路由器 ID 和自治系统 (AS) 编号。
[edit routing-options] user@R4# set autonomous-system 4 user@R4# set router-id 192.168.4.1
结果
在配置模式下,输入 show interfaces
、 show protocols
、 show policy-options
和 show routing-options
命令,以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明,以更正配置。
user@R4# show interfaces fe-1/2/0 { unit 7 { family inet { address 172.16.24.4/24; } } } fe-1/2/1 { unit 8 { family inet { address 172.16.34.4/24; } } } lo0 { unit 4 { family inet { address 192.168.4.1/32; address 172.16.44.0/32; address 172.16.144.0/32; } } }
user@R4# show protocols bgp { group external { type external; export send-direct; peer-as 123; neighbor 172.16.24.2 { metric-out 20; } neighbor 172.16.34.3 { export [ med-10 med-30 ]; } } }
user@R4# show policy-options policy-statement med-10 { from { route-filter 172.16.144.0/32 exact; } then { metric 10; accept; } } policy-statement med-30 { from { route-filter 0.0.0.0/0 longer; } then { metric 30; accept; } } policy-statement send-direct { term 1 { from protocol direct; then accept; } }
user@R4# show routing-options autonomous-system 4; router-id 192.168.4.1;
完成设备配置后,请从配置模式进入 commit
。
验证
确认配置工作正常。
检查从设备 R1 到设备 R4 的活动路径
目的
验证活动路径是否通过设备 R2。
行动
在操作模式下,输入 show route protocol bgp
命令。
user@R1> show route protocol bgp inet.0: 13 destinations, 19 routes (13 active, 0 holddown, 0 hidden) + = Active Route, - = Last Active, * = Both 172.16.12.0/24 [BGP/170] 4d 01:13:32, localpref 100, from 192.168.2.1 AS path: I > to 172.16.12.2 via fe-1/2/0.1 172.16.13.0/24 [BGP/170] 3d 05:36:10, localpref 100, from 192.168.3.1 AS path: I > to 172.16.13.3 via fe-1/2/1.2 172.16.24.0/24 [BGP/170] 4d 01:13:32, localpref 100, from 192.168.2.1 AS path: I > to 172.16.12.2 via fe-1/2/0.1 172.16.34.0/24 [BGP/170] 3d 05:36:10, localpref 100, from 192.168.3.1 AS path: I > to 172.16.13.3 via fe-1/2/1.2 172.16.44.0/32 *[BGP/170] 00:06:03, MED 20, localpref 100, from 192.168.2.1 AS path: 4 I > to 172.16.12.2 via fe-1/2/0.1 172.16.144.0/32 *[BGP/170] 00:06:03, MED 10, localpref 100, from 192.168.3.1 AS path: 4 I > to 172.16.13.3 via fe-1/2/1.2 192.168.2.1/32 [BGP/170] 4d 01:13:32, localpref 100, from 192.168.2.1 AS path: I > to 172.16.12.2 via fe-1/2/0.1 192.168.3.1/32 [BGP/170] 3d 05:36:10, localpref 100, from 192.168.3.1 AS path: I > to 172.16.13.3 via fe-1/2/1.2 192.168.4.1/32 *[BGP/170] 00:06:03, MED 20, localpref 100, from 192.168.2.1 AS path: 4 I > to 172.16.12.2 via fe-1/2/0.1
含义
输出显示,设备 R4 播发的路由的首选路径通过设备 R2(172.16.144.0/32 除外)。对于 172.16.144.0/32,首选路径是通过设备 R3。
验证设备 R4 是否正确发送其路由
目的
请确保设备 R4 向设备 R2 发送值为 20 的更新消息,向设备 R3 发送值为 30 的更新消息。
行动
在操作模式下,输入 show route advertising-protocol bgp
命令。
user@R4> show route advertising-protocol bgp 172.16.24.2 inet.0: 11 destinations, 13 routes (11 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 172.16.24.0/24 Self 20 I * 172.16.34.0/24 Self 20 I * 172.16.44.0/32 Self 20 I * 172.16.144.0/32 Self 20 I * 192.168.4.1/32 Self 20 I
user@R4> show route advertising-protocol bgp 172.16.34.3 inet.0: 11 destinations, 13 routes (11 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 172.16.24.0/24 Self 30 I * 172.16.34.0/24 Self 30 I * 172.16.44.0/32 Self 30 I * 172.16.144.0/32 Self 10 I * 192.168.4.1/32 Self 30 I
含义
MED 列显示设备 R4 正在向其两个 EBGP 邻接方发送正确的 MED 值。
示例:使用社区配置 MED
将来自特定社区的所有路由的多出口鉴别器 (MED) 指标设置为 20。
[edit] routing-options { router-id 10.0.0.1; autonomous-system 23; } policy-options { policy-statement from-otago { from community otago; then metric 20; } community otago members [56:2379 23:46944]; } protocols { bgp { import from-otago; group 23 { type external; peer-as 56; neighbor 192.168.0.1 { traceoptions { file bgp-log-peer; flag packets; } log-updown; } } } }
示例:将 MED 路径属性与 IGP 指标关联并延迟 MED 更新
此示例说明如何将多出口鉴别器 (MED) 路径属性与内部网关协议 (IGP) 指标相关联,并配置计时器以延迟 MED 属性的更新。
要求
配置此示例之前,不需要除设备初始化之外的特殊配置。
概述
BGP 可配置为基于其内部 BGP (IBGP) 路由下一跃点的 IGP 距离为路由播发 MED 属性。IGP 指标允许内部路由根据管理设置遵循最短路径。在某些部署中,理想的方式是将 IGP 最短路径知识传达给相邻自治系统 (AS) 中的外部 BGP (EBGP) 对等方。这使得这些 EBGP 对等方可以使用尽可能短的路径将流量转发到您的 AS。
从 EBGP 对等方学习的路由通常在直连接口上有下一个跃点,因此 IGP 值等于零。零表示播发的值。当 BGP 对等方发送要求本地系统执行下一跃点解析的第三方下一跃点时,IGP 指标是非零值—IBGP 配置、联合对等方内的配置或包含语句的 multihop
EBGP 配置。在这些情况下,通过包含 metric-out minimum-igp
或 metric-out igp
选项将 MED 值与 IGP 指标相关联可能很有意义。
将 MED 与 IGP 指标关联起来的缺点是,当网络中存在 IGP 不稳时,路由播发过多的风险。为 MED 更新配置延迟提供了一种在此类情况下减少路由通告的机制。当下一跃点的 IGP 指标发生变化时,延迟会减慢 MED 更新速度。该方法使用计时器定期播发 MED 更新。计时器到期后,已 metric-out igp delay-updates
配置路由的 MED 属性将更新为下一跃点的当前 IGP 指标。启用 BGP 的设备会针对 MED 属性已更改的路由发出公告。
该 delay-updates
选项标识必须抑制 MED 更新的 BGP 组(或对等方)。默认情况下,发布 MED 更新的时间设置为 10 分钟。通过将语句包括在配置中routing-options
,您可以将间隔延长至 600 分钟med-igp-update-interval
。
如果启用了不间断活动路由 (NSR) 并发生了切换,则只要切换发生,就会立即播发延迟的 MED 更新。
配置 metric-out igp
选项时,IGP 指标将 IGP 成本直接跟踪到 IBGP 对等方。IGP 成本下降时,播发的 MED 值也下降。相反,当 IGP 成本上升时,MED 值也会上升。
配置 metric-out minimum-igp
选项时,仅当 IBGP 对等方的 IGP 成本下降时,播发的 MED 值才会更改。IGP 成本的增加不会影响 MED 值。路由器会监控并记住最低 IGP 成本,直到路由进程 (rpd) 重新启动。只有当 MED 低于先前播发的值或与路由关联的其他属性已更改,或者 BGP 对等方响应刷新路由请求时,BGP 对等方才会发送更新。
此示例使用 metric
OSPF 配置中的语句来证明,当 IGP 指标发生变化时,MED 也在配置的延迟间隔之后发生变化。OSPF 指标的范围从 1 到 65,535。
图 4 显示了示例拓扑。

在此示例中,设备 R1 播发的 MED 值与在 AS 1 中运行的 IGP 相关联。当 AS 2 将流量转发到 AS 1 时,设备 R1 播发的 MED 值会影响相邻 AS (AS 2) 的决策。
配置
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,然后将命令复制并粘贴到层次结构级别的 CLI 中 [edit]
。
设备 R1
set interfaces fe-1/2/0 unit 2 description R1->R2 set interfaces fe-1/2/0 unit 2 family inet address 10.0.0.1/30 set interfaces fe-1/2/1 unit 7 description R1->R4 set interfaces fe-1/2/1 unit 7 family inet address 172.16.0.1/30 set interfaces lo0 unit 1 family inet address 192.168.0.1/32 set protocols bgp group internal type internal set protocols bgp group internal local-address 192.168.0.1 set protocols bgp group internal export send-direct set protocols bgp group internal neighbor 192.168.0.2 set protocols bgp group internal neighbor 192.168.0.3 set protocols bgp group external type external set protocols bgp group external metric-out igp delay-med-update set protocols bgp group external export send-direct set protocols bgp group external peer-as 2 set protocols bgp group external neighbor 172.16.0.2 set protocols ospf area 0.0.0.0 interface fe-1/2/0.2 metric 600 set protocols ospf area 0.0.0.0 interface lo0.1 passive set policy-options policy-statement send-direct term 1 from protocol direct set policy-options policy-statement send-direct term 1 then accept set routing-options med-igp-update-interval 12 set routing-options router-id 192.168.0.1 set routing-options autonomous-system 1
设备 R2
set interfaces fe-1/2/0 unit 1 description R2->R1 set interfaces fe-1/2/0 unit 1 family inet address 10.0.0.2/30 set interfaces fe-1/2/1 unit 4 description R2->R3 set interfaces fe-1/2/1 unit 4 family inet address 10.0.2.2/30 set interfaces lo0 unit 2 family inet address 192.168.0.2/32 set protocols bgp group internal type internal set protocols bgp group internal local-address 192.168.0.2 set protocols bgp group internal export send-direct set protocols bgp group internal neighbor 192.168.0.1 set protocols bgp group internal neighbor 192.168.0.3 set protocols ospf area 0.0.0.0 interface fe-1/2/0.1 set protocols ospf area 0.0.0.0 interface fe-1/2/1.4 set protocols ospf area 0.0.0.0 interface lo0.2 passive set policy-options policy-statement send-direct term 1 from protocol direct set policy-options policy-statement send-direct term 1 then accept set routing-options router-id 192.168.0.2 set routing-options autonomous-system 1
设备 R3
set interfaces fe-1/2/0 unit 3 description R3->R2 set interfaces fe-1/2/0 unit 3 family inet address 10.0.2.1/30 set interfaces fe-1/2/1 unit 5 description R3->R5 set interfaces fe-1/2/1 unit 5 family inet address 172.16.0.5/30 set interfaces lo0 unit 3 family inet address 192.168.0.3/32 set protocols bgp group internal type internal set protocols bgp group internal local-address 192.168.0.3 set protocols bgp group internal export send-direct set protocols bgp group internal neighbor 192.168.0.1 set protocols bgp group internal neighbor 192.168.0.2 set protocols bgp group external type external set protocols bgp group external export send-direct set protocols bgp group external peer-as 2 set protocols bgp group external neighbor 172.16.0.6 set protocols ospf area 0.0.0.0 interface fe-1/2/0.3 set protocols ospf area 0.0.0.0 interface lo0.3 passive set policy-options policy-statement send-direct term 1 from protocol direct set policy-options policy-statement send-direct term 1 then accept set routing-options router-id 192.168.0.3 set routing-options autonomous-system 1
设备 R4
set interfaces fe-1/2/0 unit 8 description R4->R1 set interfaces fe-1/2/0 unit 8 family inet address 172.16.0.2/30 set interfaces fe-1/2/1 unit 9 description R4->R5 set interfaces fe-1/2/1 unit 9 family inet address 10.0.4.1/30 set interfaces fe-1/2/2 unit 13 description R4->R6 set interfaces fe-1/2/2 unit 13 family inet address 172.16.0.9/30 set interfaces lo0 unit 4 family inet address 192.168.0.4/32 set protocols bgp group internal type internal set protocols bgp group internal local-address 192.168.0.4 set protocols bgp group internal export send-direct set protocols bgp group internal neighbor 192.168.0.5 set protocols bgp group external type external set protocols bgp group external export send-direct set protocols bgp group external neighbor 172.16.0.10 peer-as 3 set protocols bgp group external neighbor 172.16.0.1 peer-as 1 set protocols ospf area 0.0.0.0 interface fe-1/2/1.9 set protocols ospf area 0.0.0.0 interface lo0.4 passive set policy-options policy-statement send-direct term 1 from protocol direct set policy-options policy-statement send-direct term 1 then accept set routing-options router-id 192.168.0.4 set routing-options autonomous-system 2
设备 R5
set interfaces fe-1/2/0 unit 6 description R5->R3 set interfaces fe-1/2/0 unit 6 family inet address 172.16.0.6/30 set interfaces fe-1/2/1 unit 10 description R5->R4 set interfaces fe-1/2/1 unit 10 family inet address 10.0.4.2/30 set interfaces fe-1/2/2 unit 11 description R5->R8 set interfaces fe-1/2/2 unit 11 family inet address 172.16.0.13/30 set interfaces lo0 unit 5 family inet address 192.168.0.5/32 set protocols bgp group internal type internal set protocols bgp group internal local-address 192.168.0.5 set protocols bgp group internal export send-direct set protocols bgp group internal neighbor 192.168.0.4 set protocols bgp group external type external set protocols bgp group external export send-direct set protocols bgp group external neighbor 172.16.0.5 peer-as 1 set protocols bgp group external neighbor 172.16.0.14 peer-as 3 set protocols ospf area 0.0.0.0 interface fe-1/2/1.10 set protocols ospf area 0.0.0.0 interface lo0.5 passive set policy-options policy-statement send-direct term 1 from protocol direct set policy-options policy-statement send-direct term 1 then accept set routing-options router-id 192.168.0.5 set routing-options autonomous-system 2
设备 R6
set interfaces fe-1/2/0 unit 14 description R6->R4 set interfaces fe-1/2/0 unit 14 family inet address 172.16.0.10/30 set interfaces fe-1/2/1 unit 15 description R6->R7 set interfaces fe-1/2/1 unit 15 family inet address 10.0.6.1/30 set interfaces lo0 unit 6 family inet address 192.168.0.6/32 set protocols bgp group internal type internal set protocols bgp group internal local-address 192.168.0.6 set protocols bgp group internal export send-direct set protocols bgp group internal neighbor 192.168.0.7 set protocols bgp group internal neighbor 192.168.0.8 set protocols bgp group external type external set protocols bgp group external export send-direct set protocols bgp group external peer-as 2 set protocols bgp group external neighbor 172.16.0.9 peer-as 2 set protocols ospf area 0.0.0.0 interface fe-1/2/1.15 set protocols ospf area 0.0.0.0 interface lo0.6 passive set policy-options policy-statement send-direct term 1 from protocol direct set policy-options policy-statement send-direct term 1 then accept set routing-options router-id 192.168.0.6 set routing-options autonomous-system 3
设备 R7
set interfaces fe-1/2/0 unit 16 description R7->R6 set interfaces fe-1/2/0 unit 16 family inet address 10.0.6.2/30 set interfaces fe-1/2/1 unit 17 description R7->R8 set interfaces fe-1/2/1 unit 17 family inet address 10.0.7.2/30 set interfaces lo0 unit 7 family inet address 192.168.0.7/32 set protocols bgp group internal type internal set protocols bgp group internal local-address 192.168.0.7 set protocols bgp group internal export send-direct set protocols bgp group internal neighbor 192.168.0.6 set protocols bgp group internal neighbor 192.168.0.8 set protocols ospf area 0.0.0.0 interface fe-1/2/0.16 set protocols ospf area 0.0.0.0 interface fe-1/2/1.17 set protocols ospf area 0.0.0.0 interface lo0.7 passive set policy-options policy-statement send-direct term 1 from protocol direct set policy-options policy-statement send-direct term 1 then accept set routing-options router-id 192.168.0.7 set routing-options autonomous-system 3
设备 R8
set interfaces fe-1/2/0 unit 12 description R8->R5 set interfaces fe-1/2/0 unit 12 family inet address 172.16.0.14/30 set interfaces fe-1/2/1 unit 18 description R8->R7 set interfaces fe-1/2/1 unit 18 family inet address 10.0.7.1/30 set interfaces lo0 unit 8 family inet address 192.168.0.8/32 set protocols bgp group internal type internal set protocols bgp group internal local-address 192.168.0.8 set protocols bgp group internal export send-direct set protocols bgp group internal neighbor 192.168.0.6 set protocols bgp group internal neighbor 192.168.0.7 set protocols bgp group external type external set protocols bgp group external export send-direct set protocols bgp group external peer-as 2 set protocols bgp group external neighbor 172.16.0.13 peer-as 2 set protocols ospf area 0.0.0.0 interface fe-1/2/1.18 set protocols ospf area 0.0.0.0 interface lo0.8 passive set policy-options policy-statement send-direct term 1 from protocol direct set policy-options policy-statement send-direct term 1 then accept set routing-options router-id 192.168.0.8 set routing-options autonomous-system 3
配置设备 R1
逐步过程
以下示例要求您在配置层次结构中的各个级别上导航。有关导航 CLI 的信息,请参阅《Junos OS CLI 用户指南》中的在配置模式下使用 CLI 编辑器。
要配置设备 R1:
配置接口。
[edit interfaces fe-1/2/0 unit 2] user@R1# set description R1->R2 user@R1# set family inet address 10.0.0.1/30 [edit interfaces fe-1/2/1 unit 7] user@R1# set description R1->R4 user@R1# set family inet address 172.16.0.1/30 [edit interfaces lo0 unit 1] user@R1# set family inet address 192.168.0.1/32
配置 IBGP。
[edit protocols bgp group internal] user@R1# set type internal user@R1# set local-address 192.168.0.1 user@R1# set export send-direct user@R1# set neighbor 192.168.0.2 user@R1# set neighbor 192.168.0.3
配置 EBGP。
[edit protocols bgp group external] user@R1# set type external user@R1# set export send-direct user@R1# set peer-as 2 user@R1# set neighbor 172.16.0.2
将 MED 值与 IGP 指标相关联。
[edit protocols bgp group external] user@R1# set metric-out igp delay-med-update
包括
delay-med-update
选项时,MED 更新的默认设置为 10 分钟。排除delay-med-update
选项时,MED 更新会立即在 IGP 指标更改之后发生。(可选)配置 MED 更新的更新间隔。
[edit routing-options] user@R1# set med-igp-update-interval 12
您可以配置 10 分钟到 600 分钟的间隔。
配置 OSPF。
[edit protocols ospf area 0.0.0.0] user@R1# set interface fe-1/2/0.2 metric 600 user@R1# set interface lo0.1 passive
metric
此处的语句用于展示当 IGP 指标发生变化时会发生什么。配置接受直接路由的策略。
此方案的其他有用选项可能是接受通过 OSPF 或本地路由获知的路由。
[edit policy-options policy-statement send-direct term 1] user@R1# set from protocol direct user@R1# set then accept
配置路由器 ID 和自治系统 (AS) 编号。
[edit routing-options] user@R1# set router-id 192.168.0.1 user@R1# set autonomous-system 1
结果
在配置模式下,输入 show interfaces
、 show policy-options
、 show protocols
和 show routing-options
命令,以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明,以更正配置。
user@R1# show interfaces fe-1/2/0 { unit 2 { description R1->R2; family inet { address 10.0.0.1/30; } } } fe-1/2/1 { unit 7 { description R1->R4; family inet { address 172.16.0.1/30; } } } lo0 { unit 1 { family inet { address 192.168.0.1/32; } } }
user@R1# show policy-options policy-statement send-direct { term 1 { from protocol direct; then accept; } }
user@R1# show protocols bgp { group internal { type internal; local-address 192.168.0.1; export send-direct; neighbor 192.168.0.2; neighbor 192.168.0.3; } group external { type external; metric-out igp delay-med-update; export send-direct; peer-as 2; neighbor 172.16.0.2; } } ospf { area 0.0.0.0 { interface fe-1/2/0.2 { metric 600; } interface lo0.1 { passive; } } }
user@R1# show routing-options med-igp-update-interval 12; router-id 192.168.0.1; autonomous-system 1;
完成设备配置后,请从配置模式进入 commit
。根据网络需要,在拓扑中的其他设备上重复配置步骤。
验证
确认配置工作正常。
检查 BGP 通告
目的
验证设备 R1 是否正在向设备 R4 发布反映 IGP 指标的 BGP MED 值。
行动
在操作模式下,输入 show route advertising-protocol bgp
命令。
user@R1> show route advertising-protocol bgp 172.16.0.2 inet.0: 19 destinations, 33 routes (19 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 10.0.0.0/30 Self 0 I * 172.16.0.0/30 Self 0 I * 172.16.0.4/30 Self 601 I * 192.168.0.1/32 Self 0 I
含义
MED 列中的 601 值表示 MED 值已更新,以反映配置的 OSPF 指标。
验证当 OSPF 指标发生变化时 MED 值是否发生变化
目的
请确保将 OSPF 指标提高到 700 时,MED 值已更新以反映此更改。
行动
在配置模式下,输入 set protocols ospf area 0 interface fe-1/2/0.2 metric 700
命令。
user@R1# set protocols ospf area 0 interface fe-1/2/0.2 metric 700 user@R1# commit
等待 12 分钟(配置的延迟期)后,在 show route advertising-protocol bgp
操作模式下输入命令。
user@R1> show route advertising-protocol bgp 172.16.0.2 inet.0: 19 destinations, 33 routes (19 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 10.0.0.0/30 Self 0 I * 172.16.0.0/30 Self 0 I * 172.16.0.4/30 Self 701 I * 192.168.0.1/32 Self 0 I
含义
MED 列中的 701 值表示 MED 值已更新,以反映配置的 OSPF 指标。
测试最小 igp 设置
目的
将配置更改为使用 minimum-igp
语句,而非语句 igp
。增加 OSPF 指标时,MED 值保持不变,但当您减少 OSPF 指标时,MED 值将反映新的 OSPF 指标。
行动
在配置模式下,删除 igp
语句,添加 minimum-igp
语句,然后增加 OSPF 指标。
user@R1# delete protocols bgp group external metric-out igp user@R1# set protocols bgp group external metric-out minimum-igp user@R1# set protocols ospf area 0 interface fe-1/2/0.2 metric 800 user@R1# commit
在操作模式下,输入 show route advertising-protocol bgp
命令以确保 MED 值不会更改。
user@R1> show route advertising-protocol bgp 172.16.0.2 inet.0: 19 destinations, 33 routes (19 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 10.0.0.0/30 Self 0 I * 172.16.0.0/30 Self 0 I * 172.16.0.4/30 Self 701 I * 192.168.0.1/32 Self 0 I
在配置模式下,降低 OSPF 指标。
user@R1# set protocols ospf area 0 interface fe-1/2/0.2 metric 20 user@R1# commit
在操作模式下,输入 show route advertising-protocol bgp
命令以确保 MED 值发生变化。
user@R1> show route advertising-protocol bgp 172.16.0.2 inet.0: 19 destinations, 33 routes (19 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 10.0.0.0/30 Self 0 I * 172.16.0.0/30 Self 0 I * 172.16.0.4/30 Self 21 I * 192.168.0.1/32 Self 0 I
含义
minimum-igp
配置语句后,MED 值仅在较短路径可用时才会更改。