示例:配置路由过滤器策略以指定通过 OSPF 获知的前缀的优先级
此示例说明如何创建 OSPF 导入策略,以优先处理通过 OSPF 获知的特定前缀。
要求
准备工作:
配置设备接口。请参阅 安全设备的接口用户指南。
为 OSPF 网络中的设备配置路由器标识符。请参阅 示例:配置 OSPF 路由器标识符。
控制 OSPF 指定路由器选择 请参阅 示例:控制 OSPF 指定路由器选择
配置单区域 OSPF 网络。请参阅 示例:配置单区域 OSPF 网络 。
配置多区域 OSPF 网络。请参阅 示例:配置多区域 OSPF 网络。
概述
在具有大量 OSPF 路由的网络中,控制路由的更新顺序以响应网络拓扑更改会很有用。在 Junos OS 9.3 及更高版本中,您可以为 OSPF 导入策略中包含的前缀指定高、中或低优先级。如果 OSPF 拓扑发生更改,将首先在路由表中更新高优先级前缀,然后更新中优先级前缀,然后更新低优先级前缀。
OSPF 导入策略只能用于设置优先级或过滤 OSPF 外部路由。如果应用的 OSPF 导入策略导致 对非外部路由执行终止操作,则会忽略该 操作,并且无论如何都会接受该路由。reject
reject
默认情况下,此类路由现在安装在优先级为低的路由表中。此行为通过确保 OSPF 域内的一致路由来防止流量黑洞,即静默丢弃的流量。
通常,未显式分配优先级的 OSPF 路由将被视为优先级介质,但以下情况除外:
摘要放弃路由的默认优先级为低。
未添加到路由表中的本地路由分配的优先级为低。
被导入策略拒绝并因此未添加到路由表中的外部路由将被分配低优先级。
任何适用于 OSPF 路由的可用匹配标准都可用于确定优先级。OSPF 最常用的两个匹配标准是 和 语句。route-filter
tag
在此示例中,路由设备位于区域 0.0.0.0 中,具有接口 并 连接到相邻设备。fe-0/1/0
fe-1/1/0
您可以配置名为 ospf-import 的导入路由策略,以指定通过 OSPF 获知的前缀的优先级。与这些前缀关联的路由将按前缀指定优先级的顺序安装在路由表中。首先安装匹配 的路由,因为它们的优先级为 。192.0.2.0/24 orlonger
high
接下来安装匹配 的路由,因为它们的优先级为 .198.51.100.0/24 orlonger
medium
路由匹配 项最后安装,因为它们的优先级为 。203.0.113.0/24 orlonger
low
然后,您将导入策略应用于 OSPF。
优先级值在安装新路由或对现有路由进行更改时生效。
拓扑
配置
CLI 快速配置
要快速配置 OSPF 导入策略,以优先处理通过 OSPF 获知的特定前缀,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改与您的网络配置匹配所需的任何详细信息,将命令复制并粘贴到 [edit] 层次结构级别的 CLI 中,然后从配置模式进入 。commit
[edit] set interfaces fe-0/1/0 unit 0 family inet address 192.168.8.4/30 set interfaces fe-0/1/0 unit 0 family inet address 192.168.8.5/30 set policy-options policy-statement ospf-import term t1 from route-filter 203.0.113.0/24 orlonger set policy-options policy-statement ospf-import term t1 then priority low set policy-options policy-statement ospf-import term t1 then accept set policy-options policy-statement ospf-import term t2 from route-filter 198.51.100.0/24 orlonger set policy-options policy-statement ospf-import term t2 then priority medium set policy-options policy-statement ospf-import term t2 then accept set policy-options policy-statement ospf-import term t3 from route-filter 192.0.2.0/24 orlonger set policy-options policy-statement ospf-import term t3 then priority high set policy-options policy-statement ospf-import term t3 then accept set protocols ospf import ospf-import set protocols ospf area 0.0.0.0 interface fe-0/1/0 set protocols ospf area 0.0.0.0 interface fe-1/1/0
程序
分步过程
下面的示例要求您在各个配置层级中进行导航。有关导航 CLI 的信息,请参阅CLI 用户指南中的修改 Junos OS 配置。Modifying the Configuration for a Devicehttps://www.juniper.net/documentation/en_US/junos/information-products/pathway-pages/junos-cli/junos-cli.html
要配置优先考虑特定前缀的 OSPF 导入策略,请执行以下操作:
配置接口。
[edit] user@host# set interfaces fe-0/1/0 unit 0 family inet address 192.168.8.4/30 user@host# set interfaces fe-0/2/0 unit 0 family inet address 192.168.8.5/30
在接口上启用 OSPF。
注:对于 OSPFv3,请在层次结构级别包含 语句 。
ospf3
[edit protocols]
[edit] user@host# set protocols ospf area 0.0.0.0 interface fe-0/1/0 user@host# set protocols ospf area 0.0.0.0 interface fe-0/2/0
配置策略以指定通过 OSPF 获知的前缀的优先级。
[edit ] user@host# set policy-options policy-statement ospf-import term t1 from route-filter 203.0.113.0/24 orlonger user@host# set policy-options policy-statement ospf-import term t1 then priority low user@host# set policy-options policy-statement ospf-import term t1 then accept user@host# set policy-options policy-statement ospf-import term t2 from route-filter 198.51.100.0/24 orlonger user@host# set policy-options policy-statement ospf-import term t2 then priority medium user@host# set policy-options policy-statement ospf-import term t2 then accept user@host# set policy-options policy-statement ospf-import term t3 from route-filter 192.0.2.0/24 orlonger user@host# set policy-options policy-statement ospf-import term t3 then priority high user@host# set policy-options policy-statement ospf-import term t3 then accept
将策略应用于 OSPF。
[edit] user@host# set protocols ospf import ospf-import
如果完成设备配置,请提交配置。
[edit] user@host# commit
成果
通过输入 、 和 命令来确认您的配置。show interfaces
show policy-options
show protocols ospf
如果输出未显示预期的配置,请重复此示例中的说明,以便进行更正。
user@host# show interfaces fe-0/1/0 { unit 0 { family inet { address 192.168.8.4/30; } } } fe-0/2/0 { unit 0 { family inet { address 192.168.8.5/30; } } }
user@host# show protocols ospf import ospf-import; area 0.0.0.0 { interface fe-0/1/0.0; interface fe-0/2/0.0; }
user@host# show policy-options policy-statement ospf-import { term t1 { from { route-filter 203.0.113.0/24 orlonger; } then { priority low; accept; } } term t2 { from { route-filter 198.51.100.0/24 orlonger; } then { priority medium; accept; } } term t3 { from { route-filter 192.0.2.0/24 orlonger; } then { priority high; accept; } } }
user@host# show protocols ospf import ospf-import; area 0.0.0.0 { interface fe-0/1/0.0; interface fe-0/2/0.0; }
要确认 OSPFv3 配置, 请输入 、 和 命令。show interfaces
show policy-options
show protocols ospf3