1.基本概念
Router-Policy由一个或多个节点组成的列表,每个节点可以定义条件语句和执行语句,从编号最小的节点开始进行路由匹配,如果被匹配的对象满足所有条件,则执行该节点中的执行语句,并且不会再往下一个节点进行匹配,否则前往下一个节点匹配,以此类推。
2.基本配置
1)创建节点
Route-policy 节点名称 {permit|deny} node 编号
2)配置if-match语句匹配条件
(1)匹配ACL:if-match acl
(2)匹配IP前缀列表:if-match ip-prefix
(3)匹配度量值:if-match metric
(4)匹配出接口:if-match interface
(5)匹配路由标记:if-match tag
3)配置apply语句执行动作
(1)设置度量值:apply cost
(1)设置度量值类型:apply cost-type
(3)设置路由下一跳地址:apply ip-address next-hop
(4)设置路由优先级:apply preference
(5)设置路由标记:apply tag
3.配置案例
1)直连路由调用route-policy
(1)配置感兴趣路由
[R1]acl 2000
[R1-acl-basic-2000]rule permit source 192.168.1.0 0.0.0.0
[R1-acl-basic-2000]rule permit source 192.168.2.0 0.0.0.0
(2)创建路由策略,设置COST值
[R1]route-policy dsrw.com permit node 10
[R1-route-policy]if-match acl 2000
[R1-route-policy]apply cost 20
(3)配置OSPF,引入路由策略
[R1]ospf 1 router-id 1.1.1.1
[R1-ospf-1]area 0
[R1-ospf-1-area-0.0.0.0]network 12.1.1.0 0.255.255.255
[R1-ospf-1-area-0.0.0.0]quit
[R1-ospf-1]import-route direct route-policy dsrw.com
[R2]ospf 1 router-id 2.2.2.2
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]network 12.1.1.0 0.255.255.255
(4)查看R2路由表
<R2>display ip routing-table protocol ospf
Destination/Mask Proto Pre Cost Flags NextHop Interface
192.168.1.0/24 O_ASE 150 20 D 12.1.1.1 GigabitEthernet0/0/0
192.168.2.0/24 O_ASE 150 20 D 12.1.1.1 GigabitEthernet0/0/0
2)静态路由调用route-policy
(1)基础配置
[R1]ip route-static 192.168.1.0 24 14.1.1.4
[R1]ip route-static 192.168.2.0 24 14.1.1.4
[R1]ospf 1 router-id 1.1.1.1
[R1-ospf-1]area 0
[R1-ospf-1-area-0.0.0.0]network 13.1.1.0 0.255.255.255
[R2]ip route-static 192.168.3.0 24 25.1.1.5
[R2]ip route-static 192.168.4.0 24 25.1.1.5
[R2]ospf 1 router-id 2.2.2.2
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]network 23.1.1.0 0.255.255.255
[R3]ospf 1 router-id 3.3.3.3
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]network 13.1.1.0 0.255.255.255
[R3-ospf-1-area-0.0.0.0]network 23.1.1.0 0.255.255.255
(2)配置R1感兴趣路由
[R1]acl 2000
[R1-acl-basic-2000]rule permit source 192.168.1.0 0.0.0.0
[R1-acl-basic-2000]quit
[R1]acl 2001
[R1-acl-basic-2001]rule permit source 192.168.2.0 0.0.0.0
(3)配置R1路由策略
[R1]route-policy dsrw.com permit node 10
[R1-route-policy]if-match acl 2000
[R1-route-policy]apply cost 10
[R1]route-policy dsrw.com permit node 20
[R1-route-policy]if-match acl 2001
[R1-route-policy]apply cost 20
(4)配置R1引入路由策略
[R1]ospf 1
[R1-ospf-1]import-route static route-policy dsrw.com
(5)配置R2感兴趣路由
[R2]acl 2000
[R2-acl-basic-2000]rule permit source 192.168.3.0 0.0.0.0
[R2-acl-basic-2000]quit
[R2]acl 2001
[R2-acl-basic-2001]rule permit source 192.168.4.0 0.0.0.0
(6)配置R2路由策略
[R2]route-policy dsrw.com permit node 10
[R2-route-policy]if-match acl 2000
[R2-route-policy]apply cost 20
[R2]route-policy dsrw.com permit node 20
[R2-route-policy]if-match acl 2001
[R2-route-policy]apply cost 10
(7)配置R2引入路由策略
[R2]ospf 1
[R2-ospf-1]import-route static route-policy dsrw.com
(8)查看R3的LSDB
<R3>display ospf lsdb
OSPF Process 1 with Router ID 3.3.3.3
Link State Database
Area: 0.0.0.0
Type LinkState ID AdvRouter Age Len Sequence Metric
Router 2.2.2.2 2.2.2.2 48 36 80000004 1
Router 1.1.1.1 1.1.1.1 482 36 80000004 1
Router 3.3.3.3 3.3.3.3 1122 48 8000000A 1
Network 13.1.1.3 3.3.3.3 1122 32 80000002 0
Network 23.1.1.3 3.3.3.3 1232 32 80000002 0
AS External Database
Type LinkState ID AdvRouter Age Len Sequence Metric
External 192.168.4.0 2.2.2.2 48 36 80000001 10
External 192.168.2.0 1.1.1.1 482 36 80000001 20
External 192.168.3.0 2.2.2.2 48 36 80000001 20
External 192.168.1.0 1.1.1.1 482 36 80000001 10
(9)查看R3的路由表
<R3>display ip routing-table protocol ospf
Destination/Mask Proto Pre Cost Flags NextHop Interface
192.168.1.0/24 O_ASE 150 10 D 13.1.1.1 GigabitEthernet0/0/0
192.168.2.0/24 O_ASE 150 20 D 13.1.1.1 GigabitEthernet0/0/0
192.168.3.0/24 O_ASE 150 20 D 23.1.1.2 GigabitEthernet0/0/1
192.168.4.0/24 O_ASE 150 10 D 23.1.1.2 GigabitEthernet0/0/1
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
请登录后查看评论内容