路由策略问题?为满足业务需求和保证数据访问安全性,要求市场部不能访问财务部、研发部,公司总部不能访问研发部filter-policy过滤策略,能够对接收或发布的路由进行过滤,可以调用ACL、ip-pr
.
路由策略
问题?
为满足业务需求和保证数据访问安全性,要求市场部不能访问财务部、研发部,公司总部不能访问研发部
filter-policy
过滤策略,能够对接收或发布的路由进行过滤,可以调用ACL、ip-prefix等工具来匹配路由,可应用于ISIS、OSPF、BGP等协议。filter-policy分为import和export两个方向
命令格式:
对协议接收的路由进行过滤:
filter-policy { acl-number | ip-prefix ip-prefix-name } import
对协议发布的路由进行过滤:
filter-policy { acl-number | ip-prefix ip-prefix-name } export
案例1:filter-policy(rip)
场景:R1、R2、R3之间运行RIP协议,要求R2过滤掉其中奇数路由
在R2中查看RIP学习到的路由
[R2]display ip routing-table protocol rip Route Flags: R - relay, D - download to fib------------------------------------------------------------------------------Public routing table : RIP Destinations : 5 Routes : 5 RIP routing table status : <Active> Destinations : 5 Routes : 5Destination/Mask Proto Pre Cost Flags NextHop Interface 172.16.1.0/24 RIP 100 1 D 10.1.12.1 GigabitEthernet0/0/0 172.16.2.0/24 RIP 100 1 D 10.1.12.1 GigabitEthernet0/0/0 172.16.3.0/24 RIP 100 1 D 10.1.12.1 GigabitEthernet0/0/0 172.16.4.0/24 RIP 100 1 D 10.1.12.1 GigabitEthernet0/0/0 172.16.5.0/24 RIP 100 1 D 10.1.12.1 GigabitEthernet0/0/0RIP routing table status : <Inactive> Destinations : 0 Routes : 0
方法一:在R2的RIP进程下的IMPORT方向上调用
在R2上面做filter-policy来实现需求
第一步:首先匹配奇数路由出来
#acl number 2000 rule 5 deny source 172.16.1.0 0.0.6.0 rule 100000 permit #
注意:ACL用于控制平面过滤路由的时候,最后都会有一条隐含拒绝所有,因此需要允许其他流量放行
第二步:在RIP进程下进行调用
#rip 1 version 2filter-policy 2000 import#
注意:在R2的import调用的时候,会影响到R2本身的流量
第三步:查看R2和R3的路由表
[R2]display ip routing-table protocol rip Route Flags: R - relay, D - download to fib------------------------------------------------------------------------------Public routing table : RIP Destinations : 2 Routes : 2 RIP routing table status : <Active> Destinations : 2 Routes : 2Destination/Mask Proto Pre Cost Flags NextHop Interface 172.16.2.0/24 RIP 100 1 D 10.1.12.1 GigabitEthernet0/0/0 172.16.4.0/24 RIP 100 1 D 10.1.12.1 GigabitEthernet0/0/0RIP routing table status : <Inactive> Destinations : 0 Routes : 0
在R3上面查看rip的路由
<R3>display ip routing-table protocol rip Route Flags: R - relay, D - download to fib------------------------------------------------------------------------------Public routing table : RIP Destinations : 3 Routes : 3 RIP routing table status : <Active> Destinations : 3 Routes : 3Destination/Mask Proto Pre Cost Flags NextHop Interface 10.1.12.0/24 RIP 100 1 D 10.1.23.2 GigabitEthernet0/0/1 172.16.2.0/24 RIP 100 2 D 10.1.23.2 GigabitEthernet0/0/1 172.16.4.0/24 RIP 100 2 D 10.1.23.2 GigabitEthernet0/0/1RIP routing table status : <Inactive> Destinations : 0 Routes : 0<R3>
方法二:在R2的RIP进程下的EXPORT方向上调用
如果在R2的export方向上调用的时候
#rip 1 version 2 network 10.0.0.0 filter-policy 2000 export#
在R2上查看rip路由
[R2]display ip routing-table protocol rip Route Flags: R - relay, D - download to fib------------------------------------------------------------------------------Public routing table : RIP Destinations : 5 Routes : 5 RIP routing table status : <Active> Destinations : 5 Routes : 5Destination/Mask Proto Pre Cost Flags NextHop Interface 172.16.1.0/24 RIP 100 1 D 10.1.12.1 GigabitEthernet0/0/0 172.16.2.0/24 RIP 100 1 D 10.1.12.1 GigabitEthernet0/0/0 172.16.3.0/24 RIP 100 1 D 10.1.12.1 GigabitEthernet0/0/0 172.16.4.0/24 RIP 100 1 D 10.1.12.1 GigabitEthernet0/0/0 172.16.5.0/24 RIP 100 1 D 10.1.12.1 GigabitEthernet0/0/0RIP routing table status : <Inactive> Destinations : 0 Routes : 0
在R3上查看RIP路由
<R3>display ip routing-table protocol ripRoute Flags: R - relay, D - download to fib------------------------------------------------------------------------------Public routing table : RIP Destinations : 3 Routes : 3 RIP routing table status : <Active> Destinations : 3 Routes : 3Destination/Mask Proto Pre Cost Flags NextHop Interface 10.1.12.0/24 RIP 100 1 D 10.1.23.2 GigabitEthernet0/0/1 172.16.2.0/24 RIP 100 2 D 10.1.23.2 GigabitEthernet0/0/1 172.16.4.0/24 RIP 100 2 D 10.1.23.2 GigabitEthernet0/0/1RIP routing table status : <Inactive> Destinations : 0 Routes : 0
小结:
filter-policy在import方向上调用的时候,会影响自身路由表的变化
filter-policy在export方向上调用的时候,不会影响自身路由表的变化
案例2:filter-policy(ospf)
场景:R1、R2、R3之间运行OSPF协议,要求R2过滤掉其中奇数路由
查看OSPF的邻居关系
[R2]display ospf peer brief OSPF Process 1 with Router ID 10.1.12.2 Peer Statistic Information ---------------------------------------------------------------------------- Area Id Interface Neighbor id State 0.0.0.0 GigabitEthernet0/0/0 10.1.12.1 Full 0.0.0.0 GigabitEthernet0/0/1 10.1.23.3 Full ----------------------------------------------------------------------------
查看R2上面学习到的OSPF路由
[R2]display ip routing-table protocol ospfRoute Flags: R - relay, D - download to fib------------------------------------------------------------------------------Public routing table : OSPF Destinations : 5 Routes : 5 OSPF routing table status : <Active> Destinations : 5 Routes : 5Destination/Mask Proto Pre Cost Flags NextHop Interface 172.16.1.1/32 OSPF 10 1 D 10.1.12.1 GigabitEthernet0/0/0 172.16.2.1/32 OSPF 10 1 D 10.1.12.1 GigabitEthernet0/0/0 172.16.3.1/32 OSPF 10 1 D 10.1.12.1 GigabitEthernet0/0/0 172.16.4.1/32 OSPF 10 1 D 10.1.12.1 GigabitEthernet0/0/0 172.16.5.1/32 OSPF 10 1 D 10.1.12.1 GigabitEthernet0/0/0OSPF routing table status : <Inactive> Destinations : 0 Routes : 0
方法一:在R2的OSPF进程下的IMPORT方向调用
在R2上面做filter-policy来实现需求
第一步:首先匹配奇数路由出来
#acl number 2000 rule 5 deny source 172.16.1.0 0.0.6.0 rule 100000 permit #
注意:ACL用于控制平面过滤路由的时候,最后都会有一条隐含拒绝所有,因此需要允许其他流量放行
第二步:在OSPF进程下进行调用
#ospf 1 filter-policy 2000 import#
第三步:查看R2和R3的路由表
查看R2的路由表和R2的LSDB表
[R2]display ip routing-table protocol ospfRoute Flags: R - relay, D - download to fib------------------------------------------------------------------------------Public routing table : OSPF Destinations : 2 Routes : 2 OSPF routing table status : <Active> Destinations : 2 Routes : 2Destination/Mask Proto Pre Cost Flags NextHop Interface 172.16.2.0/24 OSPF 10 1 D 10.1.12.1 GigabitEthernet0/0/0 172.16.4.0/24 OSPF 10 1 D 10.1.12.1 GigabitEthernet0/0/0OSPF routing table status : <Inactive> Destinations : 0 Routes : 0
查看R2的LSDB
[R2]display ospf lsdb OSPF Process 1 with Router ID 10.1.12.2 Link State Database Area: 0.0.0.0 Type LinkState ID AdvRouter Age Len Sequence Metric Router 10.1.23.3 10.1.23.3 452 36 80000004 1 Router 10.1.12.2 10.1.12.2 457 48 80000007 1 Router 10.1.12.1 10.1.12.1 98 96 80000015 1 Network 10.1.23.3 10.1.23.3 452 32 80000002 0 Network 10.1.12.1 10.1.12.1 507 32 80000002 0
结论:
由于OSPF是链路状态路由协议,传递是LSA信息,而你的filter-polic过滤的是路由信息,因此R3路由表中可以学习到完整的条目
查看R3的OSPF路由表
<R3>display ip routing-table protocol ospf Route Flags: R - relay, D - download to fib------------------------------------------------------------------------------Public routing table : OSPF Destinations : 6 Routes : 6 OSPF routing table status : <Active> Destinations : 6 Routes : 6Destination/Mask Proto Pre Cost Flags NextHop Interface 10.1.12.0/24 OSPF 10 2 D 10.1.23.2 GigabitEthernet0/0/1 172.16.1.0/24 OSPF 10 2 D 10.1.23.2 GigabitEthernet0/0/1 172.16.2.0/24 OSPF 10 2 D 10.1.23.2 GigabitEthernet0/0/1 172.16.3.0/24 OSPF 10 2 D 10.1.23.2 GigabitEthernet0/0/1 172.16.4.0/24 OSPF 10 2 D 10.1.23.2 GigabitEthernet0/0/1 172.16.5.0/24 OSPF 10 2 D 10.1.23.2 GigabitEthernet0/0/1OSPF routing table status : <Inactive> Destinations : 0 Routes : 0<R3>
方法二:在R2的OSPF进程下的EXPORT方向调用
[R2]display 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 : 5Destination/Mask Proto Pre Cost Flags NextHop Interface 172.16.1.0/24 OSPF 10 1 D 10.1.12.1 GigabitEthernet0/0/0 172.16.2.0/24 OSPF 10 1 D 10.1.12.1 GigabitEthernet0/0/0 172.16.3.0/24 OSPF 10 1 D 10.1.12.1 GigabitEthernet0/0/0 172.16.4.0/24 OSPF 10 1 D 10.1.12.1 GigabitEthernet0/0/0 172.16.5.0/24 OSPF 10 1 D 10.1.12.1 GigabitEthernet0/0/0OSPF routing table status : <Inactive> Destinations : 0 Routes : 0[R2]
第一步:首先匹配奇数路由出来
#acl number 2000 rule 5 deny source 172.16.1.0 0.0.6.0 rule 100000 permit #
注意:ACL用于控制平面过滤路由的时候,最后都会有一条隐含拒绝所有,因此需要允许其他流量放行
第二步:在OSPF进程下进行调用
#ospf 1 filter-policy 2000 import#
第三步:查看R2和R3的路由表
[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 : 2Destination/Mask Proto Pre Cost Flags NextHop Interface 172.16.2.0/24 OSPF 10 1 D 10.1.12.1 GigabitEthernet0/0/0 172.16.4.0/24 OSPF 10 1 D 10.1.12.1 GigabitEthernet0/0/0OSPF routing table status : <Inactive> Destinations : 0 Routes : 0
因为R2是ABR路由器。而OSPF在整个区域内是链路状态路由协议,在区域间是距离矢量路由协议,所以,可以在R2的的import方向上进行过滤动作,故因此R3上面也没有奇数路由条目
查看R3的路由表
[R3]display ip routing-table protocol ospfRoute Flags: R - relay, D - download to fib------------------------------------------------------------------------------Public routing table : OSPF Destinations : 3 Routes : 3 OSPF routing table status : <Active> Destinations : 3 Routes : 3Destination/Mask Proto Pre Cost Flags NextHop Interface 10.1.12.0/24 OSPF 10 2 D 10.1.23.2 GigabitEthernet0/0/1 172.16.2.0/24 OSPF 10 2 D 10.1.23.2 GigabitEthernet0/0/1 172.16.4.0/24 OSPF 10 2 D 10.1.23.2 GigabitEthernet0/0/1OSPF routing table status : <Inactive> Destinations : 0 Routes : 0
或者在R2的的export方向上进行过滤
在OSPF进程下进行调用
#ospf 1 filter-policy 2000 export#
查看R2和R3的路由表
[R2]display 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 : 5Destination/Mask Proto Pre Cost Flags NextHop Interface 172.16.1.0/24 OSPF 10 1 D 10.1.12.1 GigabitEthernet0/0/0 172.16.2.0/24 OSPF 10 1 D 10.1.12.1 GigabitEthernet0/0/0 172.16.3.0/24 OSPF 10 1 D 10.1.12.1 GigabitEthernet0/0/0 172.16.4.0/24 OSPF 10 1 D 10.1.12.1 GigabitEthernet0/0/0 172.16.5.0/24 OSPF 10 1 D 10.1.12.1 GigabitEthernet0/0/0OSPF routing table status : <Inactive> Destinations : 0 Routes : 0
在R3上面查看路由表
[R3]display ip routing-table protocol ospf Route Flags: R - relay, D - download to fib------------------------------------------------------------------------------Public routing table : OSPF Destinations : 6 Routes : 6 OSPF routing table status : <Active> Destinations : 6 Routes : 6Destination/Mask Proto Pre Cost Flags NextHop Interface 10.1.12.0/24 OSPF 10 2 D 10.1.23.2 GigabitEthernet0/0/1 172.16.1.0/24 OSPF 10 2 D 10.1.23.2 GigabitEthernet0/0/1 172.16.2.0/24 OSPF 10 2 D 10.1.23.2 GigabitEthernet0/0/1 172.16.3.0/24 OSPF 10 2 D 10.1.23.2 GigabitEthernet0/0/1 172.16.4.0/24 OSPF 10 2 D 10.1.23.2 GigabitEthernet0/0/1 172.16.5.0/24 OSPF 10 2 D 10.1.23.2 GigabitEthernet0/0/1OSPF routing table status : <Inactive> Destinations : 0 Routes : 0
总结:由于R2和R3之间传递的还是链路状态路由信息
route-policy
Route-Policy是一种功能非常强大的路由策略工具,它可以灵活地与ACL、IP-Prefix List、As-Path-Filter等其它工具配合使用
路由策略的作用是当路由器在发布、接收和引入路由信息时,可根据实际组网需要实施一些策略,以便对路由信息进行过滤或改变路由信息的属性,如:
.控制路由的发布:只发布满足条件的路由信息。
控制路由的接收:只接收必要、合法的路由信息,以控制路由表的容量,提高网络的安全性。
过滤和控制引入的路由:一种路由协议在引入其它路由协议时,只引入一部分满足条件的路由信息,并对所引入的路由信息的某些属性进行设置,以使其满足本协议的要求。
命令语法:
Route-Policy:route-policy route-policy-name { permit | deny } node nodeif-match {acl/cost/interface/ip next-hop/ip-prefix}apply {cost/ip-address next-hop/tag}
注意:
Route-Policy由若干个node构成,node之间是“或”的关系。且每个node下可以有若干个if-mach和apply子句,if-match之间是“与”的关系
Route-Policy的每个node都有相应的permit模式或deny模式
4步走:
第一步:
如果是permit模式,则当路由项满足该node的所有if-match子句时,就被允许通过该node的过滤并执行该node的apply子句,且不再进入下一个node
第二步:
如果路由项没有满足该node的所有if-match子句,则会进入下一个node继续进行过滤。
第三步:
如果是deny模式,则当路由项满足该node的所有if-match子句时,就被拒绝通过该node的过滤,这时apply子句不会被执行,并且不进入下一个node;否则就进入下一个node继续进行过滤
第四步:
如果都没有匹配成功的话,router-policy默认情况下是拒绝通过
案例3:控制路由引入并修改路由属性
在R2上面将RIP进程引进OSPF,通过route-policy修改路由的属性,并将所有奇数路由的cost值修改为100,偶数路由打上路由标记Tag为200
第一步:首先匹配奇数路由和偶数路由出来
#acl number 2000 rule 5 permit source 172.16.1.0 0.0.6.0
偶数路由
#acl number 2001 rule 5 permit source 172.16.0.0 0.0.6.0 rule 100000 permit #
第二步:配置策略工具route-policy
#route-policy R2O permit node 10 if-match acl 2000 apply cost 100 #route-policy R2O permit node 20 if-match acl 2001 apply tag 200 #route-policy R2O permit node 1000 #
注意:
后面添加了一条node为1000的条目 目的是为了让其他路由通过
第三步:应用策略工具
#ospf 1 import-route rip 1 route-policy R2O#
第四步:在R3上进行检查
R3]display ip routing-table protocol ospf Route Flags: R - relay, D - download to fib------------------------------------------------------------------------------Public routing table : OSPF Destinations : 6 Routes : 6 OSPF routing table status : <Active> Destinations : 6 Routes : 6Destination/Mask Proto Pre Cost Flags NextHop Interface 10.1.12.0/24 O_ASE 150 1 D 10.1.23.2 GigabitEthernet0/0/1 172.16.1.0/24 O_ASE 150 100 D 10.1.23.2 GigabitEthernet0/0/1 172.16.2.0/24 O_ASE 150 1 D 10.1.23.2 GigabitEthernet0/0/1 172.16.3.0/24 O_ASE 150 100 D 10.1.23.2 GigabitEthernet0/0/1 172.16.4.0/24 O_ASE 150 1 D 10.1.23.2 GigabitEthernet0/0/1 172.16.5.0/24 O_ASE 150 100 D 10.1.23.2 GigabitEthernet0/0/1OSPF routing table status : <Inactive> Destinations : 0 Routes : 0
[R3]display ospf lsdb ase OSPF Process 1 with Router ID 10.1.23.3 Link State Database Type : External Ls id : 10.1.23.0 Adv rtr : 10.1.12.2 Ls age : 34 Len : 36 Options : E seq# : 80000002 chksum : 0xade6 Net mask : 255.255.255.0 TOS 0 Metric: 1 E type : 2 Forwarding Address : 0.0.0.0 Tag : 1 Priority : Low Type : External Ls id : 172.16.4.0 Adv rtr : 10.1.12.2 Ls age : 34 Len : 36 Options : E seq# : 80000002 chksum : 0x9499 Net mask : 255.255.255.0 TOS 0 Metric: 1 E type : 2 Forwarding Address : 0.0.0.0 Tag : 200 Priority : Low Type : External Ls id : 172.16.5.0 Adv rtr : 10.1.12.2 Ls age : 505 Len : 36 Options : E seq# : 80000001 chksum : 0x6131 Net mask : 255.255.255.0 TOS 0 Metric: 100 E type : 2 Forwarding Address : 0.0.0.0 Tag : 1 Priority : Low Type : External Ls id : 172.16.2.0 Adv rtr : 10.1.12.2 Ls age : 37 Len : 36 Options : E seq# : 80000002 chksum : 0xaa85 Net mask : 255.255.255.0 TOS 0 Metric: 1 E type : 2 Forwarding Address : 0.0.0.0 Tag : 200 Priority : Low Type : External Ls id : 172.16.3.0 Adv rtr : 10.1.12.2 Ls age : 508 Len : 36 Options : E seq# : 80000001 chksum : 0x771d Net mask : 255.255.255.0 TOS 0 Metric: 100 E type : 2 Forwarding Address : 0.0.0.0 Tag : 1 Priority : Low Type : External Ls id : 172.16.1.0 Adv rtr : 10.1.12.2 Ls age : 510 Len : 36 Options : E seq# : 80000001 chksum : 0x8d09 Net mask : 255.255.255.0 TOS 0 Metric: 100 E type : 2 Forwarding Address : 0.0.0.0 Tag : 1 Priority : Low Type : External Ls id : 10.1.12.0 Adv rtr : 10.1.12.2 Ls age : 42 Len : 36 Options : E seq# : 80000002 chksum : 0x2778 Net mask : 255.255.255.0 TOS 0 Metric: 1 E type : 2 Forwarding Address : 0.0.0.0 Tag : 1 Priority : Low
案例4:route-policy难点研究
对比项 | router-policy | ACL或者前缀列表 |
---|---|---|
permit的意思 | 是指将匹配到的路由允许通过或者被执行路由策略 | 是指匹配该路由 |
deny的意思 | 是指将路由进行过滤 | 是指不匹配该路由 |
第一步:在R2上面定义ACL
#acl number 2000 rule 5 deny source 172.16.1.0 0 rule 10 permit source 172.16.2.0 0 acl number 2001 rule 5 deny source 172.16.3.0 0 rule 10 permit source 172.16.4.0 0 #
第二步:定义策略
#route-policy R2O deny node 10 if-match acl 2000 #route-policy R2O permit node 20 if-match acl 2001 apply cost 50 #route-policy R2O permit node 1000 #
第三步:应用策略工具
#ospf 1 import-route rip 1 route-policy R2O#
第四步:在R3上面查看路由表
<R3>display 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 : 5Destination/Mask Proto Pre Cost Flags NextHop Interface 10.1.12.0/24 O_ASE 150 1 D 10.1.23.2 GigabitEthernet0/0/1 172.16.1.0/24 O_ASE 150 1 D 10.1.23.2 GigabitEthernet0/0/1 172.16.3.0/24 O_ASE 150 1 D 10.1.23.2 GigabitEthernet0/0/1 172.16.4.0/24 O_ASE 150 50 D 10.1.23.2 GigabitEthernet0/0/1 172.16.5.0/24 O_ASE 150 1 D 10.1.23.2 GigabitEthernet0/0/1OSPF routing table status : <Inactive> Destinations : 0 Routes : 0
分析如下:
在node 10上面,router-policy的匹配模式为deny,if-match中调用了acl 2000,该节点会匹配到172.16.2.0这条路由,而172.16.1.0在这个节点不会被匹配到,并且会放到下面的节点进行匹配,因此这个节点所实现的作用是将172.16.2.0过滤掉
在node 20上面,router-policy的匹配模式为permit,if-match中调用了acl 2001,该节点会匹配到172.16.4.0这条路由,而172.16.3.0这个节点会放到下面的节点进行匹配,因此这个节点所实现的作用是将172.16.4.0路由的cost值属性改为50
在node 30上面,router-policy的匹配模式为permit,其作用是将前面节点没有被匹配到的路由全部匹配到,因此在上面的节点未被匹配的172.16.1.0和172.16.3.0将被允许通过,且不修改任何属性
.