1.路由策略Route-policy
规定路由器在发布路由时只发布某些满足特定条件的路由,在接收路由时只接收满足特定条件的路由,在引入路由时只引入某些满足特定条件的路由,等等。
Route-policy由一个或多个节点(Node)构成,Node之间是“或”的关系。每个Node都有一个编号,路由项按照Node编号由小到大的顺序通过各个Node。每个Node下可以有若干个if-match和apply子句,if-match之间是“与”的关系。If-match子句用来定义匹配规则,即路由项通过当前Node所需要满足的条件,匹配对象是路由项的某个属性,比如路由前缀、NextHop、Cost、路由优先级等;apply子句用来规定处理动作。
Route-policy的每个Node都有相应的permit模式或deny模式。如果是permit模式,则当路由项满足该Node的所有if-match子句时,就被允许通过该Node的过滤并执行该Node的apply子句,不再进入下一个Node;如果路由项没有满足该Node的所有if-match子句,则会进入下一个Node继续进行过滤。如果是deny模式,则当路由项满足该Node的所有if-match子句时,就被拒绝通过该Node的过滤,这时apply子句不会被执行,并且不进入下一个Node;否则就进入下一个Node继续进行过滤。
1.基本接口配置(略)
2.RIPv2和OSPF配置
[R1]rip
[R1-rip-1]version 2
[R1-rip-1]undo summary
[R1-rip-1]network 10.0.0.0
[R1-rip-1]network 192.168.1.0
[R1-rip-1]network 192.168.2.0
[R1-rip-1]network 192.168.3.0
[R1-rip-1]network 192.168.4.0
[R2]rip
[R2-rip-1]version 2
[R2-rip-1]undo summary
[R2-rip-1]network 10.0.0.0
[R2]ospf 1
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]network10.0.23.1 0.0.0.0
[R3]ospf 1
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]network10.0.23.2 0.0.0.0
[R3-ospf-1-area-0.0.0.0]network10.0.34.2 0.0.0.0
[R4]rip
[R4-rip-1]version 2
[R4-rip-1]undo summary
[R4-rip-1]network 10.0.0.0
[R4-rip-1]ospf 1
[R4-ospf-1]area 0
[R4-ospf-1-area-0.0.0.0]network10.0.34.1 0.0.0.0
在R2和R4上将RIP路由引入到OSPF协议中
[R2]ospf 1
[R2-ospf-1]import-route rip 1
[R4]ospf 1
[R4-ospf-1]import-route rip 1
配置完成后查看R3的IP路由表
[R3]dis ip routing-table
Route Flags: R - relay, D - downloadto fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 19Routes : 26
Destination/MaskProtoPreCostFlags NextHopInterface
10.0.1.1/32O_ASE1501D10.0.23.1Serial1/0/0
O_ASE1501D10.0.34.1Serial1/0/1
10.0.12.0/24O_ASE1501D10.0.23.1Serial1/0/0
O_ASE1501D10.0.34.1Serial1/0/1
10.0.14.0/24O_ASE1501D10.0.23.1Serial1/0/0
O_ASE1501D10.0.34.1Serial1/0/1
10.0.23.0/24Direct00D10.0.23.2Serial1/0/0
10.0.23.1/32Direct00D10.0.23.1Serial1/0/0
10.0.23.2/32Direct00D127.0.0.1Serial1/0/0
10.0.23.255/32Direct00D127.0.0.1Serial1/0/0
10.0.34.0/24Direct00D10.0.34.2Serial1/0/1
10.0.34.1/32Direct00D10.0.34.1Serial1/0/1
10.0.34.2/32Direct00D127.0.0.1Serial1/0/1
10.0.34.255/32Direct00D127.0.0.1Serial1/0/1
127.0.0.0/8Direct00D127.0.0.1InLoopBack0
127.0.0.1/32Direct00D127.0.0.1InLoopBack0
127.255.255.255/32Direct00D127.0.0.1InLoopBack0
192.168.1.0/24O_ASE1501D10.0.34.1Serial1/0/1
O_ASE1501D10.0.23.1Serial1/0/0
192.168.2.0/24O_ASE1501D10.0.23.1Serial1/0/0
O_ASE1501D10.0.34.1Serial1/0/1
192.168.3.0/24O_ASE1501D10.0.34.1Serial1/0/1
O_ASE1501D10.0.23.1Serial1/0/0
192.168.4.0/24O_ASE1501D10.0.23.1Serial1/0/0
O_ASE1501D10.0.34.1Serial1/0/1
255.255.255.255/32Direct00D127.0.0.1InLoopBack0
3.使用Route-policy对引入到OSPF进程的路由进行过滤和修改。
要求:从R3去往192.168.1.0/24和192.168.3.0/24这两个网段的流量经由路径R3-R2-R1,并且被引入OSPF时Cost值为20,cost-type为type-1。而在R4上引入两条路由时cost值为30,cost-type为type-1。
#首先使用ACL来进行匹配网段
[R2]acl 2000
[R2-acl-basic-2000]rule permitsource 192.168.1.0 0.0.254.255
[R4]acl 2000
[R4-acl-basic-2000]rule permitsource 192.168.1.0 0.0.254.255
#创建Route-policy,并进行相应设置
[R2]route-policy import-ospf permitnode 5
[R2-route-policy]if-match acl 2000
[R2-route-policy]apply cost 20
[R2-route-policy]apply cost-typetype-1
[R4]route-policy import-ospf permitnode 5
[R4-route-policy]if-match acl 2000
[R4-route-policy]apply cost 30
[R4-route-policy]apply cost-typetype-1
在R2、R4上将RIP引入OSPF时,应用Route-policy
[R2]ospf 1
[R2-ospf-1]import-route riproute-policy import-ospf
[R4]ospf 1
[R4-ospf-1]import-route riproute-policy import-ospf
配置完成后查看R3的IP路由表
[R3]dis ip routing-table
Route Flags: R - relay, D - downloadto fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 19Routes : 20
Destination/MaskProtoPreCostFlags NextHopInterface
10.0.1.1/32O_ASE1501D10.0.23.1Serial1/0/0
O_ASE1501D10.0.34.1Serial1/0/1
10.0.12.0/24O_ASE1501D10.0.34.1Serial1/0/1
10.0.14.0/24O_ASE1501D10.0.34.1Serial1/0/1
10.0.23.0/24Direct00D10.0.23.2Serial1/0/0
10.0.23.1/32Direct00D10.0.23.1Serial1/0/0
10.0.23.2/32Direct00D127.0.0.1Serial1/0/0
10.0.23.255/32Direct00D127.0.0.1Serial1/0/0
10.0.34.0/24Direct00D10.0.34.2Serial1/0/1
10.0.34.1/32Direct00D10.0.34.1Serial1/0/1
10.0.34.2/32Direct00D127.0.0.1Serial1/0/1
10.0.34.255/32Direct00D127.0.0.1Serial1/0/1
127.0.0.0/8Direct00D127.0.0.1InLoopBack0
127.0.0.1/32Direct00D127.0.0.1InLoopBack0
127.255.255.255/32Direct00D127.0.0.1InLoopBack0
192.168.1.0/24O_ASE15068D10.0.23.1Serial1/0/0
192.168.2.0/24O_ASE1501D10.0.34.1Serial1/0/1
192.168.3.0/24O_ASE15068D10.0.23.1Serial1/0/0
192.168.4.0/24O_ASE1501D10.0.34.1Serial1/0/1
255.255.255.255/32Direct00D127.0.0.1InLoopBack0
发现已经少了两条。
此外同时要求从R3去往192.168.2.0/24和192.18.4.0/24这两个网段的流量经由路径R3-R4-R1,并且cost值为20、cost-type为type-2。在R2上引入这两条路由时的Cost值为30。
[R2]acl 2001
[R2-acl-basic-2001]rule permitsource 192.168.2.0 0.0.254.255
[R4]acl 2001
[R4-acl-basic-2001]rule permitsource 192.168.2.0 0.0.254.255
#在R2、R4上添加新的策略node
[R2]route-policy import-ospf permitnode 10
[R2-route-policy]if-match acl 2001
[R2-route-policy]apply cost 30
[R2-route-policy]apply cost-typetype-2
[R4]route-policy import-ospf permitnode 10
[R4-route-policy]if-match acl 2001
[R4-route-policy]apply cost 20
[R4-route-policy]apply cost-typetype-2
//f���M�)i