RIPng 导入策略
了解用于过滤路由的 RIPng 导入策略
默认的 RIPng 导入策略是接受通过有效性检查的所有接收 RIPng 路由。要过滤由本地路由设备从其邻接方导入的路由,请包含语句 import
并列出要评估的一个或多个策略的名称。如果指定了多个策略,则按顺序评估这些策略(从第一个到最后一个),并将第一个匹配策略应用于路由。如果未找到匹配项,则本地路由设备不会导入任何路由。
示例:将策略应用于从邻接方导入的 RIPng 路由
此示例说明如何在 RIPng 网络中配置导入策略。
要求
配置此示例之前,不需要除设备初始化之外的特殊配置。
概述
在此示例中,设备 R2 配置了多个额外的环路接口地址,以模拟其他网络。
设备 R1 的导入策略接受 fe80::/64 和 2001:db8:/64 路由并拒绝所有其他路由。这意味着设备 R2 播发的额外网络不会被接受到设备 R1 的路由表中。
导出策略也显示,因为需要导出策略作为 RIPng 的最低配置的一部分。
图 1 显示了此示例中使用的拓扑。
CLI 快速配置 显示了 图 1 中所有设备的配置。 第 #d81e58__d81e204 节介绍了设备 R1 上的步骤。
拓扑
配置
程序
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,然后将命令复制并粘贴到层级的 [edit]
CLI 中。
设备 R1
set interfaces fe-1/2/0 unit 1 description to-R2 set interfaces fe-1/2/0 unit 1 family inet6 address 2001:db8:0:1::/64 eui-64 set interfaces lo0 unit 1 family inet6 address 2001:db8::1/128 set protocols ripng group ripng-group export advertise-routes-through-ripng set protocols ripng group ripng-group neighbor fe-1/2/0.1 import ripng-import set policy-options policy-statement advertise-routes-through-ripng term 1 from protocol direct set policy-options policy-statement advertise-routes-through-ripng term 1 from protocol ripng set policy-options policy-statement advertise-routes-through-ripng term 1 then accept set policy-options policy-statement ripng-import term 1 from route-filter fe80::/64 orlonger set policy-options policy-statement ripng-import term 1 from route-filter 2001:db8::/64 orlonger set policy-options policy-statement ripng-import term 1 then accept set policy-options policy-statement ripng-import term 2 then reject
设备 R2
set interfaces fe-1/2/0 unit 2 description to-R1 set interfaces fe-1/2/0 unit 2 family inet6 address 2001:db8:0:2::/64 eui-64 set interfaces fe-1/2/1 unit 5 description to-R3 set interfaces fe-1/2/1 unit 5 family inet6 address 2001:db8:0:3::/64 eui-64 set interfaces lo0 unit 2 family inet6 address 2001:db8::2/128 set interfaces lo0 unit 2 family inet6 address 2002:db8::2/128 set interfaces lo0 unit 2 family inet6 address 2002:db9::2/128 set interfaces lo0 unit 2 family inet6 address 2002:db7::2/128 set protocols ripng group ripng-group export advertise-routes-through-ripng set protocols ripng group ripng-group neighbor fe-1/2/0.2 set protocols ripng group ripng-group neighbor fe-1/2/1.5 set policy-options policy-statement advertise-routes-through-ripng term 1 from protocol direct set policy-options policy-statement advertise-routes-through-ripng term 1 from protocol ripng set policy-options policy-statement advertise-routes-through-ripng term 1 then accept
设备 R3
set interfaces fe-1/2/0 unit 6 description to-R2 set interfaces fe-1/2/0 unit 6 family inet6 address 2001:db8:0:4::/64 eui-64 set interfaces lo0 unit 3 family inet6 address 2001:db8::3/128 set protocols ripng group ripng-group export advertise-routes-through-ripng set protocols ripng group ripng-group neighbor fe-1/2/0.6 set policy-options policy-statement advertise-routes-through-ripng term 1 from protocol direct set policy-options policy-statement advertise-routes-through-ripng term 1 from protocol ripng set policy-options policy-statement advertise-routes-through-ripng term 1 then accept
逐步过程
以下示例要求您在配置层次结构中的各个级别上导航。有关导航 CLI 的信息,请参阅 CLI 用户指南中的在配置模式下使用 CLI 编辑器。
要配置 RIPng 导入策略:
配置网络接口。
此示例显示了多个用于模拟附加网络的环路接口地址。
[edit interfaces] user@R1# set fe-1/2/0 unit 1 description to-R2 user@R1# set fe-1/2/0 unit 1 family inet6 address 2001:db8:0:1::/64 eui-64 user@R1# set lo0 unit 1 family inet6 address 2001:db8::1/128
创建 RIPng 组并添加接口。
要在 Junos OS 中配置 RIPng,必须配置一个包含启用了 RIPng 的接口的组。无需在环路接口上启用 RIPng。
[edit protocols ripng group ripng-group] user@R1# set neighbor fe-1/2/0.1
创建路由策略以播发直接路由和 RIPng 学习路由。
[edit policy-options policy-statement advertise-routes-through-ripng term 1] user@R1# set from protocol direct user@R1# set from protocol ripng user@R1# set then accept
应用路由策略。
在 Junos OS 中,只能在组级别应用 RIPng 导出策略。
[edit protocols ripng group ripng-group] user@R1# set export advertise-routes-through-ripng
配置导入策略。
[edit policy-options policy-statement ripng-import] user@R1# set term 1 from route-filter fe80::/64 orlonger user@R1# set term 1 from route-filter 2001:db8::/64 orlonger user@R1# set term 1 then accept user@R1# set term 2 then reject
应用导入策略。
[edit protocols ripng group ripng-group] user@R1# set neighbor fe-1/2/0.1 import ripng-import
结果
在配置模式下,输入 、 show protocols
和show policy-options
命令,show interfaces
以确认您的配置。如果输出未显示预期的配置,请重复此示例中的配置说明,以便进行更正。
user@R1# show interfaces
fe-1/2/0 {
unit 1 {
description to-R2;
family inet6 {
address 2001:db8:0:1::/64 {
eui-64;
}
}
}
}
lo0 {
unit 1 {
family inet6 {
address 2001:db8::1/128;
}
}
}
user@R1# show protocols
ripng {
group ripng-group {
export advertise-routes-through-ripng;
neighbor fe-1/2/0.1 {
import ripng-import;
}
}
}
user@R1# show policy-options
policy-statement advertise-routes-through-ripng {
term 1 {
from protocol [ direct ripng ];
then accept;
}
}
policy-statement ripng-import {
term 1 {
from {
route-filter fe80::/64 orlonger;
route-filter 2001:db8::/64 orlonger;
}
then accept;
}
term 2 {
then reject;
}
}
完成设备配置后,请在配置模式下输入 提交 。
验证
确认配置工作正常。
查看设备 R2 的邻接方地址
目的
确定设备 R2 用于设备 R1 的邻接方地址。
行动
在操作模式下,输入 show ripng neighbor
命令。
user@R2> show ripng neighbor fe-1/2/0.2 Source Dest In Neighbor State Address Address Send Recv Met -------- ----- ------- ------- ---- ---- --- fe-1/2/0.2 Up fe80::2a0:a514:0:24c ff02::9 yes yes 1
意义
设备 R2 使用 fe80::2a0:a514:0:24c 地址将路由发送到设备 R1。
查看设备 R2 向设备 R1 传播的路由
目的
验证设备 R2 是否正在发送预期的路由。
行动
在操作模式下,输入 show route advertising-protocol ripng
命令。
user@R2> show route advertising-protocol ripng fe80::2a0:a514:0:24c inet6.0: 17 destinations, 18 routes (17 active, 0 holddown, 0 hidden) + = Active Route, - = Last Active, * = Both 2001:db8::2/128 *[Direct/0] 3d 22:00:34 > via lo0.2 2001:db8::3/128 *[RIPng/100] 3d 21:47:00, metric 2, tag 0 > to fe80::2a0:a514:0:64c via fe-1/2/1.5 2001:db8:0:2::/64 *[Direct/0] 3d 22:00:34 > via fe-1/2/0.2 2001:db8:0:3::/64 *[Direct/0] 3d 22:00:34 > via fe-1/2/1.5 2001:db8:0:4::/64 *[RIPng/100] 3d 21:47:00, metric 2, tag 0 > to fe80::2a0:a514:0:64c via fe-1/2/1.5 2002:db7::2/128 *[Direct/0] 00:29:05 > via lo0.2 2002:db8::2/128 *[Direct/0] 00:31:49 > via lo0.2 2002:db9::2/128 *[Direct/0] 00:29:05 > via lo0.2
意义
设备 R2 正在向设备 R1 发送额外的环路接口 /128 路由。
查看设备 R1 从设备 R2 接收的路由
目的
验证设备 R1 是否接收预期的路由。
行动
在操作模式下,输入 show route receive-protocol ripng
命令。
user@R1> show route receive-protocol ripng fe80::2a0:a514:0:24c inet6.0: 9 destinations, 9 routes (9 active, 0 holddown, 0 hidden) + = Active Route, - = Last Active, * = Both 2001:db8::2/128 *[RIPng/100] 3d 21:55:49, metric 2, tag 0 > to fe80::2a0:a514:0:24c via fe-1/2/0.1 2001:db8::3/128 *[RIPng/100] 3d 21:55:46, metric 3, tag 0 > to fe80::2a0:a514:0:24c via fe-1/2/0.1
意义
输出显示,将排除额外的环路接口地址。
检查路由表
目的
验证路由表是否填充了预期的路由。
行动
在操作模式下,输入 show route protocol ripng
命令。
user@R1> show route protocol ripng inet6.0: 9 destinations, 9 routes (9 active, 0 holddown, 0 hidden) + = Active Route, - = Last Active, * = Both 2001:db8::2/128 *[RIPng/100] 3d 22:01:40, metric 2, tag 0 > to fe80::2a0:a514:0:24c via fe-1/2/0.1 2001:db8::3/128 *[RIPng/100] 3d 22:01:37, metric 3, tag 0 > to fe80::2a0:a514:0:24c via fe-1/2/0.1 ff02::9/128 *[RIPng/100] 00:00:08, metric 1 MultiRecv
意义
输出显示,已从设备 R2 和设备 R3 获知路由。
如果删除或停用导入策略,路由表将包含额外的环路接口路由。
示例:测试使用复杂正则表达式的路由策略
此示例说明如何使用命令测试路由策略 test policy
,以确保该策略在生产环境中应用之前产生预期的结果。正则表达式,尤其是复杂的表达式,可能很难搞对。此示例说明如何使用 test policy
命令确保您的正则表达式具有预期的效果。
要求
配置此示例之前,不需要除设备初始化之外的特殊配置。
概述
此示例显示了两个路由设备,设备之间有外部 BGP (EBGP) 连接。设备 R2 使用 BGP 会话将客户路由发送到设备 R1。这些静态路由附加了多个社区值。
user@R2> show route match-prefix 172.16.* detail inet.0: 7 destinations, 7 routes (7 active, 0 holddown, 0 hidden) 172.16.1.0/24 (1 entry, 1 announced) *Static Preference: 5 Next hop type: Reject Address: 0x8fd0dc4 Next-hop reference count: 8 State: <Active Int Ext> Local AS: 64511 Age: 21:32:13 Validation State: unverified Task: RT Announcement bits (1): 0-KRT AS path: I Communities: 64510:1 64510:10 64510:11 64510:100 64510:111 172.16.2.0/24 (1 entry, 1 announced) *Static Preference: 5 Next hop type: Reject Address: 0x8fd0dc4 Next-hop reference count: 8 State: <Active Int Ext> Local AS: 64511 Age: 21:32:13 Validation State: unverified Task: RT Announcement bits (1): 0-KRT AS path: I Communities: 64510:2 64510:20 64510:22 64510:200 64510:222 172.16.3.0/24 (1 entry, 1 announced) *Static Preference: 5 Next hop type: Reject Address: 0x8fd0dc4 Next-hop reference count: 8 State: <Active Int Ext> Local AS: 64511 Age: 21:32:13 Validation State: unverified Task: RT Announcement bits (1): 0-KRT AS path: I Communities: 64510:3 64510:30 64510:33 64510:300 64510:333 172.16.4.0/24 (1 entry, 1 announced) *Static Preference: 5 Next hop type: Reject Address: 0x8fd0dc4 Next-hop reference count: 8 State: <Active Int Ext> Local AS: 64511 Age: 21:32:13 Validation State: unverified Task: RT Announcement bits (1): 0-KRT AS path: I Communities: 64510:4 64510:40 64510:44 64510:400 64510:444
为了测试复杂的正则表达式,设备 R2 有一个称为 test-regex
策略的策略,用于定位路由。策略的配置方式是这样的:
policy-statement test-regex { term find-routes { from community complex-regex; then accept; } term reject-the-rest { then reject; } } community complex-regex members "^64510:[13].*$";
此正则表达式匹配以 1 或 3 开头的社区值。
配置
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,然后将命令复制并粘贴到层级的 [edit]
CLI 中。
设备 R1
set interfaces fe-1/2/0 unit 0 family inet address 10.0.0.1/30 set interfaces lo0 unit 0 family inet address 192.168.0.1/32 set protocols bgp group ext type external set protocols bgp group ext peer-as 64511 set protocols bgp group ext neighbor 10.0.0.2 set routing-options router-id 192.168.0.1 set routing-options autonomous-system 64510
设备 R2
set interfaces fe-1/2/0 unit 0 family inet address 10.0.0.2/30 set interfaces lo0 unit 0 family inet address 192.168.0.2/32 set protocols bgp group ext type external set protocols bgp group ext peer-as 64510 set protocols bgp group ext neighbor 10.0.0.1 set policy-options policy-statement send-static term 1 from protocol static set policy-options policy-statement send-static term 1 then accept set policy-options policy-statement send-static term 2 then reject set policy-options policy-statement test-regex term find-routes from community complex-regex set policy-options policy-statement test-regex term find-routes then accept set policy-options policy-statement test-regex term reject-the-rest then reject set policy-options community complex-regex members "^64510:[13].*$" set routing-options static route 172.16.1.0/24 reject set routing-options static route 172.16.1.0/24 community 64510:1 set routing-options static route 172.16.1.0/24 community 64510:10 set routing-options static route 172.16.1.0/24 community 64510:11 set routing-options static route 172.16.1.0/24 community 64510:100 set routing-options static route 172.16.1.0/24 community 64510:111 set routing-options static route 172.16.2.0/24 reject set routing-options static route 172.16.2.0/24 community 64510:2 set routing-options static route 172.16.2.0/24 community 64510:20 set routing-options static route 172.16.2.0/24 community 64510:22 set routing-options static route 172.16.2.0/24 community 64510:200 set routing-options static route 172.16.2.0/24 community 64510:222 set routing-options static route 172.16.3.0/24 reject set routing-options static route 172.16.3.0/24 community 64510:3 set routing-options static route 172.16.3.0/24 community 64510:30 set routing-options static route 172.16.3.0/24 community 64510:33 set routing-options static route 172.16.3.0/24 community 64510:300 set routing-options static route 172.16.3.0/24 community 64510:333 set routing-options static route 172.16.4.0/24 reject set routing-options static route 172.16.4.0/24 community 64510:4 set routing-options static route 172.16.4.0/24 community 64510:40 set routing-options static route 172.16.4.0/24 community 64510:44 set routing-options static route 172.16.4.0/24 community 64510:400 set routing-options static route 172.16.4.0/24 community 64510:444 set routing-options router-id 192.168.0.2 set routing-options autonomous-system 64511
程序
逐步过程
以下示例要求您在配置层次结构中的各个级别上导航。有关导航 CLI 的信息,请参阅 CLI 用户指南中的在配置模式下使用 CLI 编辑器。
要配置设备 R2:
配置接口。
[edit interfaces] user@R2# set fe-1/2/0 unit 0 family inet address 10.0.0.2/30 user@R2# set lo0 unit 0 family inet address 192.168.0.2/32
配置 BGP。
将导入策略应用于使用设备 R2 的 BGP 对等会话。
[edit protocols bgp group ext] user@R2# set type external user@R2# set peer-as 64510 user@R2# set neighbor 10.0.0.1
配置发送静态路由的路由策略。
[edit policy-options policy-statement send-static] user@R2# set term 1 from protocol static user@R2# set term 1 then accept user@R2# set term 2 then reject
配置用于测试正则表达式的路由策略。
[edit policy-options policy-statement test-regex] user@R2# set term find-routes from community complex-regex user@R2# set term find-routes then accept user@R2# set term reject-the-rest then reject [edit policy-options community] user@R2# set complex-regex members "^64510:[13].*$"
配置静态路由并附加社区值。
[edit routing-options static route 172.16.1.0/24] user@R2# set reject user@R2# set community [ 64510:1 64510:10 64510:11 64510:100 64510:111 ] [edit routing-options static route 172.16.2.0/24] user@R2# set reject user@R2# set community [ 64510:2 64510:20 64510:22 64510:200 64510:222 ] [edit routing-options static route 172.16.3.0/24] user@R2# set reject user@R2# set community [ 64510:3 64510:30 64510:33 64510:300 64510:333 ] [edit routing-options static route 172.16.4.0/24] user@R2# set reject user@R2# set community [ 64510:4 64510:40 64510:44 64510:400 64510:444 ]
配置自治系统 (AS) 编号和路由器 ID。
这会影响设备 R2 的路由表,并且不会影响设备 R1 和设备 R3。
[edit routing-options ] user@R2# set router-id 192.168.0.2 user@R2# set autonomous-system 64511
结果
在配置模式下,输入 show interfaces
、 show protocols
、 show policy-options
和 show routing-options
命令,以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明,以更正配置。
user@R2# show interfaces fe-1/2/0 { unit 0 { family inet { address 10.0.0.2/30; } } } lo0 { unit 0 { family inet { address 192.168.0.2/32; } } }
user@R2# show protocols bgp { group ext { type external; peer-as 64510; neighbor 10.0.0.1; } }
user@R2# show policy-options policy-statement send-static { term 1 { from protocol static; then accept; } term 2 { then reject; } } policy-statement test-regex { term find-routes { from community complex-regex; then accept; } term reject-the-rest { then reject; } } community complex-regex members "^64510:[13].*$";
user@R2# show routing-options static { route 172.16.1.0/24 { reject; community [ 64510:1 64510:10 64510:11 64510:100 64510:111 ]; } route 172.16.2.0/24 { reject; community [ 64510:2 64510:20 64510:22 64510:200 64510:222 ]; } route 172.16.3.0/24 { reject; community [ 64510:3 64510:30 64510:33 64510:300 64510:333 ]; } route 172.16.4.0/24 { reject; community [ 64510:4 64510:40 64510:44 64510:400 64510:444 ]; } } router-id 192.168.0.2; autonomous-system 64511;
完成设备配置后,请从配置模式进入 commit
。
验证
确认配置工作正常。
测试,查看哪些社区与正则表达式匹配
目的
您可以使用命令测试正则表达式及其策略 test policypolicy-name
。
行动
在设备 R2 上,运行
test policy test-regex 0/0
命令。user@R2> test policy test-regex 0/0 inet.0: 7 destinations, 7 routes (7 active, 0 holddown, 0 hidden) + = Active Route, - = Last Active, * = Both 172.16.1.0/24 *[Static/5] 1d 00:32:50 Reject 172.16.3.0/24 *[Static/5] 1d 00:32:50 Reject Policy test-regex: 2 prefix accepted, 5 prefix rejected
在设备 R2 上,更改正则表达式,以匹配包含数字 2 任意数量的实例的社区值。
[edit policy-options community complex-regex] user@R2# delete members "^64510:[13].*$" user@R2# set members "^65020:2+$" user@R2# commit
在设备 R2 上,重新运行
test policy test-regex 0/0
命令。user@R2> test policy test-regex 0/0 inet.0: 7 destinations, 7 routes (7 active, 0 holddown, 0 hidden) + = Active Route, - = Last Active, * = Both 172.16.2.0/24 *[Static/5] 1d 00:31:36 Reject Policy test-regex: 1 prefix accepted, 6 prefix rejected
意义
172.16.1.0 /24 和 172.16.3.0/24 路由均附加了与 ^64510:[13]*$ 表达式匹配的社区。172.16.2.0/24 路由具有与 $65020:2+$ 表达式匹配的社区。