示例:使用路由过滤器配置 MED-V
此示例演示如何配置使用路由过滤器修改多个退出鉴别器(MED-V)指标的策略,以便在 BGP 更新消息中公布。
要求
在配置此示例之前,不需要进行设备初始化以外的特殊配置。
概述
要配置在 BGP 更新消息中修改公布的中端指标的路由过滤器策略,请在metric策略操作中包含该语句。
图 1显示了带有内部对等会话的典型网络和邻接自治系统(AS)的多个出口点。

设备 R 4 有多个回传接口配置为模拟广告前缀。额外的回传接口地址为 172.16.44.0/32 和 172.16.144.0/32。此示例演示如何将设备 R 4 配置为向除172.16.144.0 以外的所有路由通告中值30到设备 R3。对于172.16.144.0,将向设备3通告 MED-V 值10。将中值20通告到设备 R2,而不考虑路由前缀。
配置
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除任何换行符,更改与网络配置匹配的必要详细信息,然后将命令复制并粘贴到[edit]层次结构级别的 CLI 中。
设备 R1
设备 R2
设备 R3
设备 R 4
配置设备 R1
分步过程
下面的示例要求您在配置层次结构中导航各个级别。有关导航 CLI 的信息,请参阅中的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 internaluser@R1# set local-address 192.168.1.1user@R1# set export send-directuser@R1# set neighbor 192.168.2.1user@R1# set neighbor 192.168.3.1
- 配置 OSPF。[edit protocols ospf area 0.0.0.0]user@R1# set interface lo0.1 passiveuser@R1# set interface fe-1/2/0.1user@R1# set interface fe-1/2/1.2
- 配置接受直接路由的策略。
此方案的其他有用选项可能是接受通过 OSPF 或本地路由获知的路由。
[edit policy-options policy-statement send-direct term 1]user@R1# set from protocol directuser@R1# set then accept - 配置路由器 ID 和自治系统(AS)编号。[edit routing-options]user@R1# set autonomous-system 123user@R1# set router-id 192.168.1.1
结果
从配置模式, show interfaces输入、 show protocolsshow policy-options、和show routing-options命令以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明以更正配置。
如果您完成了设备配置,请从commit配置模式进入。
配置设备 R2
分步过程
下面的示例要求您在配置层次结构中导航各个级别。有关导航 CLI 的信息,请参阅中的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 internaluser@R2# set local-address 192.168.2.1user@R2# set export send-directuser@R2# set neighbor 192.168.1.1user@R2# set neighbor 192.168.3.1[edit protocols bgp group external]user@R2# set type externaluser@R2# set export send-directuser@R2# set peer-as 4user@R2# set neighbor 172.16.24.4
- 配置 OSPF。[edit protocols ospf area 0.0.0.0]user@R2# set interface lo0.2 passiveuser@R2# set interface fe-1/2/0.3user@R2# set interface fe-1/2/1.4
- 配置接受直接路由的策略。
此方案的其他有用选项可能是接受通过 OSPF 或本地路由获知的路由。
[edit policy-options policy-statement send-direct term 1]user@R2# set from protocol directuser@R2# set then accept - 配置路由器 ID 和自治系统(AS)编号。[edit routing-options]user@R2# set autonomous-system 123user@R2# set router-id 192.168.2.1
结果
从配置模式, show interfaces输入、 show protocolsshow policy-options、和show routing-options命令以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明以更正配置。
如果您完成了设备配置,请从commit配置模式进入。
配置设备 R3
分步过程
下面的示例要求您在配置层次结构中导航各个级别。有关导航 CLI 的信息,请参阅中的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 internaluser@R3# set local-address 192.168.3.1user@R3# set export send-directuser@R3# set neighbor 192.168.1.1user@R3# set neighbor 192.168.2.1[edit protocols bgp group external]user@R3# set type externaluser@R3# set export send-directuser@R3# set peer-as 4user@R3# set neighbor 172.16.34.4
- 配置 OSPF。[edit protocols ospf area 0.0.0.0]user@R3# set interface lo0.3 passiveuser@R3# set interface fe-1/2/0.5user@R3# set interface fe-1/2/1.6
- 配置接受直接路由的策略。
此方案的其他有用选项可能是接受通过 OSPF 或本地路由获知的路由。
[edit policy-options policy-statement send-direct term 1]user@R3# set from protocol directuser@R3# set then accept - 配置路由器 ID 和自治系统(AS)编号。[edit routing-options]user@R3# set autonomous-system 123user@R3# set router-id 192.168.3.1
结果
从配置模式, show interfaces输入、 show protocolsshow policy-options、和show routing-options命令以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明以更正配置。
如果您完成了设备配置,请从commit配置模式进入。
配置设备 R 4
分步过程
下面的示例要求您在配置层次结构中导航各个级别。有关导航 CLI 的信息,请参阅中的CLI 用户指南在配置模式中使用 CLI 编辑器。
要配置设备 R 4:
- 配置设备接口。[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/32user@R4# set family inet address 172.16.44.0/32user@R4# set family inet address 172.16.144.0/32
设备 R 4 具有多个回传接口地址以模拟广告前缀。
- 配置接受直接路由的策略。
此方案的其他有用选项可能是接受通过 OSPF 或本地路由获知的路由。
[edit policy-options policy-statement send-direct term 1]user@R4# set from protocol directuser@R4# set then accept - 配置 BGP。[edit protocols bgp group external]user@R4# set type externaluser@R4# set export send-directuser@R4# set peer-as 123
- 配置两个 MED-V 策略。[edit policy-options]set policy-statement med-10 from route-filter 172.16.144.0/32 exactset policy-statement med-10 then metric 10set policy-statement med-10 then acceptset policy-statement med-30 from route-filter 0.0.0.0/0 longerset policy-statement med-30 then metric 30set policy-statement med-30 then accept
- 配置两个 EBGP 邻居,将两个 MED-V 策略应用于设备 R3,并将其中的中值20到设备 R2。[edit protocols bgp group external]user@R4# set neighbor 172.16.34.3 export med-10user@R4# set neighbor 172.16.34.3 export med-30user@R4# set neighbor 172.16.24.2 metric-out 20
- 配置路由器 ID 和自治系统(AS)编号。[edit routing-options]user@R4# set autonomous-system 4user@R4# set router-id 192.168.4.1
结果
从配置模式, show interfaces输入、 show protocolsshow policy-options、和show routing-options命令以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明以更正配置。
如果您完成了设备配置,请从commit配置模式进入。
针对
确认配置是否正常工作。
检查从设备 R1 到设备 R 4 的活动路径
用途
验证活动路径是否穿过设备 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
含义
输出显示,由设备 R 4 通告的路由的首选路径是通过设备 R2 (除 172.16.144.0/32 以外的所有路由)。对于 172.16.144.0/32,首选路径通过设备 R3。
验证设备 R 4 是否正确发送其路由
用途
确保设备 R 4 正在将值为20到 Device R2 的更新消息和值30发送到设备 R3。
操作
在操作模式下,输入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
含义
下列显示设备 R 4 正在将正确的 MED-V 值发送至其两个 EBGP 邻居。