XCIE-HUAWEI-Route-policy+,什么是路由策略,什么是策略路由
Route-policy
本来我想放到前面一起讲的,但是感觉内容太多了,估计不太好消化
分开吧哈~
思科叫route-map哈
意思是一样的,但是功能上差很远
在思科在,route-map可以被调用到很多功能中
但是在华为中,只能调用路由策略中
首先这个,route-policy,是用的最多的
有啥用呢?
说都说到这个了,还是说说这个吧
什么是路由策略,什么是策略路由
路由策略
先有路由,再有策略(记住这个顺序)
给路由这个对象,做修改(想想物理的参照物)
这个很好理解
然后啊
然后a
到这个
策略路由了哈!
别给晕了
他是啥呢?
他是直接依靠策略转发数据的
在思科里面.route-map既能做路由策略也能做策略路由
小总结
1.路由策略干路由表
2.策略路由仅仅是策略
3.因为无论任何品牌,策略是凌驾于路由之上的,也可以关注下一篇和思科的文章去看看
4我也不知道发明那个人怎么想的,别问
上面说了,路由策略,是有了路由再做策略
那么有路由做策略的第一步
那不还是得抓嘛?1匹配路由
1,1直接依靠路由条目来匹配
工具:ACL,前缀列表
1.2,依靠路由条目的属性来匹配,比如cost,tpye,tag等(这个东东在BGP很常用)2修改路由属性
2.1通过匹配路由条目,再对这些路由条目的属性做修改.
3配合其他工具
3.1例如,filter-policy,做过滤
3.2例如,配合import-route可以对引入的路由做过滤或者修改
3.3例如,配合preference,可以修改指定路由条目的优先级
长啥样子呢?
[AR1]route-policy name permit node 10
Info: You are overwriting this sequence.
[AR1-route-policy]
报错那个不用管,也不算报错,就是他告诉我我在覆盖操作
route-policy 模块
name就是name了
然后permit的意思是行为
permit/deny
不同场景下的意义不一样
它不一定代表允许或者拒绝
node是节点的意思,默认拒绝所有哈
10就是第一行的意思 (没有步长哈),从小到大,唯一匹配
比如
当route-policy用在filter-poicy里面的时候
permit的意义是允许加表
deny则是拒绝加表
当route-policy用于对路由属性修改的时候,一般只用permit,这个时候的permit的意义就是抓取
其实一般都是写permit的多
本章只讲两个
一个是apply
一个是if-match
只能说这翻译有点奇怪
if-match
用来匹配条件,即可是路由条目,也可以是路由属性
用ACL或者前缀列表来抓.还有cost tpye,tag等
如果有多个则同时匹配
如果什么都不写
就相当于匹配所有
apply
这个东东是执行语句
用来指定某个动作,比如路由属性(例如cost)
如果一个节点里面有多个apply,则是同时生效
如果一个节点中没有apply,则是不生效
理论讲完了,讲实验了
拓扑图
R1和R2做ospf,右边有四条静态路由
ip route-static 192.168.1.0 24 null 0
ip route-static 192.168.2.0 24 null 0
ip route-static 192.168.3.0 24 null 0
ip route-static 192.168.4.0 24 null 0
需求
1.在R2上把四条静态引入到sopf
2.192.168.1.0/24改为cost=100,tpye=1
2.192.168.2.0/24改为cost=200.tpye=2
3.192.168.3.0/24默认
4.192.168.4.0/24引入後tage=500
5.r1上,讲tag=500的外部路由拒绝加表
6.r1上,192.168.3.0/24优先级改为20
初始配置就懒得做了
就是配ip和宣告的
直接看效果
然后就要开始做需求了
首先
用前缀列表把路由抓出来先
建议呢,抓路由都是用前缀列表
为什么呢
因为操作情况下,有时候ACL的通配符可能是会人为的抓错的
但是前缀列表就不会,因为他不是发反掩码,怎么看都没那那么的反人类
然后就到route-policy了
这里的route-policy的名字是ospf-1
这里再讲一次
permit的意思并不是放行/拒绝
而是匹配,不匹配的意思
192.168.1.0需求
[R2-route-policy]if-match ?
acl Specify an ACL
as-path-filter BGP AS path list
community-filter Match BGP community filter
cost Match metric of route
extcommunity-filter Match BGP/VPN extended community filter
interface Specify the interface matching the first hop of routes
ip IP information
ip-prefix Specify an address prefix-list
ipv6 IPv6 Information
mpls-label Give the Label
rd-filter Route-distinguisher filter
route-type Match route-type of route
tag Match tag of route
[R2-route-policy]if-match ip-p
[R2-route-policy]if-match ip-prefix aaa
[R2-route-policy]
然后这个地方if-match,就是匹配什么条件
然后前缀列表,ospf-1是ip-premix的名字
抓完了,但是要怎么改呢?
需求是
引入後cost=100,tpye=1
这两个是需求哈
然后还是在这个下面
[R2-route-policy]apppy cost-type type-1 // 改type=1
[R2-route-policy]apply cost 100 // 改cost
[R2-route-policy]
这个就是修改的条件
这已经做完了吗?
还没有
无论是接口还是路由协议里面
只能调用一个route-policy
所以要在里面做多个节点俩实现不同的需求
比如你一个星期只能提一次意见
一次意见里面可以包含多个东西
过了这个村就没这店了
得下周了
192.168.2.0需求
route-policy ospf-1 permit node 20
if-match ip-prefix bbb
apply cost 200
apply cost-type type-2 //其实呢,这个不写也可以,因为ospf引入默认就是type2的,但是我这里还是写上去吧
192.168.3.0没需求,就不理他了,虽然抓了
192.168.4.0需求
route-policy ospf-1 permit node 40
if-match ip-prefix ddd
apply tag 500
来看看总的
[R2]dis route-policy ospf-1
Route-policy : ospf-1
permit : 10 (matched counts: 40)
Match clauses :
if-match ip-prefix aaa
Apply clauses :
apply cost 100
apply cost-type type-1
permit : 20 (matched counts: 0)
Match clauses :
if-match ip-prefix bbb
Apply clauses :
apply cost 200
apply cost-type type-2
permit : 40 (matched counts: 0)
Match clauses :
if-match ip-prefix ddd
Apply clauses :
apply tag 500
后面那个matched counts是匹配到多少数据的意思
第一行192.168.1.0那个有是因为一开始我挂上去了
后面打算放后面讲,所有有匹配到数据
[R2]
然后现在去ospf里面挂进去(注意哈,有坑哦)
ospf 1
import-route static route-policy ospf-1
area 0.0.0.0
network 1.1.1.0 0.0.0.255
#
[R2-ospf-1]dis ospf lsdb
OSPF Process 1 with Router ID 1.1.1.2
Link State Database
Area: 0.0.0.0
Type LinkState ID AdvRouter Age Len Sequence Metric
Router 1.1.1.2 1.1.1.2 401 36 80000006 1
Router 1.1.1.1 1.1.1.1 847 36 80000003 1
Network 1.1.1.2 1.1.1.2 846 32 80000001 0
AS External Database
Type LinkState ID AdvRouter Age Len Sequence Metric
External 192.168.4.0 1.1.1.2 79 36 80000003 1
External 192.168.2.0 1.1.1.2 79 36 80000003 200
External 192.168.1.0 1.1.1.2 222 36 80000002 100
[R2-ospf-1]
有没有发现了什么?
娘的我192.168.3.0呢?
被吃了??
大家看这个配置做完了嘛??
其实还没有
因为route-policy默认拒绝所有,如果就这样挂上去了,其他都断了
所以得做一条空的permit any来兜底
什么叫空的呢?
[R2]route-policy ospf-1 permit node 40
做一条空的就行了
来看看做完之后的效果
[R2]route-policy ospf-1 ?
deny Specify a deny rule
permit Specify a permit rule
[R2]route-policy ospf-1 pr
[R2]route-policy ospf-1 pe
[R2]route-policy ospf-1 permit mo
[R2]route-policy ospf-1 permit ?
node Node of the route policy
[R2]route-policy ospf-1 permit no
[R2]route-policy ospf-1 permit node 50 ?
<cr> Please press ENTER to execute command
[R2]route-policy ospf-1 permit node 50
Info: New Sequence of this List.
[R2-route-policy]q
[R2]dis ospf lsdb
OSPF Process 1 with Router ID 1.1.1.2
Link State Database
Area: 0.0.0.0
Type LinkState ID AdvRouter Age Len Sequence Metric
Router 1.1.1.2 1.1.1.2 466 36 80000006 1
Router 1.1.1.1 1.1.1.1 912 36 80000003 1
Network 1.1.1.2 1.1.1.2 911 32 80000001 0
AS External Database
Type LinkState ID AdvRouter Age Len Sequence Metric
External 192.168.4.0 1.1.1.2 144 36 80000003 1
External 192.168.2.0 1.1.1.2 144 36 80000003 200
External 192.168.3.0 1.1.1.2 5 36 80000001 1
External 192.168.1.0 1.1.1.2 287 36 80000002 100
对于LSDB可以看到,192.168.3.0就出来了
这个时候再来看R1的路由表
<R1>dis ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 11 Routes : 11
Destination/Mask Proto Pre Cost Flags NextHop Interface
1.1.1.0/24 Direct 0 0 D 1.1.1.1 GigabitEthernet
0/0/0
1.1.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
1.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
192.168.1.0/24 O_ASE 150 101 D 1.1.1.2 GigabitEthernet
0/0/0
192.168.2.0/24 O_ASE 150 200 D 1.1.1.2 GigabitEthernet
0/0/0
192.168.3.0/24 O_ASE 150 1 D 1.1.1.2 GigabitEthernet
0/0/0
192.168.4.0/24 O_ASE 150 1 D 1.1.1.2 GigabitEthernet
0/0/0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
<R1>
可以看到已经修改成功了
一个是101一个是200是因为
ospf引入有两种类型,t1和t2
分别是累计 和 不累计cost值的区别
R1-OSPF-LSDB
<R1>dis ospf routing
OSPF Process 1 with Router ID 1.1.1.1
Routing Tables
Routing for Network
Destination Cost Type NextHop AdvRouter Area
1.1.1.0/24 1 Transit 1.1.1.1 1.1.1.1 0.0.0.0
Routing for ASEs
Destination Cost Type Tag NextHop AdvRouter
192.168.1.0/24 101 Type1 1 1.1.1.2 1.1.1.2
192.168.2.0/24 200 Type2 1 1.1.1.2 1.1.1.2
192.168.3.0/24 1 Type2 1 1.1.1.2 1.1.1.2
192.168.4.0/24 1 Type2 500 1.1.1.2 1.1.1.2
Total Nets: 5
Intra Area: 1 Inter Area: 0 ASE: 4 NSSA: 0
<R1>也可以看到这个192.168.1.0的类型已经改成1了,4.0的tag也改成500了
截至目前这个1-4的需求已经完成了
后面就是到R1上的操作了
那么R1上的route-policy怎么做呢?
[R1]route-policy deny de
[R1]route-policy deny deny no
[R1]route-policy deny deny node 10 //这里第一个deny是名字,第二个deny则是不匹配的意思
Info: New Sequence of this List.
[R1-route-policy]if
[R1-route-policy]if-match t
[R1-route-policy]if-match tag 500
[R1-route-policy]
[R1-route-policy]route-policy deny permit node 20 //这个兜底可千万忘了
然后我们来到ospf这过滤一波,注意哈,过滤嘛,那不就是又要回到咱们的filter-policy了?
对的没错
ospf 1
filter-policy route-policy deny import
area 0.0.0.0
network 1.1.1.0 0.0.0.255
好了,又到咱们的LSDB和咱们的路由表了
看效果说话嘛
AR1-OSPF-LSDB
[R1-ospf-1]DIS OSPF lsdb
OSPF Process 1 with Router ID 1.1.1.1
Link State Database
Area: 0.0.0.0
Type LinkState ID AdvRouter Age Len Sequence Metric
Router 1.1.1.2 1.1.1.2 1113 36 80000006 1
Router 1.1.1.1 1.1.1.1 1556 36 80000003 1
Network 1.1.1.2 1.1.1.2 1557 32 80000001 0
AS External Database
Type LinkState ID AdvRouter Age Len Sequence Metric
External 192.168.4.0 1.1.1.2 790 36 80000003 1
External 192.168.2.0 1.1.1.2 790 36 80000003 200
External 192.168.3.0 1.1.1.2 651 36 80000001 1
External 192.168.1.0 1.1.1.2 933 36 80000002 100
在LSDB里面,他是有的,因为这次过滤的是LSDB-路由表这个过程
并不是说不让他进入LSDB
AR1-ROUTING
[R1-ospf-1]dis ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 10 Routes : 10
Destination/Mask Proto Pre Cost Flags NextHop Interface
1.1.1.0/24 Direct 0 0 D 1.1.1.1 GigabitEthernet
0/0/0
1.1.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
1.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
192.168.1.0/24 O_ASE 150 101 D 1.1.1.2 GigabitEthernet
0/0/0
192.168.2.0/24 O_ASE 150 200 D 1.1.1.2 GigabitEthernet
0/0/0
192.168.3.0/24 O_ASE 150 1 D 1.1.1.2 GigabitEthernet
0/0/0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
但是路由表已经没了这个192.168.4.0的路由了
只因为他的tag是500
[R1-ospf-1]dis ospf routing
OSPF Process 1 with Router ID 1.1.1.1
Routing Tables
Routing for Network
Destination Cost Type NextHop AdvRouter Area
1.1.1.0/24 1 Transit 1.1.1.1 1.1.1.1 0.0.0.0
Routing for ASEs
Destination Cost Type Tag NextHop AdvRouter
192.168.1.0/24 101 Type1 1 1.1.1.2 1.1.1.2
192.168.2.0/24 200 Type2 1 1.1.1.2 1.1.1.2
192.168.3.0/24 1 Type2 1 1.1.1.2 1.1.1.2
Total Nets: 4
Intra Area: 1 Inter Area: 0 ASE: 3 NSSA: 0
[R1-ospf-1]
最后一个需求是
在R1上,192.168.3.0/24优先级改为20
一样的,前面讲了那么多例子了,一样是在这个route-policy做哈~
说到这,顺带提一下修改优先级这个东西
如果是这个,则是修改内部优先级,全部哈,只要是这个设备出去的ospf路由,全部改
如果是这,则是修改外部路由的优先级,ASE在华为里面就是ospf的外部路由的意思,五类的LSA
那么既然按照这个逻辑的话,没错.
route-policy也在这里面做
preference ase route-policy deny //修改外部路由优先级,调用route-policy
虽然我巧的是这个,但是
这个后面多了个150
what这是啥?
这个还是讲一下
这个的150是全局的意思
除了route-policy以外的,其他都是150
是这个意思
默认值是150
可以手动修改,最大值255
话不多说看表
R1-ospf-1]dis ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 10 Routes : 10
Destination/Mask Proto Pre Cost Flags NextHop Interface
1.1.1.0/24 Direct 0 0 D 1.1.1.1 GigabitEthernet
0/0/0
1.1.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
1.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
192.168.1.0/24 O_ASE 150 101 D 1.1.1.2 GigabitEthernet
0/0/0
192.168.2.0/24 O_ASE 150 200 D 1.1.1.2 GigabitEthernet
0/0/0
192.168.3.0/24 O_ASE 20 1 D 1.1.1.2 GigabitEthernet
0/0/0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
可以看到.1,0和2.0的路由都成150了
但是3.0的就是20
[R1-ospf-1]
可算讲完了呀,好多呀
刚好今天是2022/10/24,程序员快乐哈,虽然这个网工应该不算个程序员,但是多多少少会点linux,安全,python的东东~