L2TP具体的工作原理这里不再多说(可以自行百度或者GOOGLE),这里把经历过一些碰壁的问题在这里进行下梳理:
- 针对于阿里云的云服务器要在安全组上要把500、1701和4500的UDP端口放行
阿里云盾的内置服务要关闭。 - 我用的是其他云,所以在云上不用做相应的安全策略,只需要加入防火墙策略。
- 配置文件里有涉及到TAB及空行的地方要注意!
构建环境:l2tp服务端 centos7.4 客户端win10/apple IOS系统
1. 先看看你的主机是否支持pptp,返回结果为yes就表示通过。
modprobe ppp-compress-18 && echo yes
2.是否开启了TUN,有的虚拟机主机需要开启,返回结果为cat: /dev/net/tun: File descriptor in bad state,就表示通过。
cat /dev/net/tun
3.安装EPEL源(CentOS7官方源中已经去掉了xl2tpd。
yum install -y epel-release
4.安装xl2tpd和libreswan(openswan已经停止维护)
yum install -y xl2tpd libreswan lsof
5.编辑xl2tpd配置文件
vim /etc/xl2tpd/xl2tpd.conf
以下配置增加到最后
[lns default]
ip range = 192.168.1.100-192.168.1.120 #分配连接客户端的地址
local ip = 192.168.1.3#本地内网IP,如果没有本地内网IP可以在外网IP上增加子接口
require chap = yes
refuse pap = yes
require authentication = yes
name = LinuxVPNserver
ppp debug = yes
pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes
6.编辑pppoptfile文件
vim /etc/ppp/options.xl2tpd
ipcp-accept-local
ipcp-accept-remote
ms-dns 114.114.114.114
ms-dns 8.8.8.8
# ms-wins 192.168.1.2
# ms-wins 192.168.1.4
name xl2tpd
#noccp
auth
#crtscts
idle 1800
mtu 1410
mru 1410
nodefaultroute
debug
#lo