以前的综合实验文章中能够看到,filter-policy与route-policy都能进行路由的过滤,但这两种策略却有着各自的使用场景,本文就来具体介绍下这两种策略的使用场景 node
filter-policy工做在协议的进程下,从该命令的字面意思为过滤路由的更新信息,能够做用于进程的进出两个方向 网络
[Huawei]ospf 1 [Huawei-ospf-1]? filter-policy Filtering in routing updates
filter-policy自己没法设置滤条件,须要调用其它过滤条件来完成路由信息过滤 app
[Huawei-ospf-1]filter-policy ? INTEGER<2000-2999> Apply basic ACL acl-name Specify the ACL name for filtering IPv4 routes ip-prefix IP address prefix-list route-policy Route policy
既然是过滤策略,那么它最经常使用在的地方就是网元设备的路由过滤上。以前说过filter-policy只能做用在ospf协议import方向时,提到过他不能做用于ospf协议的export方向,缘由就是他只能影响路由器的lsdb加表过程,但不会影响lsa信息,因此不能做用在export方向 ide
route-policy路由策略经常使用于路由重发布时的路由过滤或者更改已有的路由下一跳、开销等属性值。相似于acl,一个route-policy下也能够有多个节点,不一样节点使用node标识区分,不一样node之间是“或”的关系,在同一个node节点下: 工具
[R3-route-policy]if-match ? acl Specify an ACL as-path-filter BGP AS path list community-filter Match BGP community filter cost Match metric of route extcommunity-filter Match BGP/*** extended community filter interface Specify the interface matching the first hop of routes ip IP information ip-prefix Specify an address prefix-list ipv6 IPv6 Information mpls-label Give the Label rd-filter Route-distinguisher filter route-type Match route-type of route tag Match tag of route
route-policy在设置时一样有permit与deny模式,两种模式的做用分别为: 测试
用一个实例进行说明,条件以下图所示,则此时的过滤步骤为: ui
网络拓扑以下图所示,其中R4上的环回接口没有宣告进ospf,使用impor-route引入,配合route-policy,承担abr的R3使用filter-policy进行路由过滤
当基础配置完成后,在R2路由器的import方向使用filter-policy过滤,让R2只保留10.0.1.0/24路由 code
[R2]ospf 1 [R2-ospf-1]filter-policy ip-prefix A import [R2]ip ip-prefix A permit 10.0.1.0 24
此时查看R2的路由表,发现只剩10.0.1.0/24路由 orm
[R2]display ip routing-table protocol ospf Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Public routing table : OSPF Destinations : 1 Routes : 1 OSPF routing table status : <Active> Destinations : 1 Routes : 1 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.0.1.0/24 OSPF 10 1 D 12.0.0.1 GigabitEthernet 0/0/0 OSPF routing table status : <Inactive> Destinations : 0 Routes : 0
但R3与R4上却依然有10.0.0.1/24网段的路由 blog
<R3>display ip routing-table protocol ospf 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 10.0.0.0/24 OSPF 10 2 D 23.0.0.2 GigabitEthernet 0/0/1 10.0.1.0/24 OSPF 10 2 D 23.0.0.2 GigabitEthernet 0/0/1 12.0.0.0/24 OSPF 10 2 D 23.0.0.2 GigabitEthernet 0/0/1 OSPF routing table status : <Inactive> Destinations : 0 Routes : 0
这就印证了以前说的,他只能影响路由器的lsdb加表过程,但不会影响lsa信息,因此身为abr的R3仍是会将10.0.0.1/24网段汇总到3类lsa中向area 1中泛洪,当在R3的import方向使用filter-policy过滤,让R3只保留10.0.1.0/24路由,此时不只R3,连R4上也没有10.0.0.1/24网段,说明abr在向其余area发布3类lsa时,只会根据自己的路由表汇总后发出3类lsa
<R4>display ip routing-table protocol ospf Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Public routing table : OSPF Destinations : 1 Routes : 1 OSPF routing table status : <Active> Destinations : 1 Routes : 1 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.0.1.0/24 OSPF 10 3 D 34.0.0.3 GigabitEthernet 0/0/0 OSPF routing table status : <Inactive> Destinations : 0 Routes : 0
为了测试R4上route-policy效果,首先删除R3上的filter-policy过滤策略
[R3-ospf-1]undo filter-policy ip-prefix A import
其次,定义一个名为A的route-policy策略,并将cost值改成99,此处if-math条件引用的是名为A的ip-prefix
[R4]route-policy A permit node 10 [R4-route-policy]if-match ip-prefix A [R4-route-policy]apply cost 99
设置名为A的ip-prefix,让它只选取192.168.0.0/24网段
[R4]ip ip-prefix A permit 192.168.0.0 24
在ospf 1进程中使用import-route引入route-policy A
[R4]ospf 1 [R4-ospf-1]import-route direct route-policy A
此时在去R3上查看路由表,发现192.168.0.0/24网段表项为O_ASE,且cost值为99
[R3]display ip routing-table protocol 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 10.0.0.0/24 OSPF 10 2 D 23.0.0.2 GigabitEthernet 0/0/1 10.0.1.0/24 OSPF 10 2 D 23.0.0.2 GigabitEthernet 0/0/1 12.0.0.0/24 OSPF 10 2 D 23.0.0.2 GigabitEthernet 0/0/1 192.168.0.0/24 O_ASE 150 99 D 34.0.0.4 GigabitEthernet 0/0/0 OSPF routing table status : <Inactive> Destinations : 0 Routes : 0
上述内容能够总结为如下几点: