在 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就安装完成了。我们下一节会详细介绍它的工作配置。

相关推荐
汪子熙1 小时前
介绍我经常使用的两款轻便易用的 JSON 工具
linux·服务器·json
Jtti2 小时前
怎么在FTP服务器上配置SSL/TLS?
服务器·网络·ssl
XY.散人2 小时前
初识Linux · 进程终止
linux·运维·服务器
Lvan的前端笔记2 小时前
linux:详解nohup命令
linux·运维·服务器
长天一色2 小时前
C语言日志类库 zlog 使用指南(第三章 “Hello World“)
linux·c语言·openeuler
bossface2 小时前
理解线程库和线程排斥(锁)
linux·运维·服务器·c语言·c++
iFulling2 小时前
【Linux实践】实验八:Shell程序的创建及变量
android·linux·服务器
水上冰石3 小时前
ubuntu 安装neo4j
linux·ubuntu·neo4j
Percep_gan3 小时前
Linux中安装ffmpeg
linux·运维·ffmpeg