【华为】用策略路由解决双出口运营商问题

时间:2024-09-29 14:12:27

需求描述

不同网段访问互联网资源时,走不同的出口,即PC1走电信出口,PC2走移动出口。

客户在内网接口下应用策略路由后往往出现无法访问内网管理地址的现象,该举例给出解决办法。

拓扑图

基础配置

#
 sysname R1
#
#
interface GigabitEthernet0/0/0
 ip address 10.10.10.2 255.255.255.0 
#
interface GigabitEthernet0/0/1
 ip address 30.30.30.1 255.255.255.0 
#
#
ospf 1 
 import-route static
 area 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/0
 ip address 20.20.20.2 255.255.255.0 
#
interface GigabitEthernet0/0/1
 ip address 40.40.40.1 255.255.255.0 
#
#
ospf 1 
 import-route static
 area 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/0
 ip address 10.10.10.1 255.255.255.0 
#
#
interface GigabitEthernet0/0/1
 ip address 20.20.20.1 255.255.255.0 
#
#
interface GigabitEthernet0/0/2.1
 dot1q termination vid 10
 ip address 172.16.1.1 255.255.255.0 
 arp broadcast enable
#
interface GigabitEthernet0/0/2.2
 dot1q termination vid 20
 ip 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/0
 ip address 30.30.30.2 255.255.255.0 
#
interface GigabitEthernet0/0/1
 ip address 40.40.40.2 255.255.255.0 
#
#
interface LoopBack100
 ip 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 c2
 if-match acl 3002
traffic classifier c0
 if-match acl 3000
traffic classifier c1
 if-match acl 3001
#

# //流行为,配置响应的动作
traffic behavior b0
 redirect ip-nexthop 10.10.10.2
traffic behavior b1
 redirect ip-nexthop 20.20.20.2
traffic behavior b2
permit

# //流策略,把分类对应行为关联起来
traffic policy p1
 classifier c0 behavior b0
 classifier c1 behavior b1
 classifier c2 behavior b2
#
# //内网接口入方向调研 流策略
interface GigabitEthernet0/0/2.1
 traffic-policy p1 inbound
#
interface GigabitEthernet0/0/2.2
 traffic-policy p1 inbound

结果验证

从上述结果来看,可知,

PC1访问互联网资源100.100.100.100时,已经是走R1(电信)的;

PC2访问互联网资源100.100.100.100时,已经是走R2(移动)的;