1.基本概念
除了基于目的IP地址进行数据转发,还可以基于源IP地址、源MAC地址、目的MAC地址、源端口号,目的端口号、VLAN-ID等。路由策略基于路由信息进行过滤转发,策略路由(PBR)基于报文进行操作。
2.策略路由(PBR)实现负载分担
![图片[1]-6.5 策略路由PBR-大赛人网](https://www.dsrw.com/wp-content/uploads/2023/03/图片1-11.png)
1)本地策略路由
(1)基本配置(配置OSPF全网通)
[R1]ospf 1 router-id 1.1.1.1
[R1-ospf-1]area 0
[R1-ospf-1-area-0.0.0.0]network 13.1.1.0 0.255.255.255
[R1-ospf-1-area-0.0.0.0]network 1.1.1.1 0.0.0.0
[R1-ospf-1-area-0.0.0.0]network 125.1.1.0 0.255.255.255
[R2]ospf 1 router-id 2.2.2.2
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]network 125.0.0.0 0.255.255.255
[R2-ospf-1-area-0.0.0.0]network 23.0.0.0 0.255.255.255
[R2-ospf-1-area-0.0.0.0]network 2.2.2.2 0.0.0.0
[R3]ospf 1 router-id 3.3.3.3
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]network 3.3.3.3 0.0.0.0
[R3-ospf-1-area-0.0.0.0]network 6.6.6.6 0.0.0.0
[R3-ospf-1-area-0.0.0.0]network 7.7.7.7 0.0.0.0
[R3-ospf-1-area-0.0.0.0]network 13.0.0.0 0.255.255.255
[R3-ospf-1-area-0.0.0.0]network 23.0.0.0 0.255.255.255
[R3-ospf-1-area-0.0.0.0]network 34.0.0.0 0.255.255.255
[R4]ospf 1 router-id 4.4.4.4
[R4-ospf-1-area-0.0.0.0]network 34.0.0.0 0.255.255.255
[R4-ospf-1-area-0.0.0.0]network 192.168.1.0 0.0.0.255
[R4-ospf-1-area-0.0.0.0]network 192.168.2.0 0.0.0.255
[R4-ospf-1-area-0.0.0.0]network 4.4.4.4 0.0.0.0
[R5]ospf 1 router-id 5.5.5.5
[R5-ospf-1-area-0.0.0.0]network 192.168.3.0 0.0.0.255
[R5-ospf-1-area-0.0.0.0]network 125.0.0.0 0.255.255.255
(2)在R3测试6.6.6.6/32和7.7.7.7/32前往192.168.3.1/24路由
[R3-policy-based-route-dsrw-10]tracert -a 6.6.6.6 192.168.3.1
traceroute to 192.168.3.1(192.168.3.1), max hops: 30 ,packet length: 40,press CTRL_C to break
1 13.1.1.1 20 ms 30 ms 23.1.1.2 20 ms
2 125.1.1.5 60 ms 50 ms 50 ms
3 192.168.3.1 40 ms 40 ms 50 ms
[R3-policy-based-route-dsrw-10]tracert -a 7.7.7.7 192.168.3.1
traceroute to 192.168.3.1(192.168.3.1), max hops: 30 ,packet length: 40,press CTRL_C to break
1 23.1.1.2 30 ms 20 ms 20 ms
2 125.1.1.5 40 ms 40 ms 40 ms
3 192.168.3.1 50 ms 40 ms 40 ms
(3)配置本地策略路由(变更6.6.6.6/32和7.7.7.7/32前往192.168.3.1/24路由)
[R3]acl 3002
[R3-acl-adv-3002]rule permit ip source 6.6.6.6 0
[R3-acl-adv-3002]quit
[R3]acl 3003
[R3-acl-adv-3003]rule permit ip source 7.7.7.7 0
[R3]policy-based-route dsrw permit node 10
[R3-policy-based-route-dsrw-10]if-match acl 3002
[R3-policy-based-route-dsrw-10]apply ip-address next-hop 23.1.1.2
[R3]policy-based-route dsrw permit node 20
[R3-policy-based-route-dsrw-20]if-match acl 3003
[R3-policy-based-route-dsrw-20]apply ip-address next-hop 13.1.1.1
[R3-policy-based-route-dsrw-20]quit
[R3]ip local policy-based-route dsrw
(4)在R3测试6.6.6.6/32和7.7.7.7/32前往192.168.3.1/24路由
[R3]tracert -a 6.6.6.6 192.168.3.1
traceroute to 192.168.3.1(192.168.3.1), max hops: 30 ,packet length: 40,press CTRL_C to break
1 23.1.1.2 30 ms 20 ms 20 ms
2 125.1.1.5 60 ms 40 ms 50 ms
3 192.168.3.1 50 ms 60 ms 40 ms
[R3]tracert -a 7.7.7.7 192.168.3.1
traceroute to 192.168.3.1(192.168.3.1), max hops: 30 ,packet length: 40,press CTRL_C to break
1 13.1.1.1 20 ms 20 ms 20 ms
2 125.1.1.5 40 ms 40 ms 60 ms
3 192.168.3.1 50 ms 50 ms 40 ms
2)接口策略
(1)查看192.168.1.1/24和192.168.2.1/24前往192.168.3.1/24路由
PC1>tracert 192.168.3.1
traceroute to 192.168.3.1, 8 hops max
(ICMP), press Ctrl+C to stop
1 192.168.1.254 15 ms 16 ms 15 ms
2 34.1.1.3 16 ms 16 ms 15 ms
3 13.1.1.1 32 ms 31 ms 15 ms
4 125.1.1.5 47 ms 78 ms 63 ms
5 192.168.3.1 62 ms 63 ms 62 ms
PC2>tracert 192.168.3.1
traceroute to 192.168.3.1, 8 hops max
(ICMP), press Ctrl+C to stop
1 192.168.2.254 15 ms 16 ms 16 ms
2 34.1.1.3 15 ms 16 ms 15 ms
3 23.1.1.2 32 ms 31 ms 16 ms
4 125.1.1.5 62 ms 31 ms 47 ms
5 192.168.3.1 78 ms 63 ms 31 ms
(2)配置ACL,匹配源地址和目标地址
[R3]acl 3000
[R3-acl-adv-3000]rule permit ip source 192.168.1.0 0.0.0.255 destination 192.168.3.0 0.0.0.255
[R3-acl-adv-3000]quit
[R3]acl 3001
[R3-acl-adv-3001]rule permit ip source 192.168.1.0 0.0.0.255 destination 192.168.3.0 0.0.0.255
(3)配置流分类,调用ACL
[R3]traffic classifier c1
[R3-classifier-c1]if-match acl 3000
[R3-classifier-c1]quit
[R3]traffic classifier c2
[R3-classifier-c2]if-match acl 3001
(4)配置流行为,设置下一跳地址。
[R3]traffic behavior be1
[R3-behavior-be1]redirect ip-nexthop 23.1.1.2
[R3-behavior-be1]quit
[R3]traffic behavior be2
[R3-behavior-be2]redirect ip-nexthop 13.1.1.1
(5)定义流策略,将流分类与流动作绑定
[R3]traffic policy dsrw.com
[R3-trafficpolicy-dsrw.com]classifier c1 behavior be1
[R3-trafficpolicy-dsrw.com]classifier c2 behavior be2
(6)在R3的G0/0/0接口入方向应用流策略
[R3]interface GigabitEthernet 0/0/0
[R3-GigabitEthernet0/0/0]traffic-policy dsrw.com inbound
(7)跟踪192.168.1.0/24和192.168.2.0/24路由信息
PC1>tracert 192.168.3.1
traceroute to 192.168.3.1, 8 hops max
(ICMP), press Ctrl+C to stop
1 192.168.1.254 16 ms 16 ms <1 ms
2 34.1.1.3 31 ms <1 ms 15 ms
3 23.1.1.2 32 ms 31 ms 31 ms
4 125.1.1.5 63 ms 62 ms 78 ms
5 192.168.3.1 47 ms 63 ms 47 ms
PC2>tracert 192.168.3.1
traceroute to 192.168.3.1, 8 hops max
(ICMP), press Ctrl+C to stop
1 192.168.2.254 16 ms 15 ms <1 ms
2 34.1.1.3 16 ms 31 ms 16 ms
3 13.1.1.1 31 ms 31 ms 16 ms
4 125.1.1.5 63 ms 62 ms 63 ms
5 192.168.3.1 78 ms 62 ms 63 ms
8)断开R1的G0/0/0口,跟踪192.168.1.0/24和192.168.2.0/24路由信息,实现了路由备份。
[R1]interface GigabitEthernet 0/0/0
[R1-GigabitEthernet0/0/0]shutdown
PC1>tracert 192.168.3.1
traceroute to 192.168.3.1, 8 hops max
(ICMP), press Ctrl+C to stop
1 192.168.1.254 <1 ms 15 ms 16 ms
2 34.1.1.3 31 ms 16 ms 15 ms
3 23.1.1.2 32 ms 15 ms 32 ms
4 125.1.1.5 46 ms 79 ms 62 ms
5 192.168.3.1 31 ms 47 ms 63 ms
PC2>tracert 192.168.3.1
traceroute to 192.168.3.1, 8 hops max
(ICMP), press Ctrl+C to stop
1 192.168.2.254 16 ms <1 ms 15 ms
2 34.1.1.3 32 ms <1 ms 15 ms
3 13.1.1.1 16 ms 31 ms 31 ms
4 13.1.1.3 16 ms 16 ms 15 ms
5 23.1.1.2 32 ms 46 ms 16 ms
6 125.1.1.5 78 ms 63 ms 62 ms
7 192.168.3.1 63 ms 62 ms 63 ms
PC4>tracert 192.168.1.1
traceroute to 192.168.1.1, 8 hops max
(ICMP), press Ctrl+C to stop
1 192.168.3.254 31 ms <1 ms 16 ms
2 125.1.1.2 46 ms 47 ms 32 ms
3 23.1.1.3 46 ms 47 ms 47 ms
4 34.1.1.4 63 ms 62 ms 63 ms
5 192.168.1.1 47 ms 62 ms 63 ms
PC4>tracert 192.168.2.1
traceroute to 192.168.2.1, 8 hops max
(ICMP), press Ctrl+C to stop
1 192.168.3.254 16 ms 15 ms 16 ms
2 125.1.1.2 31 ms 47 ms 47 ms
3 23.1.1.3 47 ms 31 ms 47 ms
4 34.1.1.4 62 ms 63 ms 78 ms
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
请登录后查看评论内容