一、概述
GRE(Generic Routing Encapsulation)是一种隧道协议,能够在 IP 网络中封装多种协议的数据包,常用于实现 VPN 功能。本文将详细介绍如何在华为 eNSP 模拟器中通过 GRE 隧道实现 VPN 功能。
二、实验拓扑
1、拓扑结构
PC1 (192.168.1.0/24) – [Router1] – (Internet) – [Router2] – PC2 (192.168.2.0/24)
2、设备列表
Router1:作为 GRE 隧道的起点,连接 PC1。
Router2:作为 GRE 隧道的终点,连接 PC2。
PC1:模拟内网主机,IP 地址为 192.168.1.2/24,网关为 192.168.1.1。
PC2:模拟内网主机,IP 地址为 192.168.2.2/24,网关为 192.168.2.1。
三、配置步骤
3.1 配置Router1
3.1.1 配置接口 IP 地址
1、配置连接 PC1 的接口:
interface Ethernet0/0/0
ip address 192.168.1.1 255.255.255.0
2、配置连接 Internet 的接口:
interface Ethernet0/0/1
ip address 10.0.0.1 255.255.255.0
3.1.2 配置 GRE 隧道
创建 Tunnel 接口:
interface Tunnel0/0/0
ip address 172.16.1.1 255.255.255.0
tunnel-protocol gre
source 10.0.0.1
destination 10.0.0.2
3.1.3 配置静态路由
1、配置将 PC2 的流量通过隧道转发:
ip route-static 192.168.2.0 255.255.255.0 Tunnel0/0/0
2、配置默认路由指向 Internet:
ip route-static 0.0.0.0 0.0.0.0 10.0.0.2
3.2 配置 Router2
3.2.1 配置接口 IP 地址
1、配置连接 PC2 的接口:
interface Ethernet0/0/0
ip address 192.168.2.1 255.255.255.0
2、配置连接 Internet 的接口:
interface Ethernet0/0/1
ip address 10.0.0.2 255.255.255.0
3.2.2 配置 GRE 隧道
1、创建 Tunnel 接口:
interface Tunnel0/0/0
ip address 172.16.1.2 255.255.255.0
tunnel-protocol gre
source 10.0.0.2
destination 10.0.0.1
3.2.3 配置静态路由
1、配置将 PC1 的流量通过隧道转发:
ip route-static 192.168.1.0 255.255.255.0 Tunnel0/0/0
2、配置默认路由指向 Internet:
ip route-static 0.0.0.0 0.0.0.0 10.0.0.1
3.3 配置 PC1 和 PC2
3.3.1 配置 PC1
3.3.2 配置 PC2
四、验证配置
4.1 检查隧道状态
在 Router1 和 Router2 上执行以下命令,检查 Tunnel 接口状态:
display interface Tunnel0/0/0
确保 Tunnel 接口状态为 UP。
4.2 测试连通性
在 PC1 上 Ping PC2 的 IP 地址(192.168.2.2):
ping 192.168.2.2
如果配置正确,PC1 可以成功 Ping 通 PC2。
五、总结
通过 GRE 隧道,我们成功在 eNSP 中实现了 VPN 功能,使得两个远程内网(192.168.1.0/24 和 192.168.2.0/24)能够安全通信。GRE 隧道通过封装原始数据包,在公共网络中建立了一条虚拟的私有通道,适用于需要简单、高效 VPN 解决方案的场景。
注:在eNSP中对路由器进行配置时,首先输入system-view进入管理员模式,否则无权限对设备进行配置。
六、举个例子
除了在工作中,我们可以利用 VPN 进行远程办公(访问内网),在游戏领域,VPN 同样发挥着重要作用。以 Steam 等游戏平台为例,许多游戏加速器本质上也是基于 VPN 技术实现的。它们通过将玩家的网络流量路由到更近的服务器节点,帮助玩家减少网络延迟、降低丢包率,从而显著提升游戏体验。