需求描述
不同网段访问互联网资源时,走不同的出口,即PC1走电信出口,PC2走移动出口。
客户在内网接口下应用策略路由后往往出现无法访问内网管理地址的现象,该举例给出解决办法。
拓扑图
基础配置
#sysname R1
#
#
interface GigabitEthernet0/0/0ip address 10.10.10.2 255.255.255.0
#
interface GigabitEthernet0/0/1ip address 30.30.30.1 255.255.255.0
#
#
ospf 1 import-route staticarea 0.0.0.0 network 30.30.30.1 0.0.0.0
#
ip route-static 172.16.0.0 255.255.0.0 10.10.10.1
#
#sysname R2
#
#
interface GigabitEthernet0/0/0ip address 20.20.20.2 255.255.255.0
#
interface GigabitEthernet0/0/1ip address 40.40.40.1 255.255.255.0
#
#
ospf 1 import-route staticarea 0.0.0.0 network 40.40.40.1 0.0.0.0
#
ip route-static 172.16.0.0 255.255.0.0 20.20.20.1
#
#sysname R3
#
#
interface GigabitEthernet0/0/0ip address 10.10.10.1 255.255.255.0
#
#
interface GigabitEthernet0/0/1ip address 20.20.20.1 255.255.255.0
#
#
interface GigabitEthernet0/0/2.1dot1q termination vid 10ip address 172.16.1.1 255.255.255.0 arp broadcast enable
#
interface GigabitEthernet0/0/2.2dot1q termination vid 20ip address 172.16.2.1 255.255.255.0 arp broadcast enable
#
#
ip route-static 0.0.0.0 0.0.0.0 10.10.10.2
ip route-static 0.0.0.0 0.0.0.0 20.20.20.2
#
在R4上创建一个lo 100接口来模拟互联网:
#sysname R4
#
#
interface GigabitEthernet0/0/0ip address 30.30.30.2 255.255.255.0
#
interface GigabitEthernet0/0/1ip address 40.40.40.2 255.255.255.0
#
#
interface LoopBack100ip address 100.100.100.100 255.255.255.0
#
ospf 1 area 0.0.0.0 network 30.30.30.2 0.0.0.0 network 40.40.40.2 0.0.0.0 network 100.100.100.100 0.0.0.0
#
现在我们未使用策略路由前先测试一下PC1、PC2访问互联网时,各种路径走向是如何的?
从上述结果来看,可知,
PC1访问互联网资源100.100.100.100时,是走R2(移动)的;
PC2访问互联网资源100.100.100.100时,是走R1(电信)的;
我们的需求是,希望PC1走电信出口(R1),PC2走移动(R2)出口。
关键配置
#
acl number 3000 //第一个网段地址rule 5 permit ip source 172.16.1.0 0.0.0.255
acl number 3001 //第二个网段地址rule 5 permit ip source 172.16.2.0 0.0.0.255
acl number 3002 //允许两个网段地址访问网关rule 5 permit ip source 172.16.1.0 0.0.0.255 destination 172.16.1.1 0 rule 10 permit ip source 172.16.2.0 0.0.0.255 destination 172.16.2.1 0 # //流分类 ,匹配对应的ACL
traffic classifier c2if-match acl 3002
traffic classifier c0if-match acl 3000
traffic classifier c1if-match acl 3001
## //流行为,配置响应的动作
traffic behavior b0redirect ip-nexthop 10.10.10.2
traffic behavior b1redirect ip-nexthop 20.20.20.2
traffic behavior b2
permit# //流策略,把分类对应行为关联起来
traffic policy p1classifier c0 behavior b0classifier c1 behavior b1classifier c2 behavior b2
#
# //内网接口入方向调研 流策略
interface GigabitEthernet0/0/2.1traffic-policy p1 inbound
#
interface GigabitEthernet0/0/2.2traffic-policy p1 inbound
结果验证
从上述结果来看,可知,
PC1访问互联网资源100.100.100.100时,已经是走R1(电信)的;
PC2访问互联网资源100.100.100.100时,已经是走R2(移动)的;