在 Ubuntu 24.04 VPS 部署 SoftEther VPN 服务器(一)

SoftEther VPN 是一种开源多协议 VPN 软件,允许个人用户连接到远程网络。SoftEther VPN 使用户能够使用 IP 通信网络安全地创建一个高性能的虚拟专用网络 (VPN),其中互联网是典型的例子。 VPN 技术可以在从商业应用程序通信到面向个人和家庭使用的网络的各个领域中得到最大利用。SoftEther VPN 服务器、客户端和网桥是免费软件,并作为开源发布。 您可以根据 Apache License 2.0 的条款重新分发和/或修改它们。

项目地址:https://github.com/SoftEtherVPN/SoftEtherVPN

源代码包下载地址:SoftEther Download Center

SoftEther VPN 的特点:

  • **重量轻,速度快:**可以支持SoftEther VPN 观看 YouTube 4K 视频。
  • **跨平台:**它可以在 Linux、FreeBSD、macOS、Solaris 和 Windows 服务器上运行,包括对 X86、AMD64、ARM、PowerPC、MIPS 架构的支持。
  • **支持多种协议:**包括 OpenVPN、L2TP、IPSec、SSTP 等传统协议,以及内部 SoftEtherVPN 协议,这是一种基于 HTTPS 的 VPN 协议。
  • **客户端丰富:**有适用于 Linux、macOS、Windows 的 SoftEther 客户端软件,包括对 ARM、PowerPC 和 MIPS 架构的支持。
  • **NAT 遍历:**允许在 NAT 后面运行 SoftEther VPN 服务器,而无需端口转发。
  • 基于 ICMP 的 VPN / 基于 DNS 的 VPN:允许使用 ICMP 或 DNS 建立 VPN 连接,即使防火墙或路由器阻止每个 TCP 或 UDP 连接。
  • 基于 HTML5的现代 Admin Console。

搭建SoftEtherVPN你需要一台有公网地址和域名的虚拟专用服务器VPS(Virtual Private Server,简称 VPS)主机,可以向阿里、腾讯、华为等运营商处购买。

一:在ubuntu24.04上安装SoftEther软件

1、下载 SoftEther VPN 服务器的最新稳定版本

我们选择最新的v4.43来安装

复制代码
wget https://www.softether-download.com/files/softether/v4.43-9799-beta-2023.08.31-tree/Linux/SoftEther_VPN_Server/64bit_-_Intel_x64_or_AMD64/softether-vpnserver-v4.43-9799-beta-2023.08.31-linux-x64-64bit.tar.gz

这是当前版本的安装方法,如果后续版本有变化,大家可以留意GitHub上的介绍。

2、提取存档

复制代码
tar -xvf softether-vpnserver-*.tar.gz

3、编译文件

复制代码
#进入目录
cd vpnserver/
#安装依赖包
sudo apt install -y gcc binutils gzip libreadline-dev libssl-dev libncurses5-dev libncursesw5-dev libpthread-stubs0-dev
#编译
make

生成了两个可执行文件:

  • vpnserver:服务器二进制文件。
  • vpncmd:SoftEther VPN 命令行管理实用程序

4、将文件拷贝至工作目录

复制代码
cd ..
sudo mv vpnserver/ /opt/softether

二:设置自动启动

复制代码
#VPN 服务器可以通过以下方式启动:
sudo /opt/softether/vpnserver start
#停止它:
sudo /opt/softether/vpnserver stop

设置开机时自动启动,我们可以为其创建一个 systemd 服务单元。编辑启动文件:

复制代码
sudo vim /etc/systemd/system/softether-vpnserver.service

将以下行添加到此文件中。

复制代码
[Unit]
Description=SoftEther VPN server
After=network-online.target
After=dbus.service

[Service]
Type=forking
ExecStart=/opt/softether/vpnserver start
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

配置好就可以使用下面的命令来启动管理了

复制代码
#启动VPN
sudo systemctl start softether-vpnserver
#设置开机启动
sudo systemctl enable softether-vpnserver
#查看状态
systemctl status softether-vpnserver

三:需要放开的防火墙端口

TCP:80,443,992,1194,5555

UDP:1194,51612,53400,56452,40085

四:配置 SoftEther VPN 服务器

1、配置 SoftEther VPN 服务器

复制代码
/opt/softether/vpncmd

显示如下:

复制代码
root@VM-8-3-ubuntu:/opt/softether# ./vpncmd 
vpncmd command - SoftEther VPN Command Line Management Utility
SoftEther VPN Command Line Management Utility (vpncmd command)
Version 4.42 Build 9798   (English)
Compiled 2023/06/30 11:06:58 by buildsan at crosswin with OpenSSL 3.0.9
Copyright (c) 2012-2023 SoftEther VPN Project. All Rights Reserved.

By using vpncmd program, the following can be achieved. 

1. Management of VPN Server or VPN Bridge 
2. Management of VPN Client
3. Use of VPN Tools (certificate creation and Network Traffic Speed Test Tool)

Select 1, 2 or 3: 1

管理控制台正在侦听端口 5555。输入 以访问 Admin Console。127.0.0.1:5555

然后按跳过 Virtual Hub 选择。Enter

2、设置控制台密码:

默认情况下,Admin Console 的密码为空。我们需要通过执行"ServerPasswordSet"命令来设置密码。

复制代码
Specify the host name or IP address of the computer that the destination VPN Server or VPN Bridge is operating on. 
By specifying according to the format 'host name:port number', you can also specify the port number. 
(When the port number is unspecified, 443 is used.)
If nothing is input and the Enter key is pressed, the connection will be made to the port number 8888 of localhost (this computer).
Hostname of IP Address of Destination: 127.0.0.1:5555

If connecting to the server by Virtual Hub Admin Mode, please input the Virtual Hub name. 
If connecting by server admin mode, please press Enter without inputting anything.
Specify Virtual Hub Name: 
Connection has been established with VPN Server "127.0.0.1" (port 5555).

You have administrator privileges for the entire VPN Server.

VPN Server>ServerPasswordSet
ServerPasswordSet command - Set VPN Server Administrator Password
Please enter the password. To cancel press the Ctrl+D key.

Password: *********
Confirm input: *********

The command completed successfully.

3、设置虚拟中心:

接下来,我们需要在 SoftEtherVPN 中配置一个虚拟中心。我们可以使用名为 的默认虚拟中心

复制代码
Hub DEFAULT

显示如下:

复制代码
Hub command - Select Virtual Hub to Manage
The Virtual Hub "DEFAULT" has been selected.
The command completed successfully.

4、添加用户:

然后使用以下命令创建一个 VPN 账户。替换为您的首选用户名

复制代码
UserCreate test

这里我们用"test"用户来演示

复制代码
VPN Server/DEFAULT>UserCreate test
UserCreate command - Create User 
Assigned Group Name: 

User Full Name: 
User Description: 
The command completed successfully.

系统将要求您输入组名称、全名和用户描述。您可以按 Enter将它们留空

5、为此用户设置密码

复制代码
UserPasswordSet test

VPN Server/DEFAULT>UserPasswordSet test
UserPasswordSet command - Set Password Authentication for User Auth Type and Set Password
Please enter the password. To cancel press the Ctrl+D key.

Password: *********
Confirm input: *********

The command completed successfully.

6、执行以下命令开启虚拟 NAT 和 DHCP 服务器功能,否则 VPN 客户端将无法从 VPN 服务器获取 IP 地址。

复制代码
SecureNatEnable

7、接下来,我们需要通过执行命令为 VPN 用户配置 NAT

复制代码
DhcpSet

显示如下:

复制代码
VPN Server/DEFAULT>DhcpSet
DhcpSet command - Change Virtual DHCP Server Function Setting of SecureNAT Function
Start Point for Distributed Address Band: 192.168.30.10
End Point for Distributed Address Band: 192.168.30.200
Subnet Mask: 255.255.255.0
Lease Limit (Seconds): 7200
Default Gateway ('none' to not set this): 192.168.30.1
DNS Server 1 ('none' to not set this): 192.168.30.1
DNS Server 2 ('none' to not set this): 1.0.0.1
Domain Name: 
Save Log (yes / no): yes
The command completed successfully.

设置项说明:

分布式地址带的起点:192.168.30.10

分布式地址带的端点:192.168.30.200

子网掩码:255.255.255.0

租约限制(秒):7200

默认网关:192.168.30.1

DNS 服务器 1:192.168.30.1

DNS 服务器 2:1.0.0.1

域名:按下可跳过。Enter

保存日志:yes

8、退出设置

复制代码
exit

至此SoftEther VPN就安装完成了。我们下一节会详细介绍它的工作配置。

相关推荐
秋风起,再归来~2 分钟前
【Linux庖丁解牛】—进程优先级!
linux·运维·服务器
cosX+sinY21 分钟前
ubuntu 20.04 编译运行lio-sam,并保存为pcd
linux·ubuntu·机器人
Lary_Rock1 小时前
Android 编译问题 prebuilts/clang/host/linux-x86
android·linux·运维
熬夜学编程的小王1 小时前
【Linux篇】理解信号:如何通过信号让程序听从操作系统的指令
linux·信号产生·软件条件产生信号
子非衣1 小时前
Windows云主机远程连接提示“出现了内部错误”
服务器·windows
绵绵细雨中的乡音1 小时前
Linux进程学习【基本认知】
linux·运维·学习
Johny_Zhao2 小时前
MySQL 高可用集群搭建部署
linux·人工智能·mysql·信息安全·云计算·shell·yum源·系统运维·itsm
lLinkl2 小时前
项目笔记2:post请求是什么,还有什么请求
服务器·网络协议·http
FREEDOM_X2 小时前
ubuntu20.04 远程桌面Xrdp方式
ubuntu·vmware
珹洺3 小时前
Linux操作系统从入门到实战(三)Linux基础指令(上)
linux·运维·服务器