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

需求描述

不同网段访问互联网资源时,走不同的出口,即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(移动)的;

相关推荐
woshihuanglaoshi3 小时前
鸿蒙技术进阶全景高级成长体系:从初中级到架构师的技能树/学习路径/项目实战/认证体系系统性方法论
学习·华为·harmonyos
轻口味4 小时前
端侧 AI 赋能鸿蒙版 Obsidian:轻规划基于 HarmonyOS 7.0 图像超分特性的体验突破与开发实战
人工智能·华为·harmonyos·鸿蒙
OH_TPC5 小时前
【鸿蒙优选三方库】@ohos/lottie:让 After Effects 动画在 HarmonyOS 上稳定播放
华为·harmonyos·鸿蒙
2501_919749038 小时前
华为鸿蒙训练口才APP—小羊口才
华为·harmonyos·鸿蒙
大锅盖18 小时前
HarmonyOS 摄像头焦点管理的完整工程实现
华为·harmonyos
woshihuanglaoshi10 小时前
鸿蒙老旧项目升级改造高级:API废弃迁移/ArkTS语法升级/架构重构策略/增量迁移/风险管控方案
学习·华为·重构·架构·harmonyos·鸿蒙
星空真迷人1 天前
嵌入式鸿蒙并非精简版,核心究竟是什么?
stm32·单片机·嵌入式硬件·物联网·华为·harmonyos·iot
OH_TPC1 天前
【鸿蒙优选三方库】@ohos/ijkplayer:在鸿蒙上像 B 站一样流畅播视频
华为·音视频·harmonyos·鸿蒙
2501_919749031 天前
华为鸿蒙经期记录APP—小羊月经
华为·harmonyos·鸿蒙
腾科IT教育2 天前
HarmonyOS开发|ArkTS UI颜色API通用规则
ui·华为·harmonyos·harmonyos开发·鸿蒙应用开发工程师