引言:
route-policy 策略的名字 匹配模式 node 节点序号
# 匹配模式 permit 或 deny。
permit: 允许路由通过,并对路由执行apply子句动作
deny: 拒绝路由通过
if-match 子句是匹配的条件,所有if-match子句都匹配成功,则执行 节点 匹配模式的动作
如果 if-match子句,调用ACL 或者 ip-prefix 作为匹配条件
acl 或 ip-prefix 中的pemit 或 deny 的含义如下:
如果路由前缀或和掩码 与acl 或ip-prefix 中的规则的条件匹配,执行规则的动作permit
或 deny
如果动作是permit, 则表示 通过 本node节点的匹配,匹配结束,执行 node 节点的匹配模式,
如果匹配模式是permit ,允许路由通过,如果是deny,则拒绝路由通过
如果动作是deny, 则表示,拒绝通过 本 node 节点的匹配,开始下一个 node 节点的匹配
route-policy 最后隐含一条拒绝所有的node
R1:
#
interface GigabitEthernet0/0/0
ip address 10.1.12.1 255.255.255.0
#
interface GigabitEthernet0/0/1
ip address 10.1.13.1 255.255.255.0
#
interface GigabitEthernet0/0/2
#
interface NULL0
#
interface LoopBack0
ip address 1.1.1.1 255.255.255.255
#
ospf 1 router-id 1.1.1.1
area 0.0.0.0
network 1.1.1.1 0.0.0.0
network 10.1.12.0 0.0.0.255
area 0.0.0.1
network 10.1.13.0 0.0.0.255
#
R2:
interface GigabitEthernet0/0/0
ip address 10.1.12.2 255.255.255.0
#
interface GigabitEthernet0/0/1
#
interface GigabitEthernet0/0/2
#
interface NULL0
#
interface LoopBack0
ip address 2.2.2.2 255.255.255.255
#
ospf 1 router-id 2.2.2.2
area 0.0.0.0
network 2.2.2.2 0.0.0.0
network 10.1.12.0 0.0.0.255
#
R3:
#
interface LoopBack0
ip address 192.168.1.1 255.255.255.0
#
interface LoopBack1
ip address 192.168.2.1 255.255.255.0
#
interface LoopBack2
ip address 192.168.3.1 255.255.255.0
#
interface LoopBack11
ip address 3.3.3.3 255.255.255.255
#
ospf 1 router-id 3.3.3.3
import-route direct route-policy rp
area 0.0.0.1
network 3.3.3.3 0.0.0.0
network 10.1.13.0 0.0.0.255
#
route-policy rp permit node 10
if-match ip-prefix 1
#
ip ip-prefix 1 index 10 deny 192.168.1.0 24
ip ip-prefix 1 index 20 permit 192.168.2.0 24
ip ip-prefix 1 index 30 permit 192.168.3.0 24
#
<R2>dis ospf lsdb
OSPF Process 1 with Router ID 2.2.2.2
Link State Database
Area: 0.0.0.0
Type LinkState ID AdvRouter Age Len Sequence Metric
Router 2.2.2.2 2.2.2.2 122 48 80000005 1
Router 1.1.1.1 1.1.1.1 127 48 80000009 1
Network 10.1.12.1 1.1.1.1 127 32 80000003 0
Sum-Net 10.1.13.0 1.1.1.1 164 28 80000002 1
Sum-Net 3.3.3.3 1.1.1.1 30 28 80000002 1
Sum-Asbr 3.3.3.3 1.1.1.1 1767 28 80000001 1
AS External Database
Type LinkState ID AdvRouter Age Len Sequence Metric
External 192.168.2.0 3.3.3.3 944 36 80000001 1
External 192.168.3.0 3.3.3.3 939 36 80000001 1
<R2> 在R3上引入直连路由时,调用了 路由策略 过滤路由
#
route-policy rp permit node 10
if-match ip-prefix 1
#
ip ip-prefix 1 index 10 deny 192.168.1.0 24
ip ip-prefix 1 index 20 permit 192.168.2.0 24
ip ip-prefix 1 index 30 permit 192.168.3.0 24
#
ospf 1 router-id 3.3.3.3
import-route direct route-policy rp
area 0.0.0.1
network 3.3.3.3 0.0.0.0
network 10.1.13.0 0.0.0.255
#
import-route direct route-policy rp 这条命令的执行过程如下:
引入的直连路由进入到route-policy rp 进行过滤
第一条 直连路由 进行 rp 路由策略 node 10的匹配,匹配条件是通过
ip-prefix 1 来匹配
将路由的前缀及掩码长度,与 ip-prefix 1 索引为10 的规则进行匹配
如果匹配规则的条件,由于规则的动作是deny, 那么拒绝通过本 rp 路由策略本节点
的匹配,开始下一个node的匹配,由于隐藏最后一个拒绝所有的node, 所以如果直连路由是1
192.168.1.0/24,将被最后的隐藏node节点拒绝路由通过
进一步,验证
R3:
在前面的实验上,再升级,进一步验证了理论的准确性
#
ospf 1 router-id 3.3.3.3
import-route direct route-policy rp
area 0.0.0.1
network 3.3.3.3 0.0.0.0
network 10.1.13.0 0.0.0.255
#
route-policy rp permit node 10
if-match ip-prefix 1
#
route-policy rp deny node 30
if-match ip-prefix 2
#
route-policy rp permit node 1000
#
ip ip-prefix 1 index 10 deny 192.168.1.0 24
ip ip-prefix 1 index 20 permit 192.168.2.0 24
ip ip-prefix 1 index 30 permit 192.168.3.0 24
ip ip-prefix 2 index 10 permit 192.168.1.0 24
#
<R2>dis ospf lsdb
OSPF Process 1 with Router ID 2.2.2.2
Link State Database
Area: 0.0.0.0
Type LinkState ID AdvRouter Age Len Sequence Metric
Router 2.2.2.2 2.2.2.2 1161 48 80000005 1
Router 1.1.1.1 1.1.1.1 1166 48 80000009 1
Network 10.1.12.1 1.1.1.1 1166 32 80000003 0
Sum-Net 10.1.13.0 1.1.1.1 1203 28 80000002 1
Sum-Net 3.3.3.3 1.1.1.1 1069 28 80000002 1
Sum-Asbr 3.3.3.3 1.1.1.1 1006 28 80000002 1
AS External Database
Type LinkState ID AdvRouter Age Len Sequence Metric
External 192.168.2.0 3.3.3.3 183 36 80000002 1
External 192.168.3.0 3.3.3.3 178 36 80000002 1
External 3.3.3.3 3.3.3.3 17 36 80000001 1
External 10.1.13.0 3.3.3.3 17 36 80000001 1
<R2>