Centos6.9安装L2TP服务器
苹果在其MAC OS、IOS系统移除了其认为不安全的VPN协议(PPTP)支持,导致公司同事无法在外网通过PPTP方式接入公司内网,无奈只好增加L2TP服务接入。
L2TP服务安装:
#epel仓库愿安装 rpm -ivh http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm #l2tp程序安装 yum install -y openswan ppp xl2tpd
L2TP服务配置修改:
setenforce 0 getenforce sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config cat <<-ENDL2TP > /etc/ipsec.d/l2tp.conf config setup nat_traversal=yes virtual_private=%v4:10.0.0.0/8,%v4:192.168.0.0/16,%v4:172.16.0.0/12 oe=off protostack=netkey conn L2TP-PSK-NAT 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=192.168.1.254 leftprotoport=17/1701 right=%any rightprotoport=17/%any ENDL2TP #添加预共享密钥 cat <<-ENDL2TPS > /etc/ipsec.d/l2tp.secrets 192.168.1.254 %any: PSK "4RFV5tgb" ENDL2TPS #添加VPN账号信息 cat <<-ENDUSER >> /etc/ppp/chap-secrets test * 123456 * ENDUSER #根据实际情况添加DNS服务器 cat <<-ENDDNS >> /etc/ppp/options.xl2tpd ms-dns 119.29.29.29 ENDDNS
vi /etc/xl2tpd/xl2tpd.conf
#修改以下参数值(注意不要和内网网段重复):ip range为客户端分配地址范围,local ip为服务端IP
ip range = 172.18.19.100-172.18.19.200
local ip = 172.18.19.1
vi /etc/sysctl.conf #添加以下内容(亲测只添加前两条服务工作依然正常)
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.all.log_martians = 0
net.ipv4.conf.default.log_martians = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.icmp_ignore_bogus_error_responses = 1
sysctl -p #重新载入配置
#配置防火墙规则
iptables -t nat -I POSTROUTING -s 172.18.19.0/24 -o eth0 -j MASQUERADE iptables -I INPUT -p udp --dport 1701 -j ACCEPT iptables -I INPUT -p udp --dport 500 -j ACCEPT iptables -I INPUT -p udp --dport 4500 -j ACCEPT iptables -I FORWARD -s 172.18.19.0/24 -j ACCEPT iptables -I FORWARD -d 172.18.19.0/24 -j ACCEPT service iptables save service iptables restart
#防火墙配置方案二:
cat <<-ENDIPS > /etc/sysconfig/iptables # Generated by iptables-save v1.4.7 on Wed Mar 27 14:33:02 2019 *nat :PREROUTING ACCEPT [0:0] :POSTROUTING ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A POSTROUTING -s 172.18.18.0/24 -o eth0 -j MASQUERADE -A POSTROUTING -s 172.18.19.0/24 -o eth0 -j MASQUERADE COMMIT # Completed on Wed Mar 27 14:33:02 2019 # Generated by iptables-save v1.4.7 on Wed Mar 27 14:33:02 2019 *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [274320:224857259] :OUTPUT ACCEPT [193686:226104944] -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -A INPUT -p tcp -m tcp --dport 1723 -j ACCEPT -A INPUT -p gre -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 53 -j ACCEPT -A INPUT -p udp -m state --state NEW -m udp --dport 53 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 1194 -j ACCEPT -A INPUT -p udp -m state --state NEW -m udp --dport 1701 -j ACCEPT -A INPUT -p udp -m state --state NEW -m udp --dport 500 -j ACCEPT -A INPUT -p udp -m state --state NEW -m udp --dport 4500 -j ACCEPT -A FORWARD -d 172.18.18.0/24 -j ACCEPT -A FORWARD -s 172.18.18.0/24 -j ACCEPT -A FORWARD -d 172.18.19.0/24 -j ACCEPT -A FORWARD -s 172.18.19.0/24 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited COMMIT # Completed on Wed Mar 27 14:33:02 2019 ENDIPS service iptables restart
#启动L2TP服务
ipsec restart /etc/init.d/xl2tpd start chkconfig xl2tpd on chkconfig ipsec on
公网防火墙端口开放规则:
PPTP需开放端口:
UDP:1723
L2TP需开放端口:
UDP:500
UDP:4500
UDP:1701
注意:端口映射时应注意协议为UDP,否则无法生效。
Centos6.9安装PPTP服务器参考链接:https://lichengxiao.cn/8.html
教主牛B