EVE-NG裸机部署SSL VPN,实现外网连接裸机内网
本帖最后由 CingSyuan 于 2025-11-12 11:47 编辑<p><strong>这篇内容,晦涩难懂,没有Linux与网络基础的,直接绕路吧<br />
实在想研究的可以多读几遍,自行领悟奥秘,或者问问AI</strong></p>
<h1>环境</h1>
<p>这是我的部署环境,我是打算通过 公网访问 EVE-NG 的,但是对外端口有限<br />
我是在我朋友的 PVE服务器 上部署的,理论上你可以在任何 x86 Ubuntu 22 LTS 平台部署<br />
比如云服务器、物理机、ESXI、PVE、VMware vSphere、超融合平台、Open Stack等</p>
<blockquote>
<p>Proxmox VE 9.0.6<br />
Intel(R) Xeon(R) Platinum 8259CL CPU<br />
Linux 6.14 11-1-pve<br />
对外端口范围:32769~32897(必须)、以及Web(必须)、SSH/FTP等端口(建议)</p>
</blockquote>
<hr />
<p>我打算使用 SoftEtherVPN 做一个 SSL VPN 打通外网到裸机内网<br />
这样就能访问防火墙等设备的web管理页面了<br />
如果你的裸机没有公网,套一个内网穿透也是可以的</p>
<hr />
<p>需要下载 SoftEtherVPN<br />
https://github.com/SoftEtherVPN/SoftEtherVPN/releases</p>
<hr />
<h1>编译/安装</h1>
<p>安装编译依赖</p>
<pre><code class="language-shell">apt update
apt install -y sudo wget curl vim libsodium-dev pkg-config cmake build-essential libssl-dev libreadline-dev zlib1g-dev
# 验证依赖都是安装完毕,出版本号就是OK了
root@pveng:~# pkg-config --modversion libsodium
1.0.18
</code></pre>
<hr />
<p>下载 <a href="https://github.com/SoftEtherVPN/SoftEtherVPN/releases">SoftEtherVPN</a>,当前版本是5.2.5188,下载 tar.xz 结尾的<br />
自己通过FTP传到 <code>/usr/local</code> 下</p>
<pre><code class="language-shell">cd /usr/local
tar -xJf SoftEtherVPN-5.2.5188.tar.xz
cd SoftEtherVPN-5.2.5188/
mkdir build
cd build
</code></pre>
<hr />
<p>cmake</p>
<pre><code class="language-shell">root@pveng:/usr/local/SoftEtherVPN-5.2.5188/build# sudo cmake ..
-- Build date: 04/11/2025
-- Build time: 08:38:14
-- Checking for one of the modules 'libsodium'
-- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found version "3.0.2")
-- Alg enablement unchanged
-- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found suitable version "3.0.2", minimum required is "1.1.1")
-- Creating Release build
-- Build will store public keys in PKCS#8 structures
-- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found suitable version "3.0.2", minimum required is "3.0")
-- liboqs found: Include dir at $<BUILD_INTERFACE:/usr/local/SoftEtherVPN-5.2.5188/src/Mayaqua/3rdparty/liboqs/src>;$<INSTALL_INTERFACE:include> (STATIC_LIBRARY)
fatal: not a git repository (or any of the parent directories): .git
-- Building commitin /usr/local/SoftEtherVPN-5.2.5188
-- Configuring done
-- Generating done
-- Build files have been written to: /usr/local/SoftEtherVPN-5.2.5188/build
</code></pre>
<hr />
<p>make</p>
<pre><code class="language-shell">root@pveng:/usr/local/SoftEtherVPN-5.2.5188/build# sudo make -j$(nproc)
Linking C shared library ../../libcedar.so
Built target cedar
Building C object src/vpnclient/CMakeFiles/vpnclient.dir/vpncsvc.c.o
Building C object src/vpncmd/CMakeFiles/vpncmd.dir/vpncmd.c.o
Building C object src/vpntest/CMakeFiles/vpntest.dir/vpntest.c.o
Building C object src/vpnserver/CMakeFiles/vpnserver.dir/vpnserver.c.o
Building C object src/vpnbridge/CMakeFiles/vpnbridge.dir/vpnbridge.c.o
Linking C executable ../../vpnclient
Linking C executable ../../vpncmd
Linking C executable ../../vpnserver
Linking C executable ../../vpnbridge
Linking C executable ../../vpntest
Built target vpnclient
Built target vpncmd
Built target vpnserver
Built target vpnbridge
Built target vpntest
</code></pre>
<hr />
<p>make install</p>
<pre><code class="language-shell">root@pveng:/usr/local/SoftEtherVPN-5.2.5188/build# sudo make install
----------------------------------------------------------------------------------------------------------------------------
Build completed successfully.
Execute 'vpnserver start' to run the SoftEther VPN Server background service.
Execute 'vpnbridge start' to run the SoftEther VPN Bridge background service.
Execute 'vpnclient start' to run the SoftEther VPN Client background service.
Execute 'vpncmd' to run the SoftEther VPN Command-Line Utility to configure VPN Server, VPN Bridge or VPN Client.
----------------------------------------------------------------------------------------------------------------------------
</code></pre>
<hr />
<h1>配置 SoftEtherVPN</h1>
<h2>认识架构</h2>
<pre><code>┌──────────────────────────────┐
│ SoftEther VPN Server │
│├── 管理密码 (ServerPassword)│ ← 整个服务器的root权限
│├── 监听端口 (Listener) │ ← 如 443, 8888 等
│├── 虚拟 Hub (Virtual Hub)│ ← 虚拟交换机
││ ├── Hub 管理密码 │
││ ├── 用户 (User) │ ← VPN登录账号
││ ├── SecureNAT 模块 │ ← 内置NAT/DHCP网关
││ └── Bridge/Local Bridg│ ← 与物理网卡或虚拟网桥连接
│└── 日志/证书/设置等 │
└──────────────────────────────┘
</code></pre>
<hr />
<p>简单介绍,Server、Hub、User都用各自的密码,都需要需要保存下来<br />
我们需要进入Server层,修改Server密码,创建一个测试Hub,熟悉一下<br />
然后创建EVEHub,添加监听端口,再把EVEHub桥接到接口pnet0上</p>
<table>
<thead>
<tr>
<th>层级</th>
<th>类似概念</th>
<th>功能</th>
</tr>
</thead>
<tbody>
<tr>
<td>Server</td>
<td>整个VPN服务器</td>
<td>管理所有Hub、端口、全局设置</td>
</tr>
<tr>
<td>Hub</td>
<td>一个独立虚拟交换机</td>
<td>每个Hub可独立拥有用户、NAT、认证方式</td>
</tr>
</tbody>
</table>
<hr />
<h2>配置 SoftEtherVPN</h2>
<p>开启 SoftEtherVPN 服务</p>
<pre><code class="language-shell">sudo vpnserver start
</code></pre>
<hr />
<p>进入 SoftEtherVPN 交互界面,每次进入都是这样操作的</p>
<pre><code class="language-shell">sudo vpncmd# 进入SoftEtherVPN交互界面的命令,
1# 交互
localhost
(回车)
</code></pre>
<p>并配置Server密码与Default,Default可以不配</p>
<pre><code class="language-shell">ServerPasswordSet# 设置Server密码
(密码)
Hub DEFAULT# 进入一个叫DEFAULT的Hub,默认存在,一般不用
SetHubPassword# 设置当前所在Hub的密码
(密码)
Hub# 返回上一级,即Server层
</code></pre>
<hr />
<p>一些操作介绍</p>
<pre><code class="language-shell">ServerStatusGet# 查看整体服务器状态
HubList# 查看所有Hub
ListenerList# 查看所有监听端口
Hub DEFAULT# 进入一个叫DEFAULT的Hub
UserList# 查看当前Hub的用户
Hub# 返回Server层
</code></pre>
<hr />
<p>创建一个测试Hub</p>
<pre><code class="language-shell">HubCreate TestHub# 创建一个叫TestHub的Hub用于测试
Hub TestHub# 进入TestHub
StatusGet# 查看当前所在的Hub的信息
Hub# 返回到Server
HubDelete TestHub# 删除一个叫TestHub的Hub
</code></pre>
<hr />
<p>创建EVEHub</p>
<pre><code class="language-shell">HubCreate EVEHub /PASSWORD:(密码) # 创建EVEHub并设置密码
Hub EVEHub# 进入EVEHub
UserCreate vpnuser# 在当前所在Hub中创建用户vpnuser
(回车)-(vpnuser)-(eve-ng)
UserPasswordSet vpnuser# 设置vpnuser的密码
(密码)
</code></pre>
<hr />
<p>添加监听端口</p>
<pre><code>Hub# 返回Server
ListenerCreate 8888# 监听8888
ListenerList# 查看所有监听端口
</code></pre>
<hr />
<h2>关闭防火墙</h2>
<p>仅限测试环境才能这么做</p>
<p>关闭 ufw、iptables、nftables</p>
<pre><code class="language-shell">sudo ufw disable
sudo iptables -F
sudo iptables -X
sudo iptables -t nat -F
sudo iptables -t nat -X
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT
sudo nft flush ruleset
sudo systemctl stop nftables
sudo systemctl disable nftables
</code></pre>
<hr />
<p>检查状态</p>
<pre><code class="language-shell">sudo ufw status verbose && sudo iptables -L -n -v && sudo systemctl status nftables
</code></pre>
<hr />
<h2>桥接网卡Hub</h2>
<p>创建并绑定桥接Hub</p>
<pre><code class="language-shell">BridgeCreate EVEHub /DEVICE:pnet0# 绑定EVEHub到接口pnet0
BridgeList# 查看桥接状态
Hub EVEHub# 进入EVEHub
Online# 使该Hub上限,下线是Offline
</code></pre>
<hr />
<p>查看桥接状态</p>
<pre><code class="language-shell">VPN Server/EVEHub>BridgeList
BridgeList command - Get List of Local Bridge Connection
Number|Virtual Hub Name|Network Adapter or Tap Device Name|Status
------+----------------+----------------------------------+---------
1 |EVEHub |pnet0 |Operating
The command completed successfully.
</code></pre>
<hr />
<h2>Windows安装客户端</h2>
<p>下载 Windows client x64 版本的<br />
softether-vpnclient-5.02.5187.x64.exe 这种的<br />
安装就行了</p>
<hr />
<h2>连接并验证</h2>
<p>打开 SoftEtherVPN 先添加一个 VPN网卡<br />
然后添加连接,输入主机名/端口/Hub名/账户/密码</p>
<hr />
<p>配置连接</p>
<p><img src="data/attachment/forum/202511/07/124939igo22a421o4y27qr.jpg" alt="SSLN.jpg" title="SSLN.jpg" /></p>
<p><img src="data/attachment/forum/" alt="" /></p>
<hr />
<p>进行连接</p>
<p><img src="data/attachment/forum/202511/07/124947ub7vlrsp2xpj7q72.png" alt="SSL1.png" title="SSL1.png" /></p>
<hr />
<p>打开带Web界面的防火墙,并开启http/https</p>
<pre><code>ip http enable
ip https enable
</code></pre>
<p><img src="data/attachment/forum/202511/07/124952uftrjfn2t22nfzdd.png" alt="SSL2.png" title="SSL2.png" /></p>
<hr />
<p>查看Hub与桥接</p>
<p><img src="data/attachment/forum/202511/07/124957y85cx9yxmxppcxlc.png" alt="SSL3.png" title="SSL3.png" /></p>
<hr />
<p>测试ping</p>
<p><img src="data/attachment/forum/202511/07/125002wrfh1xfe510c161e.png" alt="SSL4.png" title="SSL4.png" /></p>
<hr />
<p>访问Web</p>
<p><img src="data/attachment/forum/202511/07/125007fshm4h8h4mlzl4vh.png" alt="SSL5.png" title="SSL5.png" /></p>
<hr />
<h2>重置配置</h2>
<p>如果你配置错了,可以提供以下方案重置配置,似乎无法重置Server密码<br />
关闭服务,终止进程</p>
<pre><code>sudo systemctl stop softether-vpnserver
sudo pkill vpnserver
</code></pre>
<hr />
<p>删除配置文件与日志文件</p>
<pre><code>sudo rm -f /usr/local/libexec/softether/vpn_server.config
sudo rm -rf /usr/local/libexec/softether/server_log/*
sudo rm -rf /usr/local/libexec/softether/packet_log/*
sudo rm -rf /usr/local/libexec/softether/security_log/*
</code></pre>
<hr />
<p>重启服务</p>
<pre><code>sudo systemctl restart softether-vpnserver
</code></pre>
<pre><code>
</code></pre>
<h1>BugFix 架构调整 修复无法WireShak调试</h1>
<p>上面我们用的是桥接,把SoftEther VPN桥接到VE-NG的pnet0上<br />
但是这样虽然可以访问设备Web界面,但是由于没有22端口<br />
WireShark调试只能走22,无法调试22<br />
因为目前是通过公网:端口访问EVE-NG界面,通过169临时地址访问设备Web界面<br />
因为EVE-NGweb界面是公网,所以WireShark默认也走公网:22,肯定通不了<br />
只能想办法,让所有的访问都走内网IP</p>
<p>所以就不能桥接了,但是由于PVE(或者其他云厂商)会做隔离,会出现以下情况<br />
比如内网网关IP为192.168.1.1,你的服务器IP是192.168.1.10<br />
你通过VPN连进去之后,只能访问192.168.1.1<br />
所以打进去还得做个NAT伪装成另一个网段,这样就o了<br />
不知道你们能不能懂</p>
<p>删除原来的桥接</p>
<pre><code>Hub EVEHub
BridgeList # 确认有 pnet0 且 Operating
BridgeOffline /DEVICE:pnet0
BridgeDelete/DEVICE:pnet0
</code></pre>
<p>配置NAT与DHCP</p>
<pre><code>SecureNatDisable
SecureNatEnable
DhcpEnable
DhcpSet
# 按提示输入:
# Start: 192.168.30.10
# End: 192.168.30.200
# Mask:255.255.255.0
# Lease: 86400
# GW: 192.168.30.1
# DNS1:8.8.8.8
# DNS2:114.114.114.114
</code></pre>
<p>在Hub内查询配置情况</p>
<pre><code>NatGet
DhcpGet
</code></pre>
<p>配置LInux转发</p>
<pre><code>echo 1 > /proc/sys/net/ipv4/ip_forward
sysctl -w net.ipv4.ip_forward=1
# vim /etc/sysctl.conf
添加:net.ipv4.ip_forward=1
# iptables(清理旧表可选)
iptables -F
iptables -t nat -F
# 让 VPN 子网经过 pnet0 出去时做源地址伪装(关键)
iptables -t nat -A POSTROUTING -o pnet0 -s 192.168.30.0/24 -j MASQUERADE
# 放行访问
iptables -A FORWARD -s 192.168.30.0/24 -d 192.168.1.0/24 -j ACCEPT
iptables -A FORWARD -d 192.168.30.0/24 -s 192.168.1.0/24 -j ACCEPT
</code></pre>
<p><img src="data/attachment/forum/202511/12/114747loehfv22hooahby2.png" alt="image.png" title="image.png" /></p>
<h1>知识共享许可声明</h1>
<p><strong>知识共享许可声明</strong></p>
<p>除特别说明外,本文包含的原创文字、图片与资料均依据<br />
<a href="https://creativecommons.org/licenses/by-sa/4.0/"><strong>CC BY-SA 4.0 知识共享许可协议</strong></a> 授权发布。</p>
<p>您可以在<strong>注明作者与来源</strong>的前提下自由转载、修改与商业使用,<br />
但必须以<strong>相同协议共享衍生内容</strong>。</p>
页:
[1]