示例:配置路由过滤器列表
长期以来,Junos OS 一直支持在策略语句中使用路由过滤器。每当策略发生更改时,都必须与策略内联处理路由过滤器。包含大量路由过滤器的策略需要时间才能加载。
此示例说明了如何创建路由过滤器列表并在策略语句中使用该列表。路由过滤器列表减少了重新加载给定策略所需的时间。
当只有几个路由过滤器要处理时,使用路由过滤器列表代替单个路由过滤器条目没有速度优势。速度优势主要体现在策略中列出了数百个或数千个路由过滤器的环境中。
要求
-
配置了路由协议(如 BGP 或 OSPF)的路由器,正在与对等方积极交换路由信息。
-
配置了路由过滤器列表的路由器必须运行 Junos OS 15.2 或更高版本。
概述
该route-filter-list语句允许创建预定义的路由过滤器列表,以用于路由策略。在层次结构级别配置[edit policy-options]此列表。然后,配置的路由过滤器列表将作为匹配条件在层次结构级别的[edit policy-options policy-statement policy-statement-name term term-name from]策略语句部分中from引用。
在此示例中,您正在配置的路由器从其 BGP 邻接方 192.0.2.1 接收一些路由。这如操作命令的 show route receive-protocol bgp 192.0.2.1 输出所示。
user@router> show route receive-protocol bgp 192.0.2.1
inet.0: 17 destinations, 18 routes (16 active, 0 holddown, 1 hidden)
Prefix Nexthop MED Lclpref AS path
* 198.151.100.0/29 192.0.2.1 103 I
* 198.151.100.8/29 192.0.2.1 103 I
* 203.0.113.0/29 192.0.2.1 103 I
* 203.0.113.8/29 192.0.2.1 103 I
* 203.0.113.16/29 192.0.2.1 103 I
配置
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,然后将命令复制并粘贴到层次结构级别的 [edit] CLI 中。
set policy-options route-filter-list rf-list-1 203.0.113.0/29 exact set policy-options route-filter-list rf-list-1 203.0.113.8/29 exact set policy-options route-filter-list rf-list-1 203.0.113.16/29 orlonger accept set policy-options policy-statement rf-test-policy term term2 from route-filter 198.51.100.0/29 upto 198.51.100.0/30 set policy-options policy-statement rf-test-policy term term2 from route-filter 198.51.100.8/29 upto 198.51.100.8/30 accept set policy-options policy-statement rf-test-policy term term2 from route-filter-list rf-list-1 set policy-options policy-statement rf-test-policy then reject set protocols bgp group test-group import rf-test-policy
过程
分步程序
下面的示例要求您在各个配置层级中进行导航。有关导航CLI的信息,请参阅《Junos OS CLI 用户指南》中的在配置模式下使用CLI编辑器。
以下分步过程将引导您完成以下所需步骤:
-
配置一个路由过滤器列表,命名
rf-list-1并填充该列表,以便以后在路由策略中使用。 -
配置名为 的路由策略语句,该语句
rf-test-policy使用路由过滤器和配置的路由过滤器列表。 -
将 BGP 配置为用作
rf-test-policy导入过滤器。
-
配置命名为
rf-list-1稍后在路由策略中使用的路由过滤器列表。[edit policy-options] user@router# set route-filter-list rf-list-1
-
填充列表
rf-list-1。请注意,列表中的一个语句配置了操作。此操作将在与收到的目标前缀匹配后立即执行。
[edit policy-options] user@router# set route-filter-list rf-list-1 203.0.113.0/29 exact user@router# set route-filter-list rf-list-1 203.0.113.8/29 exact user@router# set route-filter-list rf-list-1 203.0.113.16/29 orlonger accept
-
配置名为 的路由策略语句,该语句
rf-test-policy使用路由过滤器和配置的路由过滤器列表。此策略的总体操作是
reject.路由过滤器列表中的各个路由过滤器和元素配置了accept操作 。在单个路由过滤器语句和路由过滤器列表中的元素中配置的操作将在匹配收到的目标前缀后立即执行。[edit policy-options] user@router# set policy-statement rf-test-policy term term2 from route-filter 198.51.100.0/29 upto 198.51.100.0/30 user@router# set policy-statement rf-test-policy term term2 from route-filter 198.51.100.8/29 upto 198.51.100.8/30 accept user@router# set policy-statement rf-test-policy term term2 from route-filter-list rf-list-1 user@router# set policy-statement rf-test-policy then reject
-
将 BGP 配置为将配置的策略用作导入过滤器,以有选择地允许某些路由并拒绝将其他路由添加到路由表中。
[edit protocols bgp group test-group] user@router# set import rf-test-policy
验证
验证配置的路由过滤器列表
目的
要确认路由过滤器列表配置正确,请在层次结构级别发出[edit]命令show policy-options route-filter-list route-filter-list-name。
行动
[edit] user@routershow policy-options route-filter-list rf-list-1 203.0.113.0/29 exact; 203.0.113.8/29 exact; 203.0.113.16/29 orlonger accept;
意义
输出显示存储的配置是正确的。
验证配置的策略语句
目的
要确认策略语句配置正确,请在层次结构级别发出[edit]命令show policy-options policy-statement policy-statement-name。
行动
[edit]
user@router# show policy-options policy-statement rf-test-policy
from {
route-filter 198.51.100.0/29 upto 198.51.100.0/30;
route-filter 198.51.100.8/29 upto 198.51.100.8/30 accept;
route-filter-list rf-list-1;
}
then reject;
意义
输出确认存储的配置正确无误。
验证策略语句是否已作为 BGP 协议中的导入策略应用
目的
要确认配置的策略语句已作为 BGP 协议中的导入策略应用,请在层次结构级别发出show protocols bgp import[edit]命令。
行动
[edit] user@router# show protocols bgp import import rf-test-policy;
意义
输出确认存储的配置正确无误。
如果尚未在层次结构级别发出命令commit[edit],以便使配置处于活动状态。
验证路由过滤器列表是否按预期运行
目的
现在,配置已验证并提交,请发出 show route receive-protocol bgp 192.0.2.1 操作命令来确认路由过滤器列表的操作。
行动
如果将此输出与配置路由过滤器列表和策略语句之前发出的同一命令的输出进行比较,您会看到路由表中不再安装某些路由。
user@router> show route receive-protocol bgp 192.0.2.1
inet.0: 14 destinations, 15 routes (13 active, 0 holddown, 1 hidden)
Prefix Nexthop MED Lclpref AS path
* 198.151.100.8/29 192.0.2.1 103 I
* 203.0.113.16/29 192.0.2.1 103 I
意义
输出显示,之前安装的 5 个 BGP 路由中有 3 个已被 policy 语句 rf-test-policy拒绝。上一个列表中唯一保留的路由是将操作列为过滤器定义一部分的 accept 两条路由。其他路由被 的行动 policy-statement拒绝。