示例:使用路由过滤器配置 MED
此示例说明如何配置使用路由筛选器修改要在 BGP 更新消息中播发的多出口鉴别器 (MED) 指标的策略。
要求
在配置此示例之前,不需要除设备初始化之外的特殊配置。
概述
要配置在 BGP 更新消息中修改播发的 MED 指标的路由过滤器策略,请在策略操作中包含该 metric
语句。
图 1 显示了具有内部对等会话和到相邻自治系统 (AS) 的多个出口点的典型网络。
![具有 IBGP 会话和多个出口点的典型网络](../../../images/g041151.png)
设备 R4 具有多个环路接口,配置为模拟播发的前缀。额外的环路接口地址为 172.16.44.0/32 和 172.16.144.0/32。此示例说明如何配置设备 R4,以便为除 172.16.144.0 之外的所有路由将 MED 值 30 播发至设备 R3。对于 172.16.144.0,MED 值 10 将播发至设备 3。无论路由前缀如何,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
意义
输出显示,对于除 172.16.144.0/32 之外的所有路由,设备 R4 通告的路由的首选路径是通过设备 R2。对于 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 值。