路由策略:传统的路由转发原理是首先根据报文的目的地址查找路由表,然后进行报文转发。
策略路由:为提高网络安全性,用户希望能够控制进入网络的报文,将没有权限进入网络或存在安全隐患的报文隔离在网络边界。流量过滤技术、策略路由以及使用MQC(Modular QoS Command-Line Interface,模块化QoS命令行)的方式控制报文的转发路径和进行流量过滤
PBR策略路由优先于传统路由表,匹配规则与router-policy类似,节点内的多个语句之间的关系为与,节点与节点之间的关系为或。
路由策略通过对路由信息进行过滤、属性设置等操作对路由的操作或控制,来影响路由的转发路径
策略路由则直接对数据报文进行操作,通过多种手段匹配感兴趣的报文,执行丢弃或者强制转发等操作。
PBR分类:接口策略路由、本地策略路由、智能策略路由
接口:只对转发的报文有作用,将接口PBR调用在接口下,对接口的入方向报文生效,默认按路由表吓一跳进行报文转发,配置接口PBR后,按接口指定的下一跳强制执行。
本地:对本地始发的流量生效。
智能:通过主动探测链路质量并匹配链路需求,从中选择一条最优路径,可以有效避免路由黑洞,网络震荡等问题,通过对匹配链路质量和网络业务对链路质量的要求,实现智能选路。
MQC三要素:流分类traffic classifier、流行为traffic behavior、流策略traffic policy
流分类:
⦁流分类中各规则之间的关系分为:and或or,缺省情况下的关系为or。
⦁and:当流分类中包含ACL规则时,报文必须匹配其中一条ACL规则以及所有非ACL规则;当流分类中没有ACL规则时,报文必须匹配所有非ACL规则。
⦁or:报文只要匹配了流分类中的一个规则,设备就认为报文匹配中该流分类。
流行为:定义执行动作,支持报文过滤、重标记优先级、重定向、流量统计
流策略:绑定流行为和流分类
本地策略路由实验
![](https://img-blog.csdnimg.cn/img_convert/a1db1fa7af8161bb52e85aced1b1a1db.png)
上行链路使用10.1.1.0网段 下行链路使用20.1.1.0 网段 使用本地策略路由使64-100的字节走上行链路使101-500的字节走下行的链路。路由器之间使用静态可以到达对方的loopback路由。
AR1: ip address 10.1.1.1 255.255.255.0
ip address 20.1.1.1 255.255.255.0
ip address 1.1.1.1 255.255.255.255
ip route-static 2.2.2.2 255.255.255.255 20.1.1.2
ip route-static 2.2.2.2 255.255.255.255 10.1.1.2
AR2:
ip address 10.1.1.2 255.255.255.0
ip address 20.1.1.2 255.255.255.0
ip address 2.2.2.2 255.255.255.255
ip route-static 1.1.1.1 255.255.255.255 10.1.1.1
ip route-static 1.1.1.1 255.255.255.255 20.1.1.1
![](https://img-blog.csdnimg.cn/img_convert/01e15645e8e9a9dac4316f957cba89f8.png)
可以ping通走的是20.1.1.2
使用pbr改变它
R1:policy-based-route shang permit node 10 策略路由 允许 进程10
if-match packet-length 64 100 ------64 - 100的字节
apply ip-address next-hop 10.1.1.2 -----吓一跳10.1.1.2
policy-based-route shang permit node 20
if-match packet-length 101 500
apply ip-address next-hop 20.1.1.2
本地应用它:
ip local policy-based-route shang -----在本地应用
查看:dis policy-based-route shang
![](https://img-blog.csdnimg.cn/img_convert/35374de6a6c9721e2b85549eacbe5bdf.png)
![](https://img-blog.csdnimg.cn/img_convert/d414b2ed372513c659a3c33c03a43468.png)
可以看到配置成功
也可以dis ip policy-based-route statistics local 查看匹配信息看ping的时候包
接口策略路由
![](https://img-blog.csdnimg.cn/img_convert/9f537d4d9cf95354ce3433dbd8ace086.png)
配置静态或ospf实现通信然后配置接口策略路由实现选路
acl number 2000 匹配源地址
rule 10 permit source 10.1.1.0 0.0.0.255
acl number 2001
rule 10 permit source 10.1.2.0 0.0.0.255
#
traffic classifier PC2 operator or 流分类绑定ACL
if-match acl 2001
traffic classifier PC1 operator or
if-match acl 2000
#
traffic behavior PC2 流行为改变下一跳
redirect ip-nexthop 40.1.1.2
statistic enable
traffic behavior PC1
redirect ip-nexthop 30.1.1.2
statistic enable
#
traffic policy PBR 流策略将流分类和流行为进行绑定
classifier PC1 behavior PC1
classifier PC2 behavior PC2
interface GigabitEthernet0/0/0 在接口入方向应用
ip address 20.1.1.2 255.255.255.0
traffic-policy PBR inbound
![](https://img-blog.csdnimg.cn/img_convert/ba23f5c517264b2b3e0aabc31e82883d.png)
应用源地址ping可以看到已经分流
也可以dis traffic policy statistics interface GigabitEthernet 0/0/0 inbound 查看匹配策略路由并转发的数据包个数和字节数
使用traffic-filter过滤流量
![](https://img-blog.csdnimg.cn/img_convert/b2d9daa037488a6d80850f0360215266.png)
配置traffic-filter 不让pc2通pc3.
acl number 3000 配置acl禁止20.1.1.0网段通30.1.1.0网段
rule 5 deny ip source 20.1.1.0 0.0.0.255 destination 30.1.1.0 0.0.0.255
rule 10 permit ip
interface GigabitEthernet0/0/2 在接口0/0/2outbound方向应用
ip address 30.1.1.254 255.255.255.0
traffic-filter outbound acl 3000
![](https://img-blog.csdnimg.cn/img_convert/3d0bea5c7f0b434a0f62acef3634a5df.png)
会发现pc2 ping的通pc1,但是ping不通pc3
也可以使用MQC过滤流量
acl number 3000
rule 5 permit ip source 20.1.1.0 0.0.0.255 destination 30.1.1.0 0.0.0.255 注意是permit
traffic classifier 1 流分类 在MQC里应用
if-match acl 3000
traffic behavior 1 流行为
deny
traffic policy 1 流策略
classifier 1 behavior 1
interface GigabitEthernet0/0/1 ----在入接口应用
ip address 20.1.1.254 255.255.255.0
traffic-policy 1 inbound
可以达到效果