OSPF路由过滤实验
OSPF路由过滤有两种方式
-
基于3类LSA的过滤
此过滤一般在ABR上配置,针对的是一个区域
-
基于路由过滤
一般在某台路由器上配置,针对的就是这台路由器
实验拓扑
实验需求
1、area 1区域内不允许有去往5.0、7.0、8.0网段的路由条目,且不允许出现他们的3类LSA
2、R3上不允许有去往1.0网段的路由条目
3、R4上不允许有去往2.0、3.0网段的路由条目
实验步骤
步骤一 配置IP地址
按照拓扑图配置设备各个接口的IP地址
(配置过程略)
步骤二 配置OSPF
按照拓扑的规划宣告相关接口到指定的区域
(配置过程略)
步骤三 配置路由过滤
使用地址前缀列表作为过滤工具,需要注意地址前缀列表是默认拒绝的,因此单独指定了拒绝某条特定的路由后还要在后面加一条策略放行其他所有。
R2作为区域1和区域0之间的ABR,因此基于对区域1的3类LSA的过滤应该在R2上配置。
R2的配置:
# 拒绝5.0网段的路由
[R2]ip prefix-list 5.0 index 10 deny 192.168.5.0 24 less-equal 32
# 允许所有
[R2] ip prefix-list 5.0 index 20 permit 0.0.0.0 0 less-equal 32
# 允许6.0网段的路由
[R2] ip prefix-list 6.0 index 10 permit 192.168.6.0 24 less-equal 32
在OSPF中应用地址前缀列表进行路由过滤
[R2]ospf 1
[R2-ospf-1]a 0
# 在区域0的export(出)方向上应用策略
[R2-ospf-1-area-0.0.0.0]filter prefix-list 5.0 export
[R2-ospf-1]a 1
# 在区域1的import(入)方向上应用策略
[R2-ospf-1-area-0.0.0.1]filter prefix-list 6.0 import
说明一下,其实在上面只需要配置一条策略就可以实现实验效果,即在区域0的出方向后者区域1的入方向应用ip-prefix 6.0允许6.0网段就行。但是笔者想说明的是进行3类LSA过滤的位置不唯一,可以根据区域主体的不同灵活下发。
对于笔者如上的配置,LSA在出去区域0时执行区域0 export方向上的过滤,拒绝了5.0,而进入区域1时执行区域1 import方向上的过滤,只允许6.0网段通过,因此能实现最终值允许区域0有去往6.0网段的路由。
R3的配置:
# 配置地址前缀列表匹配路由
[R3] ip prefix-list 1.0 index 10 deny 192.168.1.0 24 less-equal 32
[R3] ip prefix-list 1.0 index 20 permit 0.0.0.0 0 less-equal 32
# OSPF视图下下发策略
# 这里的import可以理解为路由表import OSPF协议计算出的明细路由,因此在加入到路由表时相关的路由就被过滤了
[R3-ospf-1] filter-policy prefix-list 1.0 import
R4的配置:
[R4] ip prefix-list 2-3 index 10 deny 192.168.2.0 23 less-equal 32
[R4] ip prefix-list 2-3 index 20 permit 0.0.0.0 0 less-equal 32
[R4-ospf-1] filter-policy prefix-list 2-3 import
实验结果
R1路由表
<R1>dis ip routing-table
Destinations : 24 Routes : 24
Destination/Mask Proto Pre Cost NextHop Interface
0.0.0.0/32 Direct 0 0 127.0.0.1 InLoop0
1.1.1.1/32 Direct 0 0 127.0.0.1 InLoop0
127.0.0.0/8 Direct 0 0 127.0.0.1 InLoop0
127.0.0.1/32 Direct 0 0 127.0.0.1 InLoop0
127.255.255.255/32 Direct 0 0 127.0.0.1 InLoop0
192.168.1.0/24 Direct 0 0 192.168.1.1 Loop1
192.168.1.1/32 Direct 0 0 127.0.0.1 InLoop0
192.168.1.255/32 Direct 0 0 192.168.1.1 Loop1
192.168.2.0/24 Direct 0 0 192.168.2.1 Loop2
192.168.2.1/32 Direct 0 0 127.0.0.1 InLoop0
192.168.2.255/32 Direct 0 0 192.168.2.1 Loop2
192.168.3.0/24 Direct 0 0 192.168.3.1 Loop3
192.168.3.1/32 Direct 0 0 127.0.0.1 InLoop0
192.168.3.255/32 Direct 0 0 192.168.3.1 Loop3
192.168.4.0/24 Direct 0 0 192.168.4.1 Loop4
192.168.4.1/32 Direct 0 0 127.0.0.1 InLoop0
192.168.4.255/32 Direct 0 0 192.168.4.1 Loop4
192.168.6.1/32 O_INTER 10 3 192.168.9.2 GE0/0
192.168.9.0/24 Direct 0 0 192.168.9.1 GE0/0
192.168.9.1/32 Direct 0 0 127.0.0.1 InLoop0
192.168.9.255/32 Direct 0 0 192.168.9.1 GE0/0
224.0.0.0/4 Direct 0 0 0.0.0.0 NULL0
224.0.0.0/24 Direct 0 0 0.0.0.0 NULL0
255.255.255.255/32 Direct 0 0 127.0.0.1 InLoop0
R1的LSDB
<R1>dis ospf lsdb
OSPF Process 1 with Router ID 1.1.1.1
Link State Database
Area: 0.0.0.1
Type LinkState ID AdvRouter Age Len Sequence Metric
Router 1.1.1.1 1.1.1.1 667 84 8000000D 0
Router 2.2.2.2 2.2.2.2 1264 36 80000009 0
Network 192.168.9.1 1.1.1.1 667 32 80000006 0
Sum-Net 192.168.6.1 2.2.2.2 1211 28 80000004 2
R2的LSDB
<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 3.3.3.3 3.3.3.3 1437 36 80000009 0
Router 2.2.2.2 2.2.2.2 1438 36 80000009 0
Network 192.168.10.3 3.3.3.3 1433 32 80000006 0
Sum-Net 192.168.5.1 3.3.3.3 1403 28 80000005 1
Sum-Net 192.168.4.1 2.2.2.2 888 28 80000004 1
Sum-Net 192.168.11.0 3.3.3.3 1463 28 80000005 1
Sum-Net 192.168.9.0 2.2.2.2 888 28 80000004 1
Sum-Net 192.168.8.1 3.3.3.3 1387 28 80000005 1
Sum-Net 192.168.3.1 2.2.2.2 888 28 80000004 1
Sum-Net 192.168.2.1 2.2.2.2 888 28 80000004 1
Sum-Net 192.168.1.1 2.2.2.2 888 28 80000004 1
Sum-Net 192.168.7.1 3.3.3.3 1391 28 80000005 1
Sum-Net 192.168.6.1 3.3.3.3 1395 28 80000005 1
Area: 0.0.0.1
Type LinkState ID AdvRouter Age Len Sequence Metric
Router 1.1.1.1 1.1.1.1 848 84 8000000D 0
Router 2.2.2.2 2.2.2.2 1500 36 80000009 0
Network 192.168.9.1 1.1.1.1 848 32 80000006 0
Sum-Net 192.168.6.1 2.2.2.2 1442 28 80000004 2
R3的路由表
[R3-ospf-1]dis ip rou
Destinations : 22 Routes : 22
Destination/Mask Proto Pre Cost NextHop Interface
0.0.0.0/32 Direct 0 0 127.0.0.1 InLoop0
3.3.3.3/32 Direct 0 0 127.0.0.1 InLoop0
127.0.0.0/8 Direct 0 0 127.0.0.1 InLoop0
127.0.0.1/32 Direct 0 0 127.0.0.1 InLoop0
127.255.255.255/32 Direct 0 0 127.0.0.1 InLoop0
192.168.2.1/32 O_INTER 10 2 192.168.10.2 GE0/0
192.168.3.1/32 O_INTER 10 2 192.168.10.2 GE0/0
192.168.4.1/32 O_INTER 10 2 192.168.10.2 GE0/0
192.168.5.1/32 O_INTRA 10 1 192.168.11.1 GE0/1
192.168.6.1/32 O_INTRA 10 1 192.168.11.1 GE0/1
192.168.7.1/32 O_INTRA 10 1 192.168.11.1 GE0/1
192.168.8.1/32 O_INTRA 10 1 192.168.11.1 GE0/1
192.168.9.0/24 O_INTER 10 2 192.168.10.2 GE0/0
192.168.10.0/24 Direct 0 0 192.168.10.3 GE0/0
192.168.10.3/32 Direct 0 0 127.0.0.1 InLoop0
192.168.10.255/32 Direct 0 0 192.168.10.3 GE0/0
192.168.11.0/24 Direct 0 0 192.168.11.3 GE0/1
192.168.11.3/32 Direct 0 0 127.0.0.1 InLoop0
192.168.11.255/32 Direct 0 0 192.168.11.3 GE0/1
224.0.0.0/4 Direct 0 0 0.0.0.0 NULL0
224.0.0.0/24 Direct 0 0 0.0.0.0 NULL0
255.255.255.255/32 Direct 0 0 127.0.0.1 InLoop0
R3的LSDB
[R3-ospf-1]dis ospf lsdb
OSPF Process 1 with Router ID 3.3.3.3
Link State Database
Area: 0.0.0.0
Type LinkState ID AdvRouter Age Len Sequence Metric
Router 3.3.3.3 3.3.3.3 1478 36 80000009 0
Router 2.2.2.2 2.2.2.2 1481 36 80000009 0
Network 192.168.10.3 3.3.3.3 1474 32 80000006 0
Sum-Net 192.168.5.1 3.3.3.3 1444 28 80000005 1
Sum-Net 192.168.4.1 2.2.2.2 932 28 80000004 1
Sum-Net 192.168.11.0 3.3.3.3 1504 28 80000005 1
Sum-Net 192.168.9.0 2.2.2.2 932 28 80000004 1
Sum-Net 192.168.8.1 3.3.3.3 1428 28 80000005 1
Sum-Net 192.168.3.1 2.2.2.2 932 28 80000004 1
Sum-Net 192.168.2.1 2.2.2.2 932 28 80000004 1
Sum-Net 192.168.1.1 2.2.2.2 932 28 80000004 1
Sum-Net 192.168.7.1 3.3.3.3 1432 28 80000005 1
Sum-Net 192.168.6.1 3.3.3.3 1436 28 80000005 1
Area: 0.0.0.2
Type LinkState ID AdvRouter Age Len Sequence Metric
Router 3.3.3.3 3.3.3.3 1452 36 80000009 0
Router 4.4.4.4 4.4.4.4 1432 84 80000010 0
Network 192.168.11.3 3.3.3.3 1444 32 80000006 0
Sum-Net 192.168.4.1 3.3.3.3 930 28 80000004 2
Sum-Net 192.168.10.0 3.3.3.3 1506 28 80000005 1
Sum-Net 192.168.9.0 3.3.3.3 930 28 80000004 2
Sum-Net 192.168.3.1 3.3.3.3 930 28 80000004 2
Sum-Net 192.168.2.1 3.3.3.3 930 28 80000004 2
Sum-Net 192.168.1.1 3.3.3.3 930 28 80000004 2
R4的路由表
[R4]dis ip rou
Destinations : 27 Routes : 27
Destination/Mask Proto Pre Cost NextHop Interface
0.0.0.0/32 Direct 0 0 127.0.0.1 InLoop0
4.4.4.4/32 Direct 0 0 127.0.0.1 InLoop0
127.0.0.0/8 Direct 0 0 127.0.0.1 InLoop0
127.0.0.1/32 Direct 0 0 127.0.0.1 InLoop0
127.255.255.255/32 Direct 0 0 127.0.0.1 InLoop0
192.168.1.1/32 O_INTER 10 3 192.168.11.3 GE0/0
192.168.4.1/32 O_INTER 10 3 192.168.11.3 GE0/0
192.168.5.0/24 Direct 0 0 192.168.5.1 Loop1
192.168.5.1/32 Direct 0 0 127.0.0.1 InLoop0
192.168.5.255/32 Direct 0 0 192.168.5.1 Loop1
192.168.6.0/24 Direct 0 0 192.168.6.1 Loop2
192.168.6.1/32 Direct 0 0 127.0.0.1 InLoop0
192.168.6.255/32 Direct 0 0 192.168.6.1 Loop2
192.168.7.0/24 Direct 0 0 192.168.7.1 Loop3
192.168.7.1/32 Direct 0 0 127.0.0.1 InLoop0
192.168.7.255/32 Direct 0 0 192.168.7.1 Loop3
192.168.8.0/24 Direct 0 0 192.168.8.1 Loop4
192.168.8.1/32 Direct 0 0 127.0.0.1 InLoop0
192.168.8.255/32 Direct 0 0 192.168.8.1 Loop4
192.168.9.0/24 O_INTER 10 3 192.168.11.3 GE0/0
192.168.10.0/24 O_INTER 10 2 192.168.11.3 GE0/0
192.168.11.0/24 Direct 0 0 192.168.11.1 GE0/0
192.168.11.1/32 Direct 0 0 127.0.0.1 InLoop0
192.168.11.255/32 Direct 0 0 192.168.11.1 GE0/0
224.0.0.0/4 Direct 0 0 0.0.0.0 NULL0
224.0.0.0/24 Direct 0 0 0.0.0.0 NULL0
255.255.255.255/32 Direct 0 0 127.0.0.1 InLoop0
R4的LSDB
[R4]dis ospf lsdb
OSPF Process 1 with Router ID 4.4.4.4
Link State Database
Area: 0.0.0.2
Type LinkState ID AdvRouter Age Len Sequence Metric
Router 3.3.3.3 3.3.3.3 1528 36 80000009 0
Router 4.4.4.4 4.4.4.4 1506 84 80000010 0
Network 192.168.11.3 3.3.3.3 1520 32 80000006 0
Sum-Net 192.168.4.1 3.3.3.3 1006 28 80000004 2
Sum-Net 192.168.10.0 3.3.3.3 1582 28 80000005 1
Sum-Net 192.168.9.0 3.3.3.3 1006 28 80000004 2
Sum-Net 192.168.3.1 3.3.3.3 1006 28 80000004 2
Sum-Net 192.168.2.1 3.3.3.3 1006 28 80000004 2
Sum-Net 192.168.1.1 3.3.3.3 1006 28 80000004 2
从实验结果来看进行了3类LSA过滤的区域中,不仅没有相应路由条目,甚至连相关的LSA也没有
而单纯的进行了路由过滤的设备,只有相关路由没有,但是LSA还是存在