示例:配置策略链和路由过滤器
策略链是在配置的特定部分中应用多个策略。路由过滤器是匹配前缀的集合。
要求
配置此示例之前,不需要除设备初始化之外的特殊配置。
概述
应用于 BGP 的策略链示例如下:
user@R1# show protocols bgp group int { type internal; local-address 192.168.0.1; export [ adv-statics adv-large-aggregates adv-small-aggregates ]; neighbor 192.168.0.2; neighbor 192.168.0.3; }
adv-statics
除了adv-large-aggregates
默认 BGP 策略之外,、 和adv-small-aggregates
策略还构成了应用于设备 R1 的 BGP 对等方的策略链。其中两个策略演示了具有不同匹配类型的路由过滤器。另一个策略匹配所有静态路由,因此不需要路由筛选器。
user@R1# show policy-options policy-statement adv-large-aggregates { term between-16-and-18 { from { protocol aggregate; route-filter 172.16.0.0/16 upto /18; } then accept; } } policy-statement adv-small-aggregates { term between-19-and-24 { from { protocol aggregate; route-filter 172.16.0.0/16 prefix-length-range /19-/24; } then accept; } } policy-statement adv-statics { term statics { from protocol static; then accept; } }
或者,您可以将此策略链转换为内部 BGP (IBGP) 对等方的单个多期限策略。如果这样做,策略链的优势之一就会丧失 — 为不同目的重用策略的能力。
图 1 显示 AS 64510 中的设备 R1 及其 IBGP 对等方、设备 R2 和设备 R3。设备 R1 也有到 AS 64511 中设备 R4 和 AS 64512 中设备 R5 的外部 BGP (EBGP) 连接。AS 64510 的当前管理策略是只将客户静态路由发送至其他 IBGP 对等方。任何提供中转服务的 EBGP 对等方仅接收掩码长度小于 18 位的聚合路由。任何提供对等服务的 EBGP 对等方都会接收掩码长度大于 19 位的所有客户路由和所有聚合。这些管理策略的每个部分都在配置层次结构中的 [edit policy-opitons]
单独路由策略中配置。这些策略向 AS 64510 的管理员提供多个配置选项,用于向对等方播发路由。
设备 R4 正在向 AS 64510 提供过渡服务,允许 AS 向互联网播发其分配的路由空间。另一方面,设备 R5 提供的对等服务允许 AS 64510 在所有客户路由的自治系统 (AS) 之间直接路由流量。
配置
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改与您的网络配置匹配所需的任何详细信息,然后将命令复制并粘贴到层次结构级别的 CLI [edit]
中。
设备 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 fe-1/2/2 unit 0 description to_R3 set interfaces fe-1/2/2 unit 0 family inet address 10.0.0.5/30 set interfaces fe-1/2/3 unit 0 description to_R4 set interfaces fe-1/2/3 unit 0 family inet address 10.1.0.5/30 set interfaces fe-1/2/1 unit 0 description to_R5 set interfaces fe-1/2/1 unit 0 family inet address 10.0.0.10/30 set interfaces lo0 unit 0 family inet address 192.168.0.1/32 set protocols bgp group int type internal set protocols bgp group int local-address 192.168.0.1 set protocols bgp group int export adv-statics set protocols bgp group int export adv-large-aggregates set protocols bgp group int export adv-small-aggregates set protocols bgp group int neighbor 192.168.0.2 set protocols bgp group int neighbor 192.168.0.3 set protocols bgp group to_64511 type external set protocols bgp group to_64511 export adv-large-aggregates set protocols bgp group to_64511 neighbor 10.1.0.6 peer-as 64511 set protocols bgp group to_64512 type external set protocols bgp group to_64512 export adv-small-aggregates set protocols bgp group to_64512 export adv-statics set protocols bgp group to_64512 neighbor 10.0.0.9 peer-as 64512 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/2.0 set protocols ospf area 0.0.0.0 interface lo0.0 passive set policy-options policy-statement adv-large-aggregates term between-16-and-18 from protocol aggregate set policy-options policy-statement adv-large-aggregates term between-16-and-18 from route-filter 172.16.0.0/16 upto /18 set policy-options policy-statement adv-large-aggregates term between-16-and-18 then accept set policy-options policy-statement adv-small-aggregates term between-19-and-24 from protocol aggregate set policy-options policy-statement adv-small-aggregates term between-19-and-24 from route-filter 172.16.0.0/16 prefix-length-range /19-/24 set policy-options policy-statement adv-small-aggregates term between-19-and-24 then accept set policy-options policy-statement adv-statics term statics from protocol static set policy-options policy-statement adv-statics term statics then accept set routing-options static route 172.16.1.16/28 discard set routing-options static route 172.16.1.32/28 discard set routing-options static route 172.16.1.48/28 discard set routing-options static route 172.16.1.64/28 discard set routing-options aggregate route 172.16.0.0/16 set routing-options aggregate route 172.16.1.0/24 set routing-options router-id 192.168.0.1 set routing-options autonomous-system 64510
设备 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.1.0.1/30 set interfaces lo0 unit 0 family inet address 192.168.0.2/32 set protocols bgp group int type internal set protocols bgp group int local-address 192.168.0.2 set protocols bgp group int neighbor 192.168.0.1 export send-static-aggregate set protocols bgp group int neighbor 192.168.0.3 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 protocols ospf area 0.0.0.0 interface lo0.0 passive set policy-options policy-statement send-static-aggregate term 1 from protocol static set policy-options policy-statement send-static-aggregate term 1 from protocol aggregate set policy-options policy-statement send-static-aggregate term 1 then accept set routing-options static route 172.16.2.16/28 discard set routing-options static route 172.16.2.32/28 discard set routing-options static route 172.16.2.48/28 discard set routing-options static route 172.16.2.64/28 discard set routing-options aggregate route 172.16.2.0/24 set routing-options aggregate route 172.16.0.0/16 set routing-options router-id 192.168.0.2 set routing-options autonomous-system 64510
设备 R3
set interfaces fe-1/2/1 unit 0 description to_R2 set interfaces fe-1/2/1 unit 0 family inet address 10.1.0.2/30 set interfaces fe-1/2/2 unit 0 description to_R1 set interfaces fe-1/2/2 unit 0 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 neighbor 192.168.0.1 export send-static-aggregate set protocols bgp group int neighbor 192.168.0.2 set protocols ospf area 0.0.0.0 interface fe-1/2/2.0 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 policy-options policy-statement send-static-aggregate from protocol static set policy-options policy-statement send-static-aggregate from protocol aggregate set policy-options policy-statement send-static-aggregate then accept set routing-options static route 172.16.3.16/28 discard set routing-options static route 172.16.3.32/28 discard set routing-options static route 172.16.3.48/28 discard set routing-options static route 172.16.3.64/28 discard set routing-options aggregate route 172.16.0.0/16 set routing-options aggregate route 172.16.3.0/24 set routing-options router-id 192.168.0.3 set routing-options autonomous-system 64510
设备 R4
set interfaces fe-1/2/3 unit 0 description to_R1 set interfaces fe-1/2/3 unit 0 family inet address 10.1.0.6/30 set interfaces lo0 unit 0 family inet address 192.168.0.4/32 set protocols bgp group ext type external set protocols bgp group ext peer-as 64510 set protocols bgp group ext neighbor 10.1.0.5 set routing-options autonomous-system 64511
设备 R5
set interfaces fe-1/2/1 unit 0 description to_R1 set interfaces fe-1/2/1 unit 0 family inet address 10.0.0.9/30 set interfaces lo0 unit 0 family inet address 192.168.0.5/32 set protocols bgp group ext type external set protocols bgp group ext neighbor 10.0.0.10 peer-as 64510 set routing-options autonomous-system 64512
程序
分步过程
以下示例要求您在配置层次结构中导航各个级别。有关导航 CLI 的信息,请参阅 在配置模式下使用 CLI 编辑器Junos OS CLI 用户指南。
要配置设备 R1:
配置设备接口。
[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.0.0.1/30 user@R1# set fe-1/2/2 unit 0 description to_R3 user@R1# set fe-1/2/2 unit 0 family inet address 10.0.0.5/30 user@R1# set fe-1/2/3 unit 0 description to_R4 user@R1# set fe-1/2/3 unit 0 family inet address 10.1.0.5/30 user@R1# set fe-1/2/1 unit 0 description to_R5 user@R1# set fe-1/2/1 unit 0 family inet address 10.0.0.10/30 user@R1# set lo0 unit 0 family inet address 192.168.0.1/32
配置与设备 R2 和设备 R3 的 IBGP 连接。
[edit protocols bgp group int] user@R1# set type internal user@R1# set local-address 192.168.0.1 user@R1# set neighbor 192.168.0.2 user@R1# set neighbor 192.168.0.3
为内部对等方应用导出策略。
[edit protocols bgp group int] user@R1# set export adv-statics user@R1# set export adv-large-aggregates user@R1# set export adv-small-aggregates
配置与设备 R4 的 EBGP 连接。
[edit protocols bgp group to_64511] user@R1# set type external user@R1# set neighbor 10.1.0.6 peer-as 64511
应用设备 R4 的导出策略。
[edit protocols bgp group to_64511] user@R1# set export adv-large-aggregates
配置与设备 R5 的 EBGP 连接。
[edit protocols bgp group to_64512] user@R1# set type external user@R1# set neighbor 10.0.0.9 peer-as 64512
应用设备 R5 的导出策略。
[edit protocols bgp group to_64512] user@R1# set export adv-small-aggregates user@R1# set export adv-statics
配置与设备 R2 和设备 R3 的 OSPF 连接。
[edit protocols ospf area 0.0.0.0] user@R1# set interface fe-1/2/0.0 user@R1# set interface fe-1/2/2.0 user@R1# set interface lo0.0 passive
配置路由策略。
[edit policy-options policy-statement adv-large-aggregates term between-16-and-18] user@R1# set from protocol aggregate user@R1# set from route-filter 172.16.0.0/16 upto /18 user@R1# set then accept [edit policy-options policy-statement adv-small-aggregates term between-19-and-24] user@R1# set from protocol aggregate user@R1# set from route-filter 172.16.0.0/16 prefix-length-range /19-/24 user@R1# set then accept [edit policy-options policy-statement adv-statics term statics] user@R1# set from protocol static user@R1# set then accept
配置静态路由和聚合路由。
[edit routing-options static] user@R1# set route 172.16.1.16/28 discard user@R1# set route 172.16.1.32/28 discard user@R1# set route 172.16.1.48/28 discard user@R1# set route 172.16.1.64/28 discard [edit routing-options aggregate] user@R1# set route 172.16.0.0/16 user@R1# set route 172.16.1.0/24
配置自治系统 (AS) 编号和路由器 ID。
[edit routing-options] user@R1# set router-id 192.168.0.1 user@R1# set autonomous-system 64510
结果
在配置模式下,输入 show interfaces
、show protocols
、show policy-options
和 show routing-options
命令,以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明,以便进行更正。
user@R1# show interfaces fe-1/2/0 { unit 0 { description to_R2; family inet { address 10.0.0.1/30; } } } fe-1/2/2 { unit 0 { description to_R3; family inet { address 10.0.0.5/30; } } } fe-1/2/3 { unit 0 { description to_R4; family inet { address 10.1.0.5/30; } } } fe-1/2/1 { unit 0 { description to_R5; family inet { address 10.0.0.10/30; } } } lo0 { unit 0 { family inet { address 192.168.0.1/32; } } }
user@R1# show protocols bgp { group int { type internal; local-address 192.168.0.1; export [ adv-statics adv-large-aggregates adv-small-aggregates ]; neighbor 192.168.0.2; neighbor 192.168.0.3; } group to_64511 { type external; export adv-large-aggregates; neighbor 10.1.0.6 { peer-as 64511; } } group to_64512 { type external; export [ adv-small-aggregates adv-statics ]; neighbor 10.0.0.9 { peer-as 64512; } } } ospf { area 0.0.0.0 { interface fe-1/2/0.0; interface fe-1/2/2.0; interface lo0.0 { passive; } } }
user@R1# show policy-options policy-statement adv-large-aggregates { term between-16-and-18 { from { protocol aggregate; route-filter 172.16.0.0/16 upto /18; } then accept; } } policy-statement adv-small-aggregates { term between-19-and-24 { from { protocol aggregate; route-filter 172.16.0.0/16 prefix-length-range /19-/24; } then accept; } } policy-statement adv-statics { term statics { from protocol static; then accept; } }
user@R1# show routing-options static { route 172.16.1.16/28 discard; route 172.16.1.32/28 discard; route 172.16.1.48/28 discard; route 172.16.1.64/28 discard; } aggregate { route 172.16.0.0/16; route 172.16.1.0/24; } router-id 192.168.0.1; autonomous-system 64510;
如果完成设备配置,请从配置模式输入 commit
。
验证
确认配置工作正常。
验证发往设备 R4 的路由播发
目的
在设备 R1 上,确保将客户路由播发到设备 R4。
操作
user@R1> show route advertising-protocol bgp 10.1.0.6 inet.0: 29 destinations, 31 routes (29 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 172.16.0.0/16 Self I * 172.16.2.0/24 Self I * 172.16.2.16/28 Self I * 172.16.2.32/28 Self I * 172.16.2.48/28 Self I * 172.16.2.64/28 Self I * 172.16.3.0/24 Self I * 172.16.3.16/28 Self I * 172.16.3.32/28 Self I * 172.16.3.48/28 Self I * 172.16.3.64/28 Self I
意义
该 adv-large-aggregates
策略将应用于与设备 R4 的对等会话,以通告子网掩码长度在 16 到 18 位之间的聚合路由。172.16.0.0/16 聚合路由正在按照管理策略的定义发送,但许多其他具有较大子网掩码的路由也将发送到设备 R4。
检查较长路由的始发位置
目的
在设备 R1 上,找到其他路由的来源。
操作
user@R1> show route 172.16.3.16/28 inet.0: 29 destinations, 31 routes (29 active, 0 holddown, 0 hidden) + = Active Route, - = Last Active, * = Both 172.16.3.16/28 *[BGP/170] 20:16:00, localpref 100, from 192.168.0.3 AS path: I, validation-state: unverified > to 10.0.0.6 via fe-1/2/2.0
意义
设备 R1 已通过与设备 R3 的 BGP 会话获知此路由。由于它是活动的 BGP 路由,因此 BGP 默认策略会自动播发。请记住,默认策略始终应用于每个策略链的末尾。需要的是一个策略来阻止播发更具体的路由。
阻止更具体的路由
目的
创建一个名为的策略 not-larger-than-18
,该策略拒绝 172.16.0.0 /16 地址空间中子网掩码长度大于或等于 19 位的所有路由。这可确保通告掩码介于 16 和 18 位之间的所有聚合,从而实现管理策略的目标。
操作
在设备 R1 上,配置
not-larger-than-18
策略。[edit policy-options policy-statement not-larger-than-18 term reject-greater-than-18-bits] user@R1# set from route-filter 172.16.0.0/16 prefix-length-range /19-/32 user@R1# set then reject
在设备 R1 上,将策略应用于与设备 R4 的对等会话。
[edit protocols bgp group to_64511] user@R1# set export not-larger-than-18 user@R1# commit
在设备 R1 上,检查哪些路由播发到设备 R4。
user@R1> show route advertising-protocol bgp 10.1.0.6 inet.0: 29 destinations, 31 routes (29 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 172.16.0.0/16 Self I
意义
策略链工作正常。只有 172.16.0.0 /16 路由播发到设备 R4。
验证到设备 R5 的路由播发
目的
在设备 R1 上,确保将客户路由播发到设备 R5。
设备 R5 是 AS 64512 中设备 R1 的 EBGP 对等方。管理策略规定,此对等方仅接收长度大于 18 位的聚合路由和所有客户路由。如果预期会遇到与设备 R4 上的问题类似的问题,您可以创建一个名为的策略 not-smaller- than-18
,以拒绝掩码长度在 16 到 18 位之间的所有聚合。
操作
在设备 R2 上,为 172.16.128.0/17 配置聚合路由。
[edit routing-options aggregate] user@R2# set route 172.16.128.0/17 discard user@R2# commit
在设备 R1 上,检查哪些路由播发到设备 R5。
user@R1> show route advertising-protocol bgp 10.0.0.9 inet.0: 30 destinations, 32 routes (30 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 172.16.1.0/24 Self I * 172.16.1.16/28 Self I * 172.16.1.32/28 Self I * 172.16.1.48/28 Self I * 172.16.1.64/28 Self I * 172.16.2.0/24 Self I * 172.16.2.16/28 Self I * 172.16.2.32/28 Self I * 172.16.2.48/28 Self I * 172.16.2.64/28 Self I * 172.16.3.0/24 Self I * 172.16.3.16/28 Self I * 172.16.3.32/28 Self I * 172.16.3.48/28 Self I * 172.16.3.64/28 Self I * 172.16.128.0/17 Self I
聚合路由 172.16.128.0/17 被通告,违反了管理策略
在设备 R1 上,配置
not-smaller-than-18
策略。[edit policy-options policy-statement not-smaller-than-18 term reject-less-than-18-bits] user@R1# set from protocol aggregate user@R1# set from route-filter 172.16.0.0/16 upto /18 user@R1# set then reject
在设备 R1 上,将策略应用于与设备 R5 的对等会话。
[edit protocols bgp group to_64512] user@R1# set export not-smaller-than-18 user@R1# commit
在设备 R1 上,检查哪些路由播发到设备 R5。
user@R1> show route advertising-protocol bgp 10.0.0.9 inet.0: 29 destinations, 31 routes (29 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 172.16.1.0/24 Self I * 172.16.1.16/28 Self I * 172.16.1.32/28 Self I * 172.16.1.48/28 Self I * 172.16.1.64/28 Self I * 172.16.2.0/24 Self I * 172.16.2.16/28 Self I * 172.16.2.32/28 Self I * 172.16.2.48/28 Self I * 172.16.2.64/28 Self I * 172.16.3.0/24 Self I * 172.16.3.16/28 Self I * 172.16.3.32/28 Self I * 172.16.3.48/28 Self I * 172.16.3.64/28 Self I
意义
策略链工作正常。仅聚合长度大于 18 位的路由和所有客户路由才会播发至设备 R5。