查看: 299|回复: 0

EVE-NG裸机部署SSL VPN,实现外网连接裸机内网

3

主题

16

回帖

4591

积分

金牌会员

Rank: 6Rank: 6

积分
4591
[i=s] 本帖最后由 CingSyuan 于 2025-11-12 11:47 编辑 [/i]

这篇内容,晦涩难懂,没有Linux与网络基础的,直接绕路吧
实在想研究的可以多读几遍,自行领悟奥秘,或者问问AI

环境

这是我的部署环境,我是打算通过 公网访问 EVE-NG 的,但是对外端口有限
我是在我朋友的 PVE服务器 上部署的,理论上你可以在任何 x86 Ubuntu 22 LTS 平台部署
比如云服务器、物理机、ESXI、PVE、VMware vSphere、超融合平台、Open Stack等

Proxmox VE 9.0.6
Intel(R) Xeon(R) Platinum 8259CL CPU
Linux 6.14 11-1-pve
对外端口范围:32769~32897(必须)、以及Web(必须)、SSH/FTP等端口(建议)


我打算使用 SoftEtherVPN 做一个 SSL VPN 打通外网到裸机内网
这样就能访问防火墙等设备的web管理页面了
如果你的裸机没有公网,套一个内网穿透也是可以的


需要下载 SoftEtherVPN
https://github.com/SoftEtherVPN/SoftEtherVPN/releases


编译/安装

安装编译依赖

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

下载 SoftEtherVPN,当前版本是5.2.5188,下载 tar.xz 结尾的
自己通过FTP传到 /usr/local

cd /usr/local

tar -xJf SoftEtherVPN-5.2.5188.tar.xz

cd SoftEtherVPN-5.2.5188/
mkdir build
cd build

cmake

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 commit  in /usr/local/SoftEtherVPN-5.2.5188
-- Configuring done
-- Generating done
-- Build files have been written to: /usr/local/SoftEtherVPN-5.2.5188/build

make

root@pveng:/usr/local/SoftEtherVPN-5.2.5188/build# sudo make -j$(nproc)
[100%] Linking C shared library ../../libcedar.so
[100%] Built target cedar
[100%] Building C object src/vpnclient/CMakeFiles/vpnclient.dir/vpncsvc.c.o
[100%] Building C object src/vpncmd/CMakeFiles/vpncmd.dir/vpncmd.c.o
[100%] Building C object src/vpntest/CMakeFiles/vpntest.dir/vpntest.c.o
[100%] Building C object src/vpnserver/CMakeFiles/vpnserver.dir/vpnserver.c.o
[100%] Building C object src/vpnbridge/CMakeFiles/vpnbridge.dir/vpnbridge.c.o
[100%] Linking C executable ../../vpnclient
[100%] Linking C executable ../../vpncmd
[100%] Linking C executable ../../vpnserver
[100%] Linking C executable ../../vpnbridge
[100%] Linking C executable ../../vpntest
[100%] Built target vpnclient
[100%] Built target vpncmd
[100%] Built target vpnserver
[100%] Built target vpnbridge
[100%] Built target vpntest

make install

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.
----------------------------------------------------------------------------------------------------------------------------

配置 SoftEtherVPN

认识架构

┌──────────────────────────────┐
│ SoftEther VPN Server         │
│  ├── 管理密码 (ServerPassword)│ ← 整个服务器的root权限
│  ├── 监听端口 (Listener)      │ ← 如 443, 8888 等
│  ├── 虚拟 Hub (Virtual Hub)  │ ← 虚拟交换机
│  │   ├── Hub 管理密码         │
│  │   ├── 用户 (User)         │ ← VPN登录账号
│  │   ├── SecureNAT 模块       │ ← 内置NAT/DHCP网关
│  │   └── Bridge/Local Bridg  │ ← 与物理网卡或虚拟网桥连接
│  └── 日志/证书/设置等          │
└──────────────────────────────┘

简单介绍,Server、Hub、User都用各自的密码,都需要需要保存下来
我们需要进入Server层,修改Server密码,创建一个测试Hub,熟悉一下
然后创建EVEHub,添加监听端口,再把EVEHub桥接到接口pnet0上

层级 类似概念 功能
Server 整个VPN服务器 管理所有Hub、端口、全局设置
Hub 一个独立虚拟交换机 每个Hub可独立拥有用户、NAT、认证方式

配置 SoftEtherVPN

开启 SoftEtherVPN 服务

sudo vpnserver start

进入 SoftEtherVPN 交互界面,每次进入都是这样操作的

sudo vpncmd  # 进入SoftEtherVPN交互界面的命令,
1  # 交互
localhost
(回车)

并配置Server密码与Default,Default可以不配

ServerPasswordSet  # 设置Server密码
(密码)

Hub DEFAULT  # 进入一个叫DEFAULT的Hub,默认存在,一般不用
SetHubPassword  # 设置当前所在Hub的密码
(密码)

Hub  # 返回上一级,即Server层

一些操作介绍

ServerStatusGet  # 查看整体服务器状态
HubList  # 查看所有Hub
ListenerList  # 查看所有监听端口

Hub DEFAULT  # 进入一个叫DEFAULT的Hub
UserList  # 查看当前Hub的用户
Hub  # 返回Server层

创建一个测试Hub

HubCreate TestHub  # 创建一个叫TestHub的Hub用于测试
Hub TestHub  # 进入TestHub
StatusGet  # 查看当前所在的Hub的信息
Hub  # 返回到Server
HubDelete TestHub  # 删除一个叫TestHub的Hub

创建EVEHub

HubCreate EVEHub /PASSWORD:(密码) # 创建EVEHub并设置密码
Hub EVEHub  # 进入EVEHub
UserCreate vpnuser  # 在当前所在Hub中创建用户vpnuser
(回车)-(vpnuser)-(eve-ng)
UserPasswordSet vpnuser  # 设置vpnuser的密码
(密码)

添加监听端口

Hub  # 返回Server
ListenerCreate 8888  # 监听8888
ListenerList  # 查看所有监听端口

关闭防火墙

仅限测试环境才能这么做

关闭 ufw、iptables、nftables

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

检查状态

sudo ufw status verbose && sudo iptables -L -n -v && sudo systemctl status nftables

桥接网卡Hub

创建并绑定桥接Hub

BridgeCreate EVEHub /DEVICE:pnet0  # 绑定EVEHub到接口pnet0
BridgeList  # 查看桥接状态
Hub EVEHub  # 进入EVEHub
Online  # 使该Hub上限,下线是Offline

查看桥接状态

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.

Windows安装客户端

下载 Windows client x64 版本的
softether-vpnclient-5.02.5187.x64.exe 这种的
安装就行了


连接并验证

打开 SoftEtherVPN 先添加一个 VPN网卡
然后添加连接,输入主机名/端口/Hub名/账户/密码


配置连接

SSLN.jpg


进行连接

SSL1.png


打开带Web界面的防火墙,并开启http/https

ip http enable
ip https enable

SSL2.png


查看Hub与桥接

SSL3.png


测试ping

SSL4.png


访问Web

SSL5.png


重置配置

如果你配置错了,可以提供以下方案重置配置,似乎无法重置Server密码
关闭服务,终止进程

sudo systemctl stop softether-vpnserver
sudo pkill vpnserver

删除配置文件与日志文件

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/*

重启服务

sudo systemctl restart softether-vpnserver

BugFix 架构调整 修复无法WireShak调试

上面我们用的是桥接,把SoftEther VPN桥接到VE-NG的pnet0上
但是这样虽然可以访问设备Web界面,但是由于没有22端口
WireShark调试只能走22,无法调试22
因为目前是通过公网:端口访问EVE-NG界面,通过169临时地址访问设备Web界面
因为EVE-NGweb界面是公网,所以WireShark默认也走公网:22,肯定通不了
只能想办法,让所有的访问都走内网IP

所以就不能桥接了,但是由于PVE(或者其他云厂商)会做隔离,会出现以下情况
比如内网网关IP为192.168.1.1,你的服务器IP是192.168.1.10
你通过VPN连进去之后,只能访问192.168.1.1
所以打进去还得做个NAT伪装成另一个网段,这样就o了
不知道你们能不能懂

删除原来的桥接

Hub EVEHub
BridgeList          # 确认有 pnet0 且 Operating
BridgeOffline /DEVICE:pnet0
BridgeDelete  /DEVICE:pnet0

配置NAT与DHCP

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

在Hub内查询配置情况

NatGet
DhcpGet

配置LInux转发

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

image.png

知识共享许可声明

知识共享许可声明

除特别说明外,本文包含的原创文字、图片与资料均依据
CC BY-SA 4.0 知识共享许可协议 授权发布。

您可以在注明作者与来源的前提下自由转载、修改与商业使用,
但必须以相同协议共享衍生内容

回复

使用道具 举报

本版积分规则

Copyright   ©2015-2026  EmulatedLab  Powered by Discuz!©   ( 浙ICP备2021010423号-1 )
快速回复 返回列表 返回顶部