策略路由的基本原理就是:根据ACL定义的不同数据流,经过路由器时,使用基于源地址或者基于目标地址策略转发数据到下一个接口,通过如下案例可以实现策略路由。
RouterA、RouterB、RouterC使用OSPF保证全网路由可达,并且在RouterA上查看路由表可以发现,到10.0.0.0的下一跳为RouterC的GE1/0/0接口地址。在RouterA上应用的策略路由,使从10.0.2.0/24到10.0.0.0/24的流量重定向到RouterB上。
RouterA的配置文件如下:
[RouterA] acl number 3001 //定义ACL匹配的目的源地址是10.0.2.0/24,目的地址是10.0.0.0/24
[RouterA-acl-adv-3001] rule 5 permit ip source 10.0.2.0 0.0.0.255 destination 10.0.0.0 0.0.0.255
[RouterA-acl-adv-3001] quit
[RouterA] traffic classifier credirect operator or //定义需要重定向的数据流分类
[RouterA-classifier-credirect] if-match acl 3001
[RouterA-classifier-credirect] quit
[RouterA] traffic behavior bredirect //定义流行为重定向到RouterB的GE1/0/0的接口地址
[RouterA-behavior-bredirect] redirect ip-nexthop 10.181.10.2
[RouterA-behavior-bredirect] quit
[RouterA] traffic policy predirect //绑定流策略
[RouterA-policy-predirect] classifier credirect behavior bredirect
[RouterA-policy-predirect] quit
[RouterA] interface GigabitEthernet1/0/0
[RouterA-GigabitEthernet1/0/0] ip address 10.181.20.1 255.255.255.0
[RouterA-GigabitEthernet1/0/0] quit
[RouterA] interface GigabitEthernet2/0/0
[RouterA-GigabitEthernet2/0/0] ip address 10.181.10.1 255.255.255.0
[RouterA-GigabitEthernet2/0/0] quit
[RouterA] interface GigabitEthernet3/0/0
[RouterA-GigabitEthernet3/0/0] ip address 10.0.2.1 255.255.255.0
[
RouterA-GigabitEthernet3/0/0] traffic-policy predirect inbound //从10.0.2.0/24到10.0.0.0/24的流量重定向到RouterB上[RouterA-GigabitEthernet3/0/0] quit
[RouterA] ospf 1 //配置OSPF路由协议
[RouterA-ospf-1] area 0.0.0.0
[RouterA-ospf-1-area-0.0.0.0] network 10.0.2.0 0.0.0.255
[RouterA-ospf-1-area-0.0.0.0] network 10.181.20.0 0.0.0.255
[RouterA-ospf-1-area-0.0.0.0] network 10.191.10.0 0.0.0.255
[RouterA-ospf-1-area-0.0.0.0] quit
RouterB的配置文件如下:
[RouterB] interface GigabitEthernet1/0/0
[RouterB-GigabitEthernet1/0/0] ip address 10.181.10.2 255.255.255.0
[RouterB-GigabitEthernet1/0/0] quit
[RouterB] interface GigabitEthernet2/0/0
[RouterB-GigabitEthernet2/0/0] ip address 10.184.10.1 255.255.255.0
[RouterB-GigabitEthernet2/0/0] quit
[RouterB] ospf 1 //配置OSPF路由协议
[RouterB-ospf-1] area 0.0.0.0
[RouterB-ospf-1-area-0.0.0.0] network 10.181.10.0 0.0.0.255
[RouterB-ospf-1-area-0.0.0.0] network 10.184.10.0 0.0.0.255
[RouterB-ospf-1-area-0.0.0.0] quit
RouterC的配置文件如下:
[RouterC] interface GigabitEthernet1/0/0
[RouterC-GigabitEthernet1/0/0] ip address 10.181.20.2 255.255.255.0
[RouterC-GigabitEthernet1/0/0] quit
[RouterC] interface GigabitEthernet2/0/0
[RouterC-GigabitEthernet2/0/0] ip address 10.184.10.2 255.255.255.0
[RouterC-GigabitEthernet2/0/0] quit
[RouterC] ospf 1 //配置OSPF路由协议
[RouterC-ospf-1] area 0.0.0.0
[RouterC-ospf-1-area-0.0.0.0] network 10.181.20.0 0.0.0.255
[RouterC-ospf-1-area-0.0.0.0] network 10.184.10.0 0.0.0.255
[RouterC-ospf-1-area-0.0.0.0] network 10.0.0.0 0.0.0.255
[RouterC-ospf-1-area-0.0.0.0] quit