功能介绍:

策略路由(PBR:Policy-Based Routing)提供了一种比基于目的地址进行路由转发更加灵活的数据包路由转发机制。策略路由可以根据 IP/IPv6 报文源地址、目的地址、端口、报文长度等内容灵活地进行路由选择。

应用场景:

企业有两个出口线路,需要实现内网部分电脑固定从某一个出口线路上网,另外一部分电脑固定从另外一个出口线路上网,此时可以在路由器上启用策略路由功能。

一、组网需求

如下网络拓扑,R1到外网有2个出口 R3和R4,需要实现内网 172.16.1.0/24 访问外网走R3出口,内网 172.16.2.0/24 访问外网走R4出口。

二、组网拓扑

三、配置要点

1、基本ip地址配置

2、基本的ip路由配置,使全网可达

3、在R1上配置ACL,把内网的流量匹配出来

4、配置策略路由

5、应用策略路由

四、配置步骤

1、基本ip地址配置

Ruijie(config)#hostname R1

R1(config)#interface gigabitEthernet 0/0

R1(config-GigabitEthernet 0/0)#ip address 192.168.1.1 255.255.255.0

R1(config-GigabitEthernet 0/0)#exit

R1(config)#interface gigabitEthernet 0/1

R1(config-GigabitEthernet 0/1)#ip address 192.168.2.1 255.255.255.0

R1(config-GigabitEthernet 0/1)#exit

R1(config)#interface gigabitEthernet 0/2

R1(config-GigabitEthernet 0/2)#ip address 192.168.3.1 255.255.255.0

R1(config-GigabitEthernet 0/2)#exit

Ruijie(config)#hostname R2

R2(config)#interface gigabitEthernet 0/0

R2(config-GigabitEthernet 0/0)#ip address 192.168.1.2 255.255.255.0

R2(config-GigabitEthernet 0/0)#exit

R2(config)#interface gigabitEthernet 0/1

R2(config-GigabitEthernet 0/1)#ip address 172.16.1.1 255.255.255.0

R2(config-GigabitEthernet 0/1)#exit

R2(config)#interface gigabitEthernet 0/2

R2(config-GigabitEthernet 0/2)#ip address 172.16.2.1 255.255.255.0

R2(config-GigabitEthernet 0/2)#exit

Ruijie(config)#hostname R3

R3(config)#interface fastEthernet 0/0

R3(config-if-FastEthernet 0/0)#ip address 192.168.2.2 255.255.255.0

R3(config-if-FastEthernet 0/0)#exit

Ruijie(config)#hostname R4

R4(config)#interface fastEthernet 0/0

R4(config-if-FastEthernet 0/0)#ip address 192.168.3.2 255.255.255.0

R4(config-if-FastEthernet 0/0)#exit

2、基本的ip路由配置,使全网可达

R1(config)#ip route 172.16.0.0 255.255.0.0 192.168.1.2

R2(config)#ip route 100.1.1.0 255.255.255.0 192.168.1.1

R3(config)#ip route 172.16.0.0 255.255.0.0 192.168.2.1

R4(config)#ip route 172.16.0.0 255.255.0.0 192.168.3.1

3、在R1上配置ACL,把内网的流量匹配出来

R1(config)#ip access-list standard 10 //配置ACL 10,匹配内网172.16.1.0/24

R1(config-std-nacl)#10 permit 172.16.1.0 0.0.0.255

R1(config-std-nacl)#exit

R1(config)#ip access-list standard 20 //配置ACL 20,匹配内网172.16.2.0/24

R1(config-std-nacl)#10 permit 172.16.2.0 0.0.0.255

R1(config-std-nacl)#exit

4、配置策略路由

R1(config)#route-map ruijie permit 10 //配置route-map ruijie

R1(config-route-map)#match ip address 10 //匹配内网acl 10的流量

R1(config-route-map)#set ip next-hop 192.168.2.2 //强制设置ip报文的下一跳为 192.168.2.2,走R3出口

R1(config-route-map)#exit

R1(config)#route-map ruijie permit 20

R1(config-route-map)#match ip address 20

R1(config-route-map)#set ip next-hop 192.168.3.2

R1(config-route-map)#exit

注意:

1)route-map的匹配顺序为从上往下匹配,当流量匹配到策略后,就按匹配的策略转发数据,不会继续往下匹配。

2)route-map 最后有有一条deny所有的语句,对于没有匹配到策略路由的流量,不会把内网的流量丢弃,而是做正常的ip 路由转发。

3)set ip next-hop 可以设置下一跳ip地址,也可以设置数据包的出接口,建议设置为下一跳的ip地址。

5、应用策略路由

R1(config)#interface gigabitEthernet 0/0

R1(config-GigabitEthernet 0/0)#ip policy route-map ruijie //应用策略路由

R1(config-GigabitEthernet 0/0)#exit

注意:

策略路由一定要应用到数据包的in方向接口,不能应用到数据包的out方向接口。因为策略路由实际上是在数据包进路由器的时候,强制设置数据包的下一跳,out方向接口,路由器已经对数据包做完ip路由,把数据包从接口转发出去了,故out方向策略路由不生效。

五、配置验证

在R2上带源地址到外网100.1.1.0/24做路由跟踪,若172.16.1.0/24访问外网走R3,172.16.2.0/24访问外网走R4,则策略路由配置正确。

R2#traceroute 100.1.1.1 source 172.16.1.1

< press Ctrl+C to break >

Tracing the route to 100.1.1.1

1 192.168.1.1 0 msec 0 msec 0 msec

2 192.168.2.2 10 msec 0 msec 10 msec //172.16.1.0/24 访问外网走R3出口

其它路径省略

R2#traceroute 100.1.1.1 source 172.16.2.1

< press Ctrl+C to break >

Tracing the route to 100.1.1.1

1 192.168.1.1 0 msec 0 msec 0 msec

2 192.168.3.2 10 msec 0 msec 10 msec //172.16.2.0/24 访问外网走R4出口

其它路径省略

Copyright © 2088 世界杯乒乓球赛_2014世界杯十佳球 - mz286.com All Rights Reserved.
友情链接