标签:通配 mic 精确 ble net 颗粒度 包含 play pre
一、背景介绍ip-prefix作为另一种路由选择工具常用在路由过滤的场景下,相较于技能过滤路由又能过滤数据包的acl,ip-prefix只能过滤路由条目,但他却比acl在过滤路由时颗粒度更细,acl匹配的路由并不精确,因为一个完整的路由信息,包括网络地址与掩码,而acl只能够匹配路由的网络地址,所以像1.1.1.0/24与1.1.1.0/25这两个网段就无法通过acl进行区分,此时就需要使用ip-prefix工具了
本次实验拓扑如下图所示:
路由器之间跑ospf协议,此时R2上通过ospf学到的路由为
<R2>dis ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 5 Routes : 5
OSPF routing table status : <Active>
Destinations : 5 Routes : 5
Destination/Mask Proto Pre Cost Flags NextHop Interface
1.1.1.0/24 OSPF 10 1 D 12.0.0.1 GigabitEthernet
0/0/0
1.1.1.0/25 OSPF 10 1 D 23.0.0.3 GigabitEthernet
0/0/1
1.1.1.128/25 OSPF 10 1 D 23.0.0.3 GigabitEthernet
0/0/1
2.2.2.0/24 OSPF 10 1 D 12.0.0.1 GigabitEthernet
0/0/0
2.2.2.0/25 OSPF 10 1 D 23.0.0.3 GigabitEthernet
0/0/1
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
如果此时只想让R2学习到1.1.1.0/25跟1.1.1.128/25的网段地址,定义一个acl并引用
[R2]acl 2000
[R2-acl-basic-2000]rule 10 permit source 1.1.1.0 0.0.0.128
[R2]ospf 1
[R2-ospf-1]filter-policy 2000 import
再看R2的路由表发现1.1.1.0/24也在R2的路由表中,印证了开头的说明
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 3 Routes : 3
OSPF routing table status : <Active>
Destinations : 3 Routes : 3
Destination/Mask Proto Pre Cost Flags NextHop Interface
1.1.1.0/24 OSPF 10 1 D 12.0.0.1 GigabitEthernet
0/0/0
1.1.1.0/25 OSPF 10 1 D 23.0.0.3 GigabitEthernet
0/0/1
1.1.1.128/25 OSPF 10 1 D 23.0.0.3 GigabitEthernet
0/0/1
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
而用ip-prefix进行过滤,就能精确的抓取到路由
[R2]ip ip-prefix A permit index 10 1.1.1.0 24 greater-equal 25 less-equal 25
[R2]ospf 1
[R2-ospf-1]filter-policy ip-prefix A import
类似于acl一样,ip-prefix也需要被引用才能生效,且默认也包含deny所有未匹配到的路由,此时R2上的路由表为
[R2]display ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 2 Routes : 2
OSPF routing table status : <Active>
Destinations : 2 Routes : 2
Destination/Mask Proto Pre Cost Flags NextHop Interface
1.1.1.0/25 OSPF 10 1 D 23.0.0.3 GigabitEthernet
0/0/1
1.1.1.128/25 OSPF 10 1 D 23.0.0.3 GigabitEthernet
0/0/1
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
根据实验结果,可以对ip-prefix工具做出以下总结:
标签:通配 mic 精确 ble net 颗粒度 包含 play pre
原文地址:https://blog.51cto.com/arkling/2504386