使用 SoftEther 搭建 L2TP VPN

  1. 1. 使用 SoftEther 搭建 L2TP VPN
    1. 1.1. 安装
      1. 1.1.1. 编译安装
      2. 1.1.2. 开机自启
    2. 1.2. 配置L2TP
      1. 1.2.1. 配置
      2. 1.2.2. 端口转发

使用 SoftEther 搭建 L2TP VPN

在openwrt上搭建 L2TP VPN 都推荐用 openswan、libreswan 比较繁琐,softether在openwrt上不知道为什么总是丢失配置文件,所以要在Linux上配置,softether这个简单易用还容易管理,也能完成多地组网的复杂操作。

安装

编译安装

1
2
3
4
5
6
7
8
9
10
# 安装编译工具
apt install build-essential gcc make wget tzdata git libreadline-dev libncurses-dev libssl-dev zlib1g-dev
# 下载源码
git clone https://github.com/SoftEtherVPN/SoftEtherVPN_Stable.git
# 编译,我编译的时候丝般顺滑,一点报错都没有(Ubuntu 20.04)
cd SoftEtherVPN_Stable/
./configure
make
# 安装
make install

开机自启

创建文件:/lib/systemd/system/vpnserver.service

1
2
3
4
5
6
7
8
9
10
11
[Unit]
Description=SoftEther VPN Server
After=network.target

[Service]
Type=forking
ExecStart=/usr/bin/vpnserver start
ExecStop=/usr/bin/vpnserver stop

[Install]
WantedBy=multi-user.target
1
2
3
4
# 开启这个服务
systemctl enable vpnserver.service
# 启动服务
service vpnserver start

配置L2TP

配置

咕了,这东西配置起来很容易很容易,教程特别多,都是中文的,大致说一下有两种配置方式:

一种是通过命令行配置vpncmd,这里如果你的Linux服务器是中文的,那么这个vpncmd的命令帮助都是中文的,简直太简单,这个vpncmd值得好好玩一玩,GUI配置有些时候着实是不方便。

另一种是通过管理程序配置,也是中文的,配置工具下载 https://www.softether-download.com/cn.aspx?product=softether。

如果想要访问内网的东西,需要开启SecureNAT

参考配置教程:

  1. 中文:https://noter.tw/4524/softether-vpn-架設記錄/
  2. 官方英文(不推荐):https://www.softether.org/4-docs/2-howto/9.L2TPIPsec_Setup_Guide_for_SoftEther_VPN_Server/1.Setup_L2TP%2F%2F%2F%2FIPsec_VPN_Server_on_SoftEther_VPN_Server
  3. 中文:https://libertyleadingnetwork.blogspot.com/2018/01/softethervpsvpn.html
  4. 中文:http://blog.dengxj.com/archives/9/

端口转发

如果你和我一样是在内网配置的,且有公网IP,需要在路由器上转发UDP:500UDP:4500出去,再搞一个DDNS这样就可以远程访问家里了。