route-map test permit/deny 10
match x1
match x2,x3
set Y
route-map test permit/deny 20
match x4
set Y
2.定义匹配条件
match ip address 匹配访问列表或前缀列表
match length 根据分组的第三层长度进行匹配
match interface 匹配下一跳出接口为指定接口之一的路由
match ip next-hop 匹配下一跳地址为特定访问列表中被允许的那些路由
match metric 匹配具有指定度量值的路由
match route-type 匹配指定类型的路由
match community 匹配BGP共同体
match tag 根据路由的标记进行匹配
3.定义set动作
set metric 设置路由协议的度量值
set metric-type 设置目标路由协议的度量值类型
set default interface 指定如何发送这样的分组
set interface 指定如何发送这样的分组
set ip default next-hop指定转发的下一跳
set ip next-hop 指定转发的下一跳
set next-hop 指定下一跳的地址,指定BGP的下一跳
set as-path
set community
set local-preference
set weight
set origin
set tag
default 关键字优先级低于明细路由
R1的配置如下:
access-list 1 permit 10.1.1.0
access-list 2 permit 10.1.2.0
route-map cisco permit 10
match ip address 1
set metric 10
route-map cisco permit 20
match ip address 2
set metric 20
router ospf 100
redis static route-map cisco
R2的配置如下:
access-list 1 permit 10.1.1.0
access-list 2 permit 10.1.2.0
route-map cisco permit 10
match ip address 1
set metric 20
route-map cisco permit 20
match ip address 2
set metric 10
router ospf 100
redis static route-map cisco
这样就实现了需求。
四、其他细节
1.验证match interface 的作用1
一个route-map语句中,如果没有match语句,则匹配所有
Match interface :To distribute any routes that have their next hop out one of the interfaces specified, use the match interface command in route-map configuration mode中文上的理解是,
match interface 匹配的是下一跳出接口是这个接口的路由条目
2.验证match interface 的作用2
3.验证set ip default next-hop
先保证R1、R3到10.1.1.0是有路由的,在R2上做测试:
如果R2上没有任何的动、静态路由,且配置如下:
access-list 1 permit 10.1.1.0 0.0.0.255
route-map test permit 10
match ip address 1
set ip default next-hop 10.1.12.1
则PC ping 10.1.13.0,数据走R1;