使用SoftEther搭建VPN服务

这里将会一步一步介绍如何搭建和配置一个多协议的VPN服务,通过SoftEther翻越长城。

使用SoftEther搭建VPN服务

编号:TD-0x0003

标签:vpn;gfw;softether;DigitalOcean;

这里将会一步一步介绍如何搭建和配置一个多协议的VPN服务,通过VPN翻越长城。

什么是 GFW

英语:Great Firewall of China,常用简称:GFW,中文也称中国国家防火墙,是对中国政府在其互联网边界审查系统(包括相关行政审查系统)的统称。此系统起步于1998年,其英文名称得自于2002年5月17日Charles R. Smith所写的一篇关于中国网络审查的文章《The Great Firewall of China》,取与Great Wall(长城)相谐的效果,简写为Great Firewall,缩写GFW。随着使用的拓广,中文“墙”和英文“GFW”有时也被用作动词,网友所说的“被墙”即指被防火长城所屏蔽。

什么是 SoftEther?

SoftEther VPN是个由筑波大学Daiyuu Nobori研究生因硕士论文开发的开源、跨平台、多重协议的虚拟专用网方案。他让一些虚拟专用网协议像是SSL VPN 、L2TP、IPsec、OpenVPN以及微软SSTP都由同一个单一VPN服务器提供。在2014年一月四日以GNU通用公共授权条款方式发布。
SothEther VPN是专门被设计为穿过防火墙的。它支持NAT穿透,使他能越过政府或组织的防火墙,设立虚拟专用网服务器。因为用了HTTPS来伪装连接,防火墙的深度数据包检测无法侦测到SofthEther的VPN发送数据包构成的VPN通道。但SoftEther的SSL VPN协议在中国大陆的部分地区仍然被封锁。
性能优化也是SoftEther VPN的一个目标。它使用像是利用全部以太网帧的策略,减少了内存复制的操作、平行传输和群集,这减少了通常VPN连接会有的延迟并增加了运输吞吐量。
这个软件开源在GitHub上,搜索SoftEtherVPN。

Step 1: 建立一个虚拟服务器

推荐使用 DigitalOcean 的服务。
DigitalOcean是一家建立于美国的云基础架构提供商,面向软件开发人员提供虚拟专用服务器(VPS)。该公司总部设在纽约市,并在世界各地拥有数据中心。2015年12月,DigitalOcean成为了全球第二大面向Web的网络寄存服务公司。
使用这个链接注册可以获得$10的使用额度。最低资源的服务器为$5一个月,可以使用2个月。

https://www.digitalocean.com/?refcode=cc0edbf24578

整个建立过程十分简单,一步一步点下就可以了。登录验证方式可以使用密码或密钥。本文使用的Linux版本是Ubuntu16.04。

Step 2: 更新服务并安装相关软件

使用一下命令更新服务器。

apt-get update && apt-get upgrade

安装必须的软件包:

apt-get install build-essential -y

去下面的地址复制SoftEther的下载链接。依次选择SoftEther VPN Server,Linux, Intel x64/AMD64。
Download SoftEther
然后回到Command Line,使用wget下载。

wget http://www.softether-download.com/files/softether/v4.21-9613-beta-2016.04.24-tree/Linux/SoftEther_VPN_Server/64bit_-_Intel_x64_or_AMD64/softether-vpnserver-v4.21-9613-beta-2016.04.24-linux-x64-64bit.tar.gz

解压缩:

tar xzvf softether-vpnserver-v4.21-9613-beta-2016.04.24-linux-x64-64bit.tar.gz

编译,make后根据提示输入,同意相关协议:

cd vpnsever
make

之后出一下即可:

--------------------------------------------------------------------
The preparation of SoftEther VPN Server is completed !

......
--------------------------------------------------------------------

将SoftEther移动到其他文件夹,我们将其move到/opt.

cd ..
mv vpnserver /opt
cd /opt/vpnserver/

将VPN服务启动并检查状态:

root@debian:/opt/vpnserver# ./vpnserver start
The SoftEther VPN Server service has been started.
root@debian:/opt/vpnserver# ./vpncmd
vpncmd command - SoftEther VPN Command Line Management Utility
SoftEther VPN Command Line Management Utility (vpncmd command)
Version 4.21 Build 9613   (English)
Compiled 2016/04/24 16:39:47 by yagi at pc30
Copyright (c) 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: 3

VPN Tools has been launched. By inputting HELP, you can view a list of the commands that can be used.

VPN Tools>check
Check command - Check whether SoftEther VPN Operation is Possible
---------------------------------------------------
SoftEther VPN Operation Environment Check Tool
...
The command completed successfully.

如果所有的检查都通过了,VPN服务就已经就位,可以进行配置了。这里我们用vpncmd进行配置。也可以使用其他方式。

Step 3: 配置

更改管理员密码

在开始使用VPN先必须配置一个管理员密码:

./vpncmd

选1. Management of VPN Server or VPN Bridge。之后按两次回车进入本地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.

创建一个Virtual Hub

使用一下命令创建一个名为VPN的HUB,会提示输入此HUB的管理员密码,自己创建一个。

VPN Server>HubCreate VPN
HubCreate command - Create New Virtual Hub
Please enter the password. To cancel press the Ctrl+D key.

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

The command completed successfully.

现在选中刚才创建的HUB,此后的配置都是基于这个HUB。

VPN Server>Hub VPN
Hub command - Select Virtual Hub to Manage
The Virtual Hub "VPN" has been selected.
The command completed successfully.

开启SecureNAT

SecureNAT 是 Virtual NAT 和 DHCP Server 的结合. 使用一下命令开启SecureNAT:

VPN Server/VPN>SecureNatEnable
SecureNatEnable command - Enable the Virtual NAT and DHCP Server Function (SecureNat Function)
The command completed successfully.

创建VPN登陆用户名和密码

现在我们开始想创建的VPN HUB添加用户。使用[UserCreate]添加用户,使用[UserList]查看用户列表。

VPN Server/VPN>UserCreate mk928
UserCreate command - Create User
Assigned Group Name:

User Full Name:

User Description:

The command completed successfully.

VPN Server/VPN>UserPasswordSet mk928
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.
VPN Server/VPN>UserList
UserList command - Get List of Users
Item            |Value
----------------+-----------------------
User Name       |mk928
Full Name       |
Group Name      |-
Description     |
Auth Method     |Password Authentication
Num Logins      |0
Last Login      |(None)
Expiration Date |No Expiration
Transfer Bytes  |0
Transfer Packets|0
The command completed successfully.

SoftEther 提供了多种验证方式,可根据自己的需求配置。

开启 L2TP/IPSec

开启 L2TP over IPsec Server Function: 现在可以使用iPhone, Android, Windows, and Mac OS X 设备连接VPN服务.

VPN Server/VPN>IPsecEnable

连接到 SoftEther VPN Server

同样到一下地址下载客户端。安装并配置到VPN服务器的连接即可。Mac用户可直接使用系统的vpn工具连接。
Download SoftEther Client