L2TP centos7 快速安装

osycloud 20天前 113

curl -s https://域名.com/l2tp.sh | sed 's/\r$//' | sudo bash

 

#!/bin/bash

# 添加国内源并清理缓存
sudo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sudo yum clean all
sudo yum makecache

# 自动检测服务器公网 IP
SERVER_IP=$(curl -s http://whatismyip.akamai.com)
VPN_USER="vpn123"
VPN_PASSWORD="vpn123"

# 停止并禁用firewalld
systemctl stop firewalld
systemctl disable firewalld

# 安装必要的软件
yum install -y epel-release
yum install -y xl2tpd ppp

# 配置xl2tpd
cat > /etc/xl2tpd/xl2tpd.conf <<EOF
[global]
ipsec saref = no

[lns default]
ip range = 192.168.1.2-192.168.1.254
local ip = 192.168.1.1
require chap = yes
refuse pap = yes
require authentication = yes
name = L2TP VPN Server
ppp debug = yes
pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes
EOF

# 配置PPP
cat > /etc/ppp/options.xl2tpd <<EOF
require-mschap-v2
ms-dns 8.8.8.8
ms-dns 8.8.4.4
asyncmap 0
auth
crtscts
lock
hide-password
modem
name l2tpd
proxyarp
lcp-echo-interval 30
lcp-echo-failure 4
EOF

# 添加VPN用户
cat > /etc/ppp/chap-secrets <<EOF
# Secrets for authentication using CHAP
# client    server  secret          IP addresses
$VPN_USER    l2tpd   $VPN_PASSWORD          *
EOF

# 启动并启用xl2tpd服务
systemctl start xl2tpd
systemctl enable xl2tpd

# 配置系统转发和防火墙
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
sysctl -p

iptables --table nat --append POSTROUTING --jump MASQUERADE
iptables --append FORWARD --protocol udp --dport 1701 --jump ACCEPT

service iptables save

echo "L2TP VPN 安装和配置完成。"
echo "服务器公网IP: $SERVER_IP"
echo "VPN 用户名: $VPN_USER"
echo "VPN 密码: $VPN_PASSWORD"

最新回复 (0)