RIP 导入策略
了解 RIP 导入策略
默认 RIP 导入策略是接受通过健全性检查的所有接收 RIP 路由。要过滤由本地路由设备从其邻接方导入的路由,请包括语句 import
,并列出一个或多个要评估的策略的名称。如果指定了多个策略,则按顺序评估这些策略(从第一个到最后一个),并将第一个匹配策略应用于路由。如果未找到匹配项,则本地路由设备不会导入任何路由。请注意,Junos OS 15.1X49、15.1X49-D30 或 15.1X49-D40 版不支持将策略应用于本主题中描述的从邻接方导入的 RIP 路由的功能。
示例:对从邻接方导入的 RIP 路由应用策略
此示例说明如何在 RIP 网络中配置导入策略。
要求
配置此示例之前,不需要除设备初始化之外的特殊配置。
概述
在此示例中,设备 R1 的导入策略接受 10/8 和 192.168/16 RIP 路由,并拒绝所有其他 RIP 路由。这意味着从设备 R1 的路由表中排除了 172.16/16 RIP 路由。
同时显示导出策略,因为需要导出策略作为 RIP 的最低配置的一部分。
图 1 显示了此示例中使用的拓扑。

CLI 快速配置 显示了 图 1 中所有设备的配置。第 #d75e56__d75e199 节介绍了设备 R1 上的步骤。
拓扑
配置
程序
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,将命令复制并粘贴到层级的 [edit]
CLI 中,然后从配置模式进入 commit
。
设备 R1
set interfaces fe-1/2/0 unit 1 family inet address 10.0.0.1/30 set interfaces lo0 unit 1 family inet address 172.16.0.1/32 set interfaces lo0 unit 1 family inet address 192.168.1.1/32 set protocols rip import rip-import set protocols rip group rip-group export advertise-routes-through-rip set protocols rip group rip-group neighbor fe-1/2/0.1 set policy-options policy-statement advertise-routes-through-rip term 1 from protocol direct set policy-options policy-statement advertise-routes-through-rip term 1 from protocol rip set policy-options policy-statement advertise-routes-through-rip term 1 then accept set policy-options policy-statement rip-import term 1 from protocol rip set policy-options policy-statement rip-import term 1 from route-filter 10.0.0.0/8 orlonger set policy-options policy-statement rip-import term 1 from route-filter 192.168.0.0/16 orlonger set policy-options policy-statement rip-import term 1 then accept set policy-options policy-statement rip-import term 2 then reject
设备 R2
set interfaces fe-1/2/0 unit 2 family inet address 10.0.0.2/30 set interfaces fe-1/2/1 unit 5 family inet address 10.0.0.5/30 set interfaces lo0 unit 2 family inet address 192.168.2.2/32 set interfaces lo0 unit 2 family inet address 172.16.2.2/32 set protocols rip group rip-group export advertise-routes-through-rip set protocols rip group rip-group neighbor fe-1/2/0.2 set protocols rip group rip-group neighbor fe-1/2/1.5 set policy-options policy-statement advertise-routes-through-rip term 1 from protocol direct set policy-options policy-statement advertise-routes-through-rip term 1 from protocol rip set policy-options policy-statement advertise-routes-through-rip term 1 then accept
设备 R3
set interfaces fe-1/2/0 unit 6 family inet address 10.0.0.6/30 set interfaces lo0 unit 3 family inet address 192.168.3.3/32 set interfaces lo0 unit 3 family inet address 172.16.3.3/32 set protocols rip group rip-group export advertise-routes-through-rip set protocols rip group rip-group neighbor fe-1/2/0.6 set policy-options policy-statement advertise-routes-through-rip term 1 from protocol direct set policy-options policy-statement advertise-routes-through-rip term 1 from protocol rip set policy-options policy-statement advertise-routes-through-rip term 1 then accept
逐步过程
以下示例要求您在配置层次结构中的各个级别上导航。有关导航 CLI 的信息,请参阅 CLI 用户指南中的在配置模式下使用 CLI 编辑器。
要配置 RIP 导入策略:
配置网络接口。
此示例显示了多个用于模拟附加网络的环路接口地址。
[edit interfaces] user@R1# set fe-1/2/0 unit 1 family inet address 10.0.0.1/30 user@R1# set lo0 unit 1 family inet address 172.16.0.1/32 user@R1# set lo0 unit 1 family inet address 192.168.1.1/32
创建 RIP 组并添加接口。
要在 Junos OS 中配置 RIP,必须配置一个包含启用了 RIP 的接口的组。
无需在环路接口上启用 RIP。
[edit protocols rip group rip-group] user@R1# set neighbor fe-1/2/0.1
创建路由策略以播发直接路由和 RIP 学习路由。
[edit policy-options policy-statement advertise-routes-through-rip term 1] user@R1# set from protocol direct user@R1# set from protocol rip user@R1# set then accept
应用路由策略。
在 Junos OS 中,只能在组级别应用 RIP 导出策略。
[edit protocols rip group rip-group] user@R1# set export advertise-routes-through-rip
配置导入策略。
[edit policy-options policy-statement rip-import] user@R1# set term 1 from protocol rip user@R1# set term 1 from route-filter 10.0.0.0/8 orlonger user@R1# set term 1 from route-filter 192.168.0.0/16 orlonger user@R1# set term 1 then accept user@R1# set term 2 then reject
应用导入策略。
[edit protocols rip] user@R1# set import rip-import
结果
在配置模式下,输入 、 show protocols
和show policy-options
命令,show interfaces
以确认您的配置。如果输出未显示预期的配置,请重复此示例中的配置说明,以便进行更正。
user@R1# show interfaces
fe-1/2/0 {
unit 1 {
family inet {
address 10.0.0.1/30;
}
}
}
lo0 {
unit 1 {
family inet {
address 172.16.0.1/32;
address 192.168.1.1/32;
}
}
}
user@R1# show protocols
rip {
import rip-import;
group rip-group {
export advertise-routes-through-rip;
neighbor fe-1/2/0.1;
}
}
user@R1# show policy-options
policy-statement advertise-routes-through-rip {
term 1 {
from protocol [ direct rip ];
then accept;
}
}
policy-statement rip-import {
term 1 {
from {
protocol rip;
route-filter 10.0.0.0/8 orlonger;
route-filter 192.168.0.0/16 orlonger;
}
then accept;
}
term 2 {
then reject;
}
}
完成设备配置后,请在配置模式下输入 提交 。
验证
确认配置工作正常。
查看设备 R2 向设备 R1 传播的路由
目的
验证设备 R2 是否正在发送预期的路由。
行动
在操作模式下,输入 show route advertising-protocol rip
命令。
user@R2> show route advertising-protocol rip 10.0.0.2 inet.0: 11 destinations, 11 routes (11 active, 0 holddown, 0 hidden) + = Active Route, - = Last Active, * = Both 10.0.0.4/30 *[Direct/0] 2d 01:17:44 > via fe-1/2/0.5 172.16.2.2/32 *[Direct/0] 2d 04:09:52 > via lo0.2 172.16.3.3/32 *[RIP/100] 23:40:02, metric 2, tag 0 > to 10.0.0.6 via fe-1/2/0.5 192.168.2.2/32 *[Direct/0] 2d 04:09:52 > via lo0.2 192.168.3.3/32 *[RIP/100] 23:40:02, metric 2, tag 0 > to 10.0.0.6 via fe-1/2/0.5
意义
设备 R2 正在向设备 R1 发送 172.16/16 路由。
查看设备 R1 从设备 R2 接收的路由
目的
验证设备 R1 是否接收预期的路由。
行动
在操作模式下,输入 show route receive-protocol rip
命令。
user@R1> show route receive-protocol rip 10.0.0.2 inet.0: 8 destinations, 8 routes (8 active, 0 holddown, 0 hidden) + = Active Route, - = Last Active, * = Both 10.0.0.4/30 *[RIP/100] 01:06:03, metric 2, tag 0 > to 10.0.0.2 via fe-1/2/0.1 192.168.2.2/32 *[RIP/100] 01:06:03, metric 2, tag 0 > to 10.0.0.2 via fe-1/2/0.1 192.168.3.3/32 *[RIP/100] 01:06:03, metric 3, tag 0 > to 10.0.0.2 via fe-1/2/0.1
意义
输出显示排除了 172.16/16 路由。
检查路由表
目的
验证路由表是否填充了预期的路由。
行动
在操作模式下,输入 show route protocol rip
命令。
user@R1> show route protocol rip inet.0: 8 destinations, 8 routes (8 active, 0 holddown, 0 hidden) + = Active Route, - = Last Active, * = Both 10.0.0.4/30 *[RIP/100] 00:54:34, metric 2, tag 0 > to 10.0.0.2 via fe-1/2/0.1 192.168.2.2/32 *[RIP/100] 00:54:34, metric 2, tag 0 > to 10.0.0.2 via fe-1/2/0.1 192.168.3.3/32 *[RIP/100] 00:54:34, metric 3, tag 0 > to 10.0.0.2 via fe-1/2/0.1 224.0.0.9/32 *[RIP/100] 00:49:00, metric 1 MultiRecv
意义
输出显示,已从设备 R2 和设备 R3 获知路由。
如果删除或停用导入策略,则路由表将包含 172.16/16 路由。