# vpn搭建 **Repository Path**: fhjad/vpn-construction ## Basic Information - **Project Name**: vpn搭建 - **Description**: centos l2tp vpn 搭建 自动化脚本 - **Primary Language**: Shell - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2021-03-22 - **Last Updated**: 2023-04-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # vpn搭建 #### 介绍 centos l2tp vpn 搭建 自动化脚本 #### 安装教程 yum -y install wget 1. 下载l2tp.sh 2. chmod +x l2tp.sh 3. ./l2tp #### 使用说明 # 1.掌握防火墙知识 1. iptables 服务在 /etc/sysconfig/iptables 中储存配置 (centos6) 2. FirewallD 将配置储存在 /usr/lib/firewalld/ 和 /etc/firewalld/ 中的各种 XML 文件里 (centos7) firewall相关命令: 设置开机启用服务 systemctl enable firewalld.service 设置开机禁用服务 systemctl disable firewalld.service 开启服务 systemctl start firewalld.service 停止服务 systemctl stop firewalld.service 查看firewalld状态 systemctl status firewalld 查看版本 firewall-cmd --version 查看帮助 firewall-cmd --help 显示状态 firewall-cmd --state 注意:云服务器中 4500/udp,500/udp,1701/udp 端口必须放开 # 2. 配置文件解析 # 2.1 /etc/xl2tpd/xl2tpd.conf [global] port = 1701 [lns default] ip range = 192.168.18.2-192.168.18.254 (注:VPN连接以后分配的地址段,切记不能跟服务器地址如:eth0和公网地址相同) local ip = 192.168.18.1 require chap = yes refuse pap = yes require authentication = yes name = l2tpd ppp debug = yes pppoptfile = /etc/ppp/options.xl2tpd length bit = yes # 2.2 /etc/ppp/options.xl2tpd ipcp-accept-local ipcp-accept-remote require-mschap-v2 ms-dns 8.8.8.8 ms-dns 8.8.4.4 noccp auth hide-password idle 1800 mtu 1410 mru 1410 nodefaultroute debug proxyarp connect-delay 5000 # 2.3 /etc/ipsec.conf version 2.0 config setup protostack=netkey nhelpers=0 uniqueids=no interfaces=%defaultroute virtual_private=%v4:10.0.0.0/8,%v4:192.168.0.0/16,%v4:172.16.0.0/12,%v4:!192.168.18.0/24 logfile=/data/ipsec.log #日志有打印 conn l2tp-psk rightsubnet=vhost:%priv also=l2tp-psk-nonat conn l2tp-psk-nonat authby=secret pfs=no auto=add keyingtries=3 rekey=no ikelifetime=8h keylife=1h type=transport left=%defaultroute leftid=121.4.238.232 leftprotoport=17/1701 right=%any rightprotoport=17/%any dpddelay=40 dpdtimeout=130 dpdaction=clear sha2-truncbug=no #IOS14.2无法连接l2tp的解决方案,iphone无法连接l2tp的解决方案,配置服务器以将 SHA-256 哈希的输出截断至 128 位 # 2.4 查看xl2tpd日志 tail -100f /var/log/messages # 3. xl2tpd 、ipsec 启停 systemctl start xl2tpd systemctl stop xl2tpd systemctl status ipsec 查看ipsec状态 systemctl restart ipsec 重启 # 4. 服务器端抓包 tcpdump -i any udp and dst host 172.17.0.16 and dst port 4500 -s100 -XX -n tcpdump -i any udp and dst host 172.17.0.16 and dst port 500 -s100 -XX -n tcpdump -i any udp and dst host 172.17.0.16 and dst port 1701 -s100 -XX -n