2024年4月2日发(作者:)
Route Map
-> Route Map类似一种脚本语言。就像脚本语言当中的if语句,即
if( 条件语句 )
{
执行语句1;
执行语句2;
...
}
当符合某种条件,就开始执行某些语句。
---------------------------------------------------------
-> 而在route map当中就只有。【结构就比如match匹
配了某条路由,我就将这个路由的metric值set(设置)为10】
即类似于这样
match(匹配某个路由)
{
set metric = 10;
}
---------------------------------------------------------
-> router map的工作方式:
1、和ACL执行方式一样,也是从上到下的执行顺序,因为route map可能不
止一条。
2、route map可以随时插入某一行或者随时删掉某一行。比如route map有
间隔,默认就是间隔10,所以我创建第一条route map时,那么他的序号默认
为10,我再增加一条,我可以将这条序号手工指定为20,这样我就可以这样以
10为单位的间隔。方便在他们之间增加语句(下面实验会理解到,在这先了解
一下)
3、需要acl 或者 prefix-list进行感兴趣流的抓取
---------------------------------------------------------
-> router map的应用地方:
一般应用于以下三个地方
1、重分布上面
2、基于策略路由
3、BGP(应用最广)
在这里主要讲解的是在重分布上面的应用上面。而在BGP的应用在讲BGP协议
的时候应该会有涉及,那是以后的事了。
---------------------------------------------------------
-> 结合实验(应用于重分布下)
将rip重分布到ospf中去。
实验需求/目的:
1、将30.30.30.0/24 在重分布进ospf中,将其改变成E1类型(默认为E2)
2、将9.9.9.9/24 在重分布进ospf中,将9.9.9.9/24的seed cost值改为
10
3、将RIP重分布到ospf时,将13.1.1.0/24 deny掉
实验过程记录
R1(config)#router ospf 110
R1(config-router)#rou
R1(config-router)#router-id 1.1.1.1
R1(config-router)#net 12.1.1.0 0.0.0.255 a 0
R1(config-router)#net 10.10.10.0 0.0.0.255 a 0
R1(config-router)#
-------------------------------------------------------
R2#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#router ospf 110
R2(config-router)#router-id 2.2.2.2
R2(config-router)#net 12.1.1.0 0.0.0.255 a 0
R2(config-router)#router rip
R2(config-router)#no auto-summary
R2(config-router)#VER 2
R2(config-router)#net 13.1.1.0
-------------------------------------------------------
R3(config)#router rip
R3(config-router)#no au
R3(config-router)#no auto-summary
R3(config-router)#ver 2
R3(config-router)#net 13.1.1.0
R3(config-router)#net 30.30.30.0
R3(config-router)#net 9.9.9.0
R3(config-router)#
-------------------------------------------------------
在R2上面定义ACL 或者 prefix-list
这里使用ACL 匹配30.30.30.0 /24
使用prefix-list匹配 9.9.9.0/24
R2(config)#access-list 30 permit 30.30.30.0 0.0.0.255
R2(config)#ip prefix-list 9 permit 9.9.9.0/24
R2(config)#
-------------------------------------------------------
接下来,定义route map
R2(config)#route-map ?
//对route map起一个名字,这里起 rto
WORD Route map tag
R2(config)#route-map rto ?
//有deny 和 permit 可选,permit为允许,deny为拒绝
<0-65535> Sequence to insert to/delete from existing route-map entry
deny Route map denies set operations
permit Route map permits set operations
R2(config)#route-map rto permit ?
<0-65535> Sequence to insert to/delete from existing route-map entry
R2(config)#route-map rto permit 10
//标识
可以不加permit 10,即route-map rto 这样就可以了
route map,第一条默认序号为10,
R2(config-route-map)#match ip address ?
<1-199> IP access-list number
<1300-2699> IP access-list number (expanded range)
WORD IP access-list name
prefix-list Match entries of prefix-lists
R2(config-route-map)#match ip address 30
//匹配到ACL 号为30的路由,将进
行以下设置
R2(config-route-map)#set metric-type ?
external IS-IS external metric
internal IS-IS internal metric or Use IGP metric as the MED for BGP
type-1 OSPF external type 1 metric
type-2 OSPF external type 2 metric
R2(config-route-map)#set metric-type type-1
//修改为E1类型
R2(config-route-map)#ex
R2(config)#route-map rto permit 20
//第二条route-map语句,指定序号为20,
类型为permit,建议间隔为10,这样中间就可以有足够的空间插入其他route map语句,比如route-map
rto permit 15、类似命名ACL。不要忘记route map也是按顺序执行的哦。
R2(config-route-map)#match ip address prefix-list 9 ?
WORD IP prefix-list name
R2(config-route-map)#match ip address prefix-list 9
//匹配prefix-list
9 规则的路由
R2(config-route-map)#set metric 10
//如果匹配prefix-list 9 规则的路由,将
其metric设置为10
-------------------------------------------------
重分布调用route map
R2(config)#router ospf 110
R2(config-router)#redistribute rip subnets route-map ?
WORD Pointer to route-map entries
//重分布时挂上route-map
R2(config-router)#redistribute rip subnets route-map rto
R2(config-router)#
------------------------------------------------
在R1上查看一下效果。30.30.30.0/24已经修改为E1类型了,9.9.9.0/24
的metric已经修改为10了.
此时,我们应该注意到,我并没有写出第三个route map将13.1.1.0/24
deny掉,但是,R1的路由表却没有了13.1.1.0/24 这条路由。已经达到我们
之前所说的效果了。这是为什么?
很明显,route-map也是和ACL这些列表一样,有一个隐性默认拒绝的动作。
所以,如果最后我没有设置允许所有通过,那么其他的路由默认就会拒绝所有。
如果最后要让其他的路由允许通过,只需要写一条空的route map即可
如route-map rto permit 30 就这样一条空map即可,(注意acl号为30的
acl也无需定义,)没有match 和 set,没有match就是match any(匹配所
以) ,没有set,就是set nothing(什么都不设),permit即允许。
如果我要拒绝某个路由怎么写呢?
比如:
access-list 15 permit 13.1.1.0 0.0.0.255
route-map rto deny 25
match ip address 15
即可,没有set
再看一个例子
1、注意第二张图片的一条命令
match ip address 23 29 其中匹配的acl有acl号为23 和 29 ,那么这
个表示的是 “或” 的意思,也就是只要匹配到符合acl 23或者 29匹配到的
路由,即可对相应的路由进行操作设置
2、
这条route map语句表示的是没有匹配的剩下的所有路由都将metric值设置
为5000,E2类型


发布评论