假装网络工程师16

您所在的位置:网站首页 route-policy常用在 假装网络工程师16

假装网络工程师16

2023-06-01 08:35| 来源: 网络整理| 查看: 265

一、背景介绍

之前的综合实验文章中可以看到,filter-policy与route-policy都能进行路由的过滤,但这两种策略却有着各自的使用场景,本文就来具体介绍下这两种策略的使用场景

二、filter-policy介绍 1.filter-policy工作模式

filter-policy工作在协议的进程下,从该命令的字面意思为过滤路由的更新信息,可以作用于进程的进出两个方向

[Huawei]ospf 1 [Huawei-ospf-1]? filter-policy Filtering in routing updates

filter-policy本身无法设置滤条件,需要调用其它过滤条件来完成路由信息过滤

[Huawei-ospf-1]filter-policy ? INTEGER Apply basic ACL acl-name Specify the ACL name for filtering IPv4 routes ip-prefix IP address prefix-list route-policy Route policy 2.filter-policy使用场景

既然是过滤策略,那么它最常用在的地方就是网元设备的路由过滤上。之前说过filter-policy只能作用在ospf协议import方向时,提到过他不能作用于ospf协议的export方向,原因就是他只能影响路由器的lsdb加表过程,但不会影响lsa信息,所以不能作用在export方向

三、route-policy介绍 1.route-policy的工作模式

route-policy路由策略常用于路由重发布时的路由过滤或者更改已有的路由下一跳、开销等属性值。类似于acl,一个route-policy下也可以有多个节点,不同节点使用node标识区分,不同node之间是“或”的关系,在同一个node节点下:

可以有多个if-match和apply字句,多个if-match字句之间是“与”的关系 if-match字句可以引用其他的过滤工具 [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模式,两种模式的作用分别为:

permit:当路由满足当前结点的if-match字句时,则被允许通过并执行apply字句,如果不满足当前结点的if-match字句,转到下一节点进行if-match匹配,如果所有节点都不满足,则丢弃 deny:当路由满足当前结点的if-match字句,将被拒绝通过,且不会进入下一个节点 2.route-policy过滤详解

用一个实例进行说明,条件如下图所示,则此时的过滤步骤为: 假装网络工程师16——路由策略filter-policy与route-policy

路由进入node 10,因为是deny语句,所以Pref1挑选中的1.1.2.0/24与5.5.5.5/32路由条目不会继续进入下一个节点 除掉1.1.2.0/24与5.5.5.5/32,剩下的路由进入node 20,Pref2不挑选6.6.6.6/32,但没指定挑选哪个,ip-prefix隐含全部挑选,所以尽管node 20是permit,但Pref2没有挑选中任何一条路由,此节点无任何操作 除掉1.1.2.0/24与5.5.5.5/32,剩下的路由进入node 30,第一个if-match语句是要匹配acl 2001,由于acl不会区分掩码位数,所以1.1.3.0/24与1.1.3.0/25都被选中,其结果同时满足第二个if-match语句的结果,所以下一跳的13.13.13.1,并将cost值改为21 除掉1.1.2.0/24,5.5.5.5/32;1.1.3.0/24,1.1.3.0/25(下一跳是13.13.13.1),剩下的路由进入node 40,选中的是1.1.3.0/25(下一跳是34.34.34.2),并将cost值改为11 现在只剩下1.1.3.0/24(下一跳34.34.34.2)与6.6.6.6/32路由进入node 50,由于node 50没有设置if-match条件,且有事permit模式,所以允许剩下的所有路由通过 最后,过滤后的路由条目如左下角所示(示例不对,缺少6.6.6.6/32) 四、实验

网络拓扑如下图所示,其中R4上的环回接口没有宣告进ospf,使用impor-route引入,配合route-policy,承担abr的R3使用filter-policy进行路由过滤 假装网络工程师16——路由策略filter-policy与route-policy 当基础配置完成后,在R2路由器的import方向使用filter-policy过滤,让R2只保留10.0.1.0/24路由

[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路由

[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 : 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 : Destinations : 0 Routes : 0

但R3与R4上却依然有10.0.0.1/24网段的路由

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 : 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 : 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

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 : 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 : 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 : 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 : Destinations : 0 Routes : 0 五、总结

上述内容可以总结为以下几点:

filter-policy常用在的地方就是网元设备的路由过滤上 oute-policy常用于路由重发布时的路由过滤或者更改已有的路由下一跳、开销等属性值 在ospf协议中,过滤只会影响lsdb的加表过程,不会影响到lsa,所以作用在路由器的import方向 如果ospf的边界路由器执行过滤,他只会对其他area泛洪自身已加表的路由


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3