HCIP学习18 静态路由跨公网互通实验
2026/4/17 23:19:14 网站建设 项目流程

实验拓扑

实验设备

设备类型设备名称型号数量用途
路由器AR1AR22201左侧私网出口路由器
路由器ISPAR22201公网核心路由器
路由器AR3AR22201右侧私网出口路由器

拓扑结构

拓扑链路与接口连接表

本端设备本端接口对端设备对端接口链路网段所属网络
AR1GE0/0/0ISPGE0/0/012.0.0.0/24公网
ISPGE0/0/1AR3GE0/0/023.0.0.0/24公网
AR1LoopBack0--192.168.1.0/24左侧私网
AR3LoopBack0--192.168.2.0/24右侧私网

IP 地址规划表

设备接口IP 地址子网掩码备注
AR1GE0/0/012.0.0.1255.255.255.0连接 ISP
AR1LoopBack0192.168.1.1255.255.255.0模拟左侧私网网段
ISPGE0/0/012.0.0.2255.255.255.0连接 AR1
ISPGE0/0/123.0.0.1255.255.255.0连接 AR3
AR3GE0/0/023.0.0.2255.255.255.0连接 ISP
AR3LoopBack0192.168.2.1255.255.255.0模拟右侧私网网段

实验需求

  1. 基础配置:完成所有路由器的设备命名、接口 IP 地址、环回接口配置

  2. 静态路由配置

    • 在 AR1 上配置静态路由,指向右侧私网 192.168.2.0/24

    • 在 AR3 上配置静态路由,指向左侧私网 192.168.1.0/24

    • 在 ISP 上配置双向静态路由,分别指向两个私网网段

  3. 默认路由配置

    • 在 AR1 上配置默认路由,下一跳指向 ISP(12.0.0.2)

    • 在 AR3 上配置默认路由,下一跳指向 ISP(23.0.0.1)

  4. 实验验证

    • 验证所有路由器的路由表

    • 验证左侧私网与右侧私网的互通性

    • 验证私网与公网网段的互通性

实验原理与思路

技术原理

(1)静态路由

静态路由是由管理员手动配置的路由条目,优先级最高(管理距离 60),适用于小型、拓扑固定的网络。

  • 优点:配置简单、开销小、安全性高

  • 缺点:不能自动适应拓扑变化,需要手动更新

(2)默认路由

默认路由是一种特殊的静态路由,当路由表中没有匹配的条目时,使用默认路由转发数据包。通常用于连接公网的出口路由器,下一跳指向公网网关。

  • 格式:ip route-static 0.0.0.0 0.0.0.0 下一跳IP

(3)私网跨公网互通原理

两个私网通过公网互通时,需要在公网路由器上配置指向两个私网的静态路由,同时在私网出口路由器上配置默认路由指向公网,实现双向数据包转发。

需求拆解

需求技术实现命令
AR1 访问右侧私网静态路由ip route-static 192.168.2.0 255.255.255.0 12.0.0.2
AR3 访问左侧私网静态路由ip route-static 192.168.1.0 255.255.255.0 23.0.0.1
ISP 访问左侧私网静态路由ip route-static 192.168.1.0 255.255.255.0 12.0.0.1
ISP 访问右侧私网静态路由ip route-static 192.168.2.0 255.255.255.0 23.0.0.2
AR1 访问公网默认路由ip route-static 0.0.0.0 0.0.0.0 12.0.0.2
AR3 访问公网默认路由ip route-static 0.0.0.0 0.0.0.0 23.0.0.1

设计说明

  1. 双向静态路由:必须在所有路由器上配置双向静态路由,否则会出现单向通的问题

  2. 默认路由优化:私网出口路由器使用默认路由代替多条静态路由,简化配置

  3. 环回接口模拟:使用环回接口模拟私网网段,不需要额外的 PC 设备

实验步骤与配置

实验准备工作

  1. 所有设备恢复出厂配置

    <Huawei> reset saved-configuration Warning: The action will delete the saved configuration in the device. Continue? [Y/N]: y <Huawei> reboot Warning: All the configuration will be saved to the next startup. Continue? [Y/N]: n System will reboot! Continue? [Y/N]: y
  2. 等待所有设备启动完成(约 2-3 分钟)。

基础配置

(1)AR1 基础配置
<Huawei> system-view [Huawei] sysname AR1 # 配置公网接口 [AR1] interface GigabitEthernet 0/0/0 [AR1-GigabitEthernet0/0/0] ip address 12.0.0.1 255.255.255.0 [AR1-GigabitEthernet0/0/0] undo shutdown [AR1-GigabitEthernet0/0/0] quit # 配置环回接口模拟左侧私网 [AR1] interface LoopBack 0 [AR1-LoopBack0] ip address 192.168.1.1 255.255.255.0 [AR1-LoopBack0] undo shutdown [AR1-LoopBack0] quit # 保存配置 [AR1] save [AR1] quit
(2)ISP 基础配置
<Huawei> system-view [Huawei] sysname ISP # 配置连接AR1的接口 [ISP] interface GigabitEthernet 0/0/0 [ISP-GigabitEthernet0/0/0] ip address 12.0.0.2 255.255.255.0 [ISP-GigabitEthernet0/0/0] undo shutdown [ISP-GigabitEthernet0/0/0] quit # 配置连接AR3的接口 [ISP] interface GigabitEthernet 0/0/1 [ISP-GigabitEthernet0/0/1] ip address 23.0.0.1 255.255.255.0 [ISP-GigabitEthernet0/0/1] undo shutdown [ISP-GigabitEthernet0/0/1] quit # 保存配置 [ISP] save [ISP] quit
(3)AR3 基础配置
<Huawei> system-view [Huawei] sysname AR3 # 配置公网接口 [AR3] interface GigabitEthernet 0/0/0 [AR3-GigabitEthernet0/0/0] ip address 23.0.0.2 255.255.255.0 [AR3-GigabitEthernet0/0/0] undo shutdown [AR3-GigabitEthernet0/0/0] quit # 配置环回接口模拟右侧私网 [AR3] interface LoopBack 0 [AR3-LoopBack0] ip address 192.168.2.1 255.255.255.0 [AR3-LoopBack0] undo shutdown [AR3-LoopBack0] quit # 保存配置 [AR3] save [AR3] quit

静态路由配置

(1)AR1 静态路由配置
[AR1] ip route-static 192.168.2.0 255.255.255.0 12.0.0.2 # 指向右侧私网 [AR1] ip route-static 0.0.0.0 0.0.0.0 12.0.0.2 # 默认路由指向ISP
(2)ISP 静态路由配置
[ISP] ip route-static 192.168.1.0 255.255.255.0 12.0.0.1 # 指向左侧私网 [ISP] ip route-static 192.168.2.0 255.255.255.0 23.0.0.2 # 指向右侧私网
(3)AR3 静态路由配置
[AR3] ip route-static 192.168.1.0 255.255.255.0 23.0.0.1 # 指向左侧私网 [AR3] ip route-static 0.0.0.0 0.0.0.0 23.0.0.1 # 默认路由指向ISP

保存所有配置

所有路由器配置完成后,执行以下命令保存配置:

<Router> save The current configuration will be written to the device. Are you sure to continue? [Y/N]: y Now saving the current configuration to the slot 0. Save the configuration successfully.

实验结果验证

AR1 路由表验证

[AR1] display ip routing-table Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Public routing table : Destinations : 5 Routes : 5 Destination/Mask Proto Pre Cost Flags NextHop Interface 0.0.0.0/0 Static 60 0 D 12.0.0.2 GigabitEthernet0/0/0 12.0.0.0/24 Direct 0 0 D 12.0.0.1 GigabitEthernet0/0/0 12.0.0.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0 192.168.1.0/24 Direct 0 0 D 192.168.1.1 LoopBack0 192.168.1.1/32 Direct 0 0 D 127.0.0.1 LoopBack0 192.168.2.0/24 Static 60 0 D 12.0.0.2 GigabitEthernet0/0/0

验证结论:AR1 的路由表包含默认路由和指向右侧私网的静态路由,配置正确。

ISP 路由表验证

[ISP] display ip routing-table Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Public routing table : Destinations : 6 Routes : 6 Destination/Mask Proto Pre Cost Flags NextHop Interface 12.0.0.0/24 Direct 0 0 D 12.0.0.2 GigabitEthernet0/0/0 12.0.0.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0 23.0.0.0/24 Direct 0 0 D 23.0.0.1 GigabitEthernet0/0/1 23.0.0.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1 192.168.1.0/24 Static 60 0 D 12.0.0.1 GigabitEthernet0/0/0 192.168.2.0/24 Static 60 0 D 23.0.0.2 GigabitEthernet0/0/0

验证结论:ISP 的路由表包含指向两个私网的静态路由,配置正确。

AR3 路由表验证

[AR3] display ip routing-table Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Public routing table : Destinations : 5 Routes : 5 Destination/Mask Proto Pre Cost Flags NextHop Interface 0.0.0.0/0 Static 60 0 D 23.0.0.1 GigabitEthernet0/0/0 23.0.0.0/24 Direct 0 0 D 23.0.0.2 GigabitEthernet0/0/0 23.0.0.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0 192.168.1.0/24 Static 60 0 D 23.0.0.1 GigabitEthernet0/0/0 192.168.2.0/24 Direct 0 0 D 192.168.2.1 LoopBack0 192.168.2.1/32 Direct 0 0 D 127.0.0.1 LoopBack0

验证结论:AR3 的路由表包含默认路由和指向左侧私网的静态路由,配置正确。

全网连通性验证

(1)左侧私网访问右侧私网
[AR1] ping 192.168.2.1 PING 192.168.2.1: 56 data bytes, press CTRL_C to break Reply from 192.168.2.1: bytes=56 Sequence=1 ttl=254 time=10 ms Reply from 192.168.2.1: bytes=56 Sequence=2 ttl=254 time=10 ms Reply from 192.168.2.1: bytes=56 Sequence=3 ttl=254 time=10 ms Reply from 192.168.2.1: bytes=56 Sequence=4 ttl=254 time=10 ms Reply from 192.168.2.1: bytes=56 Sequence=5 ttl=254 time=10 ms --- 192.168.2.1 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 10/10/10 ms
(2)右侧私网访问左侧私网
[AR3] ping 192.168.1.1 PING 192.168.1.1: 56 data bytes, press CTRL_C to break Reply from 192.168.1.1: bytes=56 Sequence=1 ttl=254 time=10 ms Reply from 192.168.1.1: bytes=56 Sequence=2 ttl=254 time=10 ms Reply from 192.168.1.1: bytes=56 Sequence=3 ttl=254 time=10 ms Reply from 192.168.1.1: bytes=56 Sequence=4 ttl=254 time=10 ms Reply from 192.168.1.1: bytes=56 Sequence=5 ttl=254 time=10 ms --- 192.168.1.1 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 10/10/10 ms
(3)私网访问公网网段
[AR1] ping 23.0.0.2 PING 23.0.0.2: 56 data bytes, press CTRL_C to break Reply from 23.0.0.2: bytes=56 Sequence=1 ttl=254 time=10 ms Reply from 23.0.0.2: bytes=56 Sequence=2 ttl=254 time=10 ms Reply from 23.0.0.2: bytes=56 Sequence=3 ttl=254 time=10 ms Reply from 23.0.0.2: bytes=56 Sequence=4 ttl=254 time=10 ms Reply from 23.0.0.2: bytes=56 Sequence=5 ttl=254 time=10 ms --- 23.0.0.2 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 10/10/10 ms

验证结论:全网连通性正常,两个私网可以通过公网互相访问。

实验重难点分析

难点 1:双向静态路由配置

  • 问题原因:静态路由是单向的,只配置一个方向的路由会导致数据包能发出去但回不来,出现单向通的问题

  • 解决方案:必须在所有路由器上配置双向静态路由,确保数据包能够往返

  • 本实验验证:ISP 必须同时配置指向 AR1 和 AR3 的静态路由,否则两个私网无法互通

难点 2:默认路由的使用

  • 问题原因:如果私网出口路由器需要访问多个公网网段,配置多条静态路由会非常繁琐

  • 解决方案:使用默认路由代替多条静态路由,简化配置

  • 本实验验证:AR1 和 AR3 使用默认路由指向 ISP,不需要配置指向所有公网网段的静态路由

难点 3:下一跳地址的选择

  • 问题原因:静态路由的下一跳必须是直连网段的 IP 地址,否则路由无法生效

  • 解决方案:下一跳地址必须是对端设备的直连接口 IP 地址

  • 本实验验证:AR1 的下一跳是 ISP 的 GE0/0/0 接口 IP(12.0.0.2),而不是 ISP 的其他接口 IP

实验总结

知识点总结

  1. 静态路由:手动配置的路由条目,优先级最高,适用于小型网络

  2. 默认路由:特殊的静态路由,用于匹配所有未明确指定的路由

  3. 私网跨公网互通:需要在公网路由器上配置指向两个私网的静态路由

  4. 双向路由:静态路由是单向的,必须配置双向路由才能实现互通

  5. 下一跳地址:静态路由的下一跳必须是直连网段的 IP 地址

常见错误与排障

错误现象原因解决方案
单向通(能 ping 出去但回不来)只配置了一个方向的静态路由配置双向静态路由
静态路由不生效下一跳地址错误,或接口未 up检查下一跳地址,确保接口已启用
无法访问公网未配置默认路由,或默认路由下一跳错误配置正确的默认路由
路由表中没有静态路由静态路由配置错误,或子网掩码错误检查静态路由命令,修正子网掩码

附录:完整配置文件

AR1配置

# sysname AR1 # interface GigabitEthernet0/0/0 ip address 12.0.0.1 255.255.255.0 # interface LoopBack0 ip address 192.168.1.1 255.255.255.0 # ip route-static 0.0.0.0 0.0.0.0 12.0.0.2 ip route-static 192.168.2.0 255.255.255.0 12.0.0.2 # return

ISP 配置

# sysname ISP # interface GigabitEthernet0/0/0 ip address 12.0.0.2 255.255.255.0 # interface GigabitEthernet0/0/1 ip address 23.0.0.1 255.255.255.0 # ip route-static 192.168.1.0 255.255.255.0 12.0.0.1 ip route-static 192.168.2.0 255.255.255.0 23.0.0.2 # return

AR3 配置

# sysname AR3 # interface GigabitEthernet0/0/0 ip address 23.0.0.2 255.255.255.0 # interface LoopBack0 ip address 192.168.2.1 255.255.255.0 # ip route-static 0.0.0.0 0.0.0.0 23.0.0.1 ip route-static 192.168.1.0 255.255.255.0 23.0.0.1 # return

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询