示例:配置路由过滤器列表
Junos OS 长期以来一直支持在策略语句中使用的路由过滤器。每当更改策略时,都必须按照策略内联处理路由过滤器。加载包含大量路由筛选器的策略需要一些时间。
此示例说明如何创建路由过滤器列表并在策略语句中使用该列表。路由过滤器列表可减少重新加载给定策略所需的时间。
当只有几个路由过滤器要处理时,使用路由过滤器列表代替单个路由过滤器条目没有速度优势。速度优势主要体现在策略中列出了数百或数千个路由过滤器的环境中。
要求
配置了路由协议(如 BGP 或 OSPF)的路由器,正在主动与其对等方交换路由信息。
配置了路由过滤器列表的路由器必须运行 Junos OS 15.2 或更高版本。
概述
该 语句允许创建用于路由策略的预定义路由过滤器列表。route-filter-list
您可以在 层次结构级别配置列表。[edit policy-options]
然后,在层次结构级别的策略语句部分中,将配置的路由过滤器列表作为匹配条件引用。from
[edit policy-options policy-statement policy-statement-name term term-name 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 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改与您的网络配置匹配所需的任何详细信息,然后将命令复制并粘贴到层次结构级别的 CLI 中。[edit]
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 编辑器https://www.juniper.net/documentation/en_US/junos/information-products/pathway-pages/junos-cli/junos-cli.html
以下分步过程将引导您完成所需的步骤:
配置名为 并填充该列表的路由过滤器列表,以便以后在路由策略中使用。
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
验证
验证配置的路由过滤器列表
目的
要确认路由过滤器列表配置正确,请在层次结构级别发出 命令 。show policy-options route-filter-list route-filter-list-name
[edit]
操作
[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;
意义
输出显示存储的配置正确。
验证配置的策略语句
目的
要确认策略语句配置正确,请在层次结构级别发出命令。show policy-options policy-statement policy-statement-name
[edit]
操作
[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;
意义
outptut 确认存储的配置正确。
如果尚未执行此操作,则可以在层次结构级别发出命令,以便激活配置。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
意义
输出显示,先前安装的五个 BGP 路由中的三个已被策略语句 拒绝。rf-test-policy
上一个列表中保留的唯一路由是 将操作列为筛选器定义一部分的两个路由。accept
其他路由被 的操作 拒绝。policy-statement