亲测在Vultr
和UltraVPS
的Ubuntu 14.04 LTS
成功搭建L2TP
的VPN
。
本方法使用Linux自带的账户认证作为L2TP
的认证。用户名默认为vpn_user
,密码在脚本执行过程中,由执行者手动设定密码;PSK
为psk
,开机自动启动。
本脚本必须使用root
账户执行。
#!/bin/bash
# Referring from https://raymii.org/s/tutorials/IPSEC_L2TP_vpn_with_Ubuntu_14.04.html
if [[ $EUID -ne 0 ]]; then
echo 'Error:This script must be run as root!'
exit 1
fi
apt-get install -y openswan xl2tpd ppp lsof vim rng-tools curl
SERVERIP=`curl -s -4 icanhazip.com`
iptables -t nat -A POSTROUTING -j SNAT --to-source $SERVERIP -o eth0
echo 'net.ipv4.ip_forward = 1' | tee -a /etc/sysctl.conf
echo 'net.ipv4.conf.all.accept_redirects = 0' | tee -a /etc/sysctl.conf
echo 'net.ipv4.conf.all.send_redirects = 0' | tee -a /etc/sysctl.conf
echo 'net.ipv4.conf.default.rp_filter = 0' | tee -a /etc/sysctl.conf
echo 'net.ipv