route-policy路由加表和路由引入
拓扑图
实验目的
a.在R2上将4条静态路由引入OSPF,要求
1、192.168.1.0/24引入后cost=100,type 1,其他默认
2、192.168.2.0/24引入后cost=200,type 2,其他默认
3、192.168.3.0/24默认引入
4、192.168.4.0/24引入后tag=500,其他默认
5、192.168.5.0/24拒接引入
b.在R1上,将TAG=500的外部路由拒绝加表
c.在R1上,192.168.3.0/24的路由条目优先级单独改成20,其他条目优先级默认
实验步骤
1.配置OSPF,将R2上的静态路由引入R1
R1
<Huawei>sys
[Huawei]sys R1
[R1]un in en
[R1]int g00/0/0
[R1-GigabitEthernet0/0/0]ip add 12.0.0.1 24
[R1-GigabitEthernet0/0/0]q
[R1]ospf 1 router-id 1.1.1.1
[R1-ospf-1]area 0
[R1-ospf-1-area-0.0.0.0]net 12.0.0.1 0.0.0.0
R2
<Huawei>sys
[Huawei]sys R2
[R2]un in en
[R2]int g0/0/0
[R2-GigabitEthernet0/0/0]ip add 12.0.0.02 24
[R2-GigabitEthernet0/0/0]q
[R2]ospf 1 rou 2.2.2.2
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]net 12.0.0.2 0.0.0.0
[R2-ospf-1-area-0.0.0.0]q
[R2-ospf-1]q
[R2]ip route-static 192.168.1.0 24 NULL 0
[R2]ip route-static 192.168.2.0 24 NULL 0
[R2]ip route-static 192.168.3.0 24 NULL 0
[R2]ip route-static 192.168.4.0 24 NULL 0
[R2]ip route-static 192.168.5.0 24 NULL 0
[R2]ospf
[R2-ospf-1]import-route static
2.在R1上查看路由引入情况,可以看见5条静路由均已被引入。
[R1]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
192.168.1.0/24 O_ASE 150 1 D 12.0.0.2 GigabitEthernet
0/0/0
192.168.2.0/24 O_ASE 150 1 D 12.0.0.2 GigabitEthernet
0/0/0
192.168.3.0/24 O_ASE 150 1 D 12.0.0.2 GigabitEthernet
0/0/0
192.168.4.0/24 O_ASE 150 1 D 12.0.0.2 GigabitEthernet
0/0/0
192.168.5.0/24 O_ASE 150 1 D 12.0.0.2 GigabitEthernet
0/0/0
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
3.按照实验要求,需要对引入的静态路由进行过滤和更改。所以需要使用route-policy和ip-prefix。
4.在R2上配置前缀列表
R2
[R2]ip ip-prefix 192.168.1.0 permit 192.168.1.0 24
[R2]ip ip-prefix 192.168.2.0 permit 192.168.2.0 24
[R2]ip ip-prefix 192.168.3.0 permit 192.168.3.0 24
[R2]ip ip-prefix 192.168.4.0 permit 192.168.4.0 24
[R2]ip ip-prefix 192.168.5.0 deny 192.168.5.0 24
5.配置route-policy,在route-policy上调用ip-prefix实现路由过滤修改
R2
route-policy test permit node 10
if-match ip-prefix 192.168.1.0
apply cost 100
apply cost-type type-1
#
route-policy test permit node 20
if-match ip-prefix 192.168.2.0
apply cost 200
apply cost-type type-2
#
route-policy test permit node 30
if-match ip-prefix 192.168.3.0
#
route-policy test permit node 40
if-match ip-prefix 192.168.4.0
apply tag 500
#
route-policy test deny node 50
if-match ip-prefix 192.168.5.0
6.在R2的OSPF域内重新引入添加了route-policy的静态路由
R2
[R2-ospf-1]import-route static route-policy test
7.在R1上查看路由表,可以看见除了192.168.5.0未被引入,1~4的路由均已成功引入且有被修改。
R1
[R1]dis ip routing-table pro ospf
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 4 Routes : 4
OSPF routing table status : <Active>
Destinations : 4 Routes : 4
Destination/Mask Proto Pre Cost Flags NextHop Interface
192.168.1.0/24 O_ASE 150 101 D 12.0.0.2 GigabitEthernet
0/0/0
192.168.2.0/24 O_ASE 150 200 D 12.0.0.2 GigabitEthernet
0/0/0
192.168.3.0/24 O_ASE 150 1 D 12.0.0.2 GigabitEthernet
0/0/0
192.168.4.0/24 O_ASE 150 1 D 12.0.0.2 GigabitEthernet
0/0/0
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
8.在R1上,将TAG=500的外部路由拒绝加表
从条件tag=500可以判断需要使用route-policy,从条件加表可以判断需要使用filter-policy
R1
[R1]route-policy tag deny node 10
Info: New Sequence of this List.
[R1-route-policy]if-match tag 500 #创建route-policy过滤tag为500的路由
[R1-route-policy]q
[R1]ospf
[R1-ospf-1]filter-policy route-policy tag import #在R1的ospf上使用filter-policy调用route-policy tag进行路由引入
这个时候使用dis ip routing-table pro ospf 发现路由表是空的,那这是为神马呢???
原来在filter-policy中是根据后面的route-policy来过滤路由的,而在这里的tag中我们只匹配了tag=500的路由,其他的1.0、2.0…都无法匹配上,所以默认是拒绝其他未匹配的路由,需要在写配置时在最后加上一个兜底的允许所有
R1
[R1]route-policy tag permit node 20
现在再查看路由表,除tag为500的其他路由成功加表
9.在R1上,192.168.3.0/24的路由条目优先级单独改成20,其他条目优先级默认
R1
[R1]ip ip-prefix 192.168.3.0 permit 192.168.3.0 24 #前缀列表匹配92.168.3.0
[R1]route-policy PRE permit node 10 #创建route-policy PRE来修改路由优先级
Info: New Sequence of this List.
[R1-route-policy]if-match ip-prefix 192.168.3.0 #如果匹配到前缀列表192.168.3.0
[R1-route-policy]apply preference 20 #将优先级修改为20
[R1-route-policy]q
[R1]ospf
[R1-ospf-1]preference ase route-policy PRE #进入OSPF上配置ase(外部路由)优先级,匹配route-policy PRE
10.查看R1上OSPF详细路由表,检查192.168.3.0的优先级是否已经被修改为20
R1
[R1]dis ip routing-table protocol ospf verbose