ºìÁªLinuxÃÅ»§
Linux°ïÖú

CentOS7 ´î½¨L2TP

·¢²¼Ê±¼ä:2018-03-03 22:59:09À´Ô´:ºìÁª×÷Õß:Ronny
L2TPÊÇÒ»ÖÖ¹¤Òµ±ê×¼µÄInternetËíµÀЭÒ飬¹¦ÄÜ´óÖºÍPPTPЭÒéÀàËÆ£¬±ÈÈçͬÑù¿ÉÒÔ¶ÔÍøÂçÊý¾ÝÁ÷½øÐмÓÃÜ¡£²»¹ýÒ²Óв»Í¬Ö®´¦£¬±ÈÈçPPTPÒªÇóÍøÂçΪIPÍøÂ磬L2TPÒªÇóÃæÏòÊý¾Ý°üµÄµã¶ÔµãÁ¬½Ó£»PPTPʹÓõ¥Ò»ËíµÀ£¬L2TPʹÓöàËíµÀ£»L2TPÌṩ°üͷѹËõ¡¢ËíµÀÑéÖ¤£¬¶øPPTP²»Ö§³Ö¡£±¾ÎÄÀ´½éÉÜÈçºÎ´î½¨L2TP¡£
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.¸üÐÂÒ»ÏÂÔÙ°²×°
yum install update yum update -y
4.°²×°EPELÔ´
yum install -y epel-release
5.°²×°xl2tpdºÍlibreswan
yum install -y xl2tpd libreswan lsof
6.±à¼­xl2tpdÅäÖÃÎļþ
vim /etc/xl2tpd/xl2tpd.conf
ÐÞ¸ÄÄÚÈÝÈçÏ£º
[global] [lns default] ip range = 172.100.1.100-172.100.1.150 #·ÖÅä¸ø¿Í»§¶ËµÄµØÖ·³Ø local ip = 172.100.1.1 require chap = yes refuse pap = yes require authentication = yes name = LinuxVPNserver ppp debug = yes pppoptfile = /etc/ppp/options.xl2tpd length bit = yes
7.±à¼­pppoptfileÎļþ
vim /etc/ppp/options.xl2tpd
ÐÞ¸ÄÄÚÈÝÈçÏ£º
ipcp-accept-local ipcp-accept-remote ms-dns 8.8.8.8 ms-dns 209.244.0.3 ms-dns 208.67.222.222 name xl2tpd #noccp auth crtscts idle 1800 mtu 1410 #µÚÒ»´ÎÅäÖò»½¨ÒéÉèÖÃmtu£¬mru£¬·ñÔò¿ÉÄÜ789´íÎó mru 1410 nodefaultroute debug lock proxyarp connect-delay 5000 refuse-pap refuse-chap refuse-mschap require-mschap-v2 persist logfile /var/log/xl2tpd.log
8.±à¼­ipsecÅäÖÃÎļþ
vim /etc/ipsec.confconfig setup protostack=netkey dumpdir=/var/run/pluto/ virtual_private=%v4:10.0.0.0/8,%v4:172.100.0.0/12,%v4:25.0.0.0/8,%v4:100.64.0.0/10,%v6:fd00::/8,%v6:fe80::/10 include /etc/ipsec.d/*.conf
9.±à¼­includeµÄconnÎļþ
vim /etc/ipsec.d/l2tp-ipsec.conf
ÐÞ¸ÄÄÚÈÝÈçÏ£º
conn L2TP-PSK-NAT rightsubnet=0.0.0.0/0 dpddelay=10 dpdtimeout=20 dpdaction=clear forceencaps=yes 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.0.17 #service/VPSµÄÍâÍøµØÖ·£¬Ä³Ð©vpsÖ»ÓÐeth0Ò»¿éÍø¿¨µÄ£¬ #¾ÍÌîÄÚÍøµØÖ·£¬Äں˿ªÆônatת·¢¾Í¿ÉÒÔÁË£¬ #CentOS7ÒÔϵÄÓÃiptables¶¨Òåת·¢¹æÔò leftprotoport=17/1701 right=%any rightprotoport=17/%any
10.ÉèÖÃÓû§ÃûÃÜÂë
vim /etc/ppp/chap-secrets
ÐÞ¸ÄÄÚÈÝ£º
vpnuser * pass * ˵Ã÷£ºÓû§Ãû[¿Õ¸ñ]service[¿Õ¸ñ]ÃÜÂë[¿Õ¸ñ]Ö¸¶¨IP
11.ÉèÖÃPSK
vim /etc/ipsec.d/default.secrets: PSK "testvpn"
12.CentOS7·À»ðǽÉèÖÃ
firewall-cmd --permanent --add-service=ipsec firewall-cmd --permanent --add-port=1701/udp firewall-cmd --permanent --add-port=4500/udp firewall-cmd --permanent --add-masquerade firewall-cmd --reload
13.IP_FORWARD ÉèÖÃ
vim /etc/sysctl.d/60-sysctl_ipsec.confnet.ipv4.ip_forward = 1 net.ipv4.conf.all.accept_redirects = 0 net.ipv4.conf.all.rp_filter = 0 net.ipv4.conf.all.send_redirects = 0 net.ipv4.conf.default.accept_redirects = 0 net.ipv4.conf.default.rp_filter = 0 net.ipv4.conf.default.send_redirects = 0 net.ipv4.conf.eth0.accept_redirects = 0 net.ipv4.conf.eth0.rp_filter = 0 net.ipv4.conf.eth0.send_redirects = 0 net.ipv4.conf.eth1.accept_redirects = 0 net.ipv4.conf.eth1.rp_filter = 0 net.ipv4.conf.eth1.send_redirects = 0 net.ipv4.conf.eth2.accept_redirects = 0 net.ipv4.conf.eth2.rp_filter = 0 net.ipv4.conf.eth2.send_redirects = 0 net.ipv4.conf.ip_vti0.accept_redirects = 0 net.ipv4.conf.ip_vti0.rp_filter = 0 net.ipv4.conf.ip_vti0.send_redirects = 0 net.ipv4.conf.lo.accept_redirects = 0 net.ipv4.conf.lo.rp_filter = 0 net.ipv4.conf.lo.send_redirects = 0 net.ipv4.conf.ppp0.accept_redirects = 0 net.ipv4.conf.ppp0.rp_filter = 0 net.ipv4.conf.ppp0.send_redirects = 0
ÖØÆôÉúЧ
systemctl restart network
13.ipsecÆô¶¯&¼ì²é
systemctl enable ipsec systemctl restart ipsec
¼ì²é£ºipsec verify
Õý³£Êä³ö£º
Verifying installed system and configuration files Version check and ipsec on-path [OK] Libreswan 3.15 (netkey) on 3.10.0-123.13.2.el7.x86_64 Checking for IPsec support in kernel [OK] NETKEY: Testing XFRM related proc values ICMP default/send_redirects [OK] ICMP default/accept_redirects [OK] XFRM larval drop [OK] Pluto ipsec.conf syntax [OK] Hardware random device [N/A] Two or more interfaces found, checking IP forwarding [OK] Checking rp_filter [OK] Checking that pluto is running [OK] Pluto listening for IKE on udp 500 [OK] Pluto listening for IKE/NAT-T on udp 4500 [OK] Pluto ipsec.secret syntax [OK] Checking 'ip' command [OK] Checking 'iptables' command [OK] Checking 'prelink' command does not interfere with FIPSChecking for obsolete ipsec.conf options [OK] Opportunistic Encryption [DISABLED]
14.xl2tpdÆô¶¯
systemctl enable xl2tpd systemctl restart xl2tpd
15.WindowsÁ¬½Ó
WindowsÁ¬½Ó£¬ÐèÒªÐÞ¸Ä×¢²á±í¼üÖµ£¨¾Ý˵¿ÉÒÔ²»ÓÃÐ޸ģ¬µ«ÊÇÎҵIJ»Ð޸ĵĻ°£¬Ò»Ö±789£¬logÎÞÏÔʾ£©
Ô­ÎÄÀ´×Ô£ºhttps://www.linuxprobe.com/centos7-install-l2tp.html
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 1 ÌõÆÀÂÛ

  1. Ronny ÓÚ 2018-03-03 22:59:35·¢±í:

    CentOS7 ´î½¨L2TP