原文地址:https://raymii.org/s/tutorials/IPSEC_L2TP_vpn_with_Ubuntu_14.04.html

只要保证ipsec verify没错,基本都可以成功。再也不相信一键安装,之前遇到DDos,也怀疑是不是脚本的后门。

Install ppp openswan and xl2tpd

First we will install the required packages:

第一步,安装下面的几个,配置全部默认就好。

  1. apt-get install openswan xl2tpd ppp lsof

The openswan installation will ask some questions, this tutorial works with the default answers (just enter through it).

Firewall and sysctl

We are going to set the firewall and make sure the kernel forwards IP packets:

Execute this command to enable the iptables firewall to allow vpn traffic:

  1. 第二步,%SERVERIP%自己替换成自己的服务器ip,然后配置网络参数。
  1. iptables -t nat -A POSTROUTING -j SNAT --to-source %SERVERIP% -o eth+

Replace %SERVERIP% with the external IP of your VPS. If your external interface is not named ethX (+ is a wildcard) then rename appropriately.

Execute the below commands to enable kernel IP packet forwarding and disable ICP redirects.

  1. echo "net.ipv4.ip_forward = 1" | tee -a /etc/sysctl.conf
  2. echo "net.ipv4.conf.all.accept_redirects = 0" | tee -a /etc/sysctl.conf
  3. echo "net.ipv4.conf.all.send_redirects = 0" | tee -a /etc/sysctl.conf
  4. echo "net.ipv4.conf.default.rp_filter = 0" | tee -a /etc/sysctl.conf
  5. echo "net.ipv4.conf.default.accept_source_route = 0" | tee -a /etc/sysctl.conf
  6. echo "net.ipv4.conf.default.send_redirects = 0" | tee -a /etc/sysctl.conf
  7. echo "net.ipv4.icmp_ignore_bogus_error_responses = 1" | tee -a /etc/sysctl.conf

Set these settings for other network interfaces:

  1. for vpn in /proc/sys/net/ipv4/conf/*; do echo 0 > $vpn/accept_redirects; echo 0 > $vpn/send_redirects; done

Apply them:

  1. sysctl -p
Persistent settings via /etc/rc.local

To make sure this keeps working at boot you might want to add the following to /etc/rc.local:

  1. for vpn in /proc/sys/net/ipv4/conf/*; do echo 0 > $vpn/accept_redirects; echo 0 > $vpn/send_redirects; done
  2. iptables -t nat -A POSTROUTING -j SNAT --to-source %SERVERIP% -o eth+

Add it before the exit 0 line and replace %SERVERIP% with the external IP of your VPS.

Configure Openswan (IPSEC)

Use your favorite editor to edit the following file:

  1. /etc/ipsec.conf
  2. 到这一步可以直接到我下面的配置了,注意把/etc/ipsec.confip换成你自己的服务器IP
  1. Replace the contents with the following:
  2.  
  3. (Most lines have a comment below it explaining what it does.)
  4.  
  5. version 2 # conforms to second version of ipsec.conf specification
  6.  
  7. config setup
  8. dumpdir=/var/run/pluto/
  9. #in what directory should things started by setup (notably the Pluto daemon) be allowed to dump core?
  10.  
  11. nat_traversal=yes
  12. #whether to accept/offer to support NAT (NAPT, also known as "IP Masqurade") workaround for IPsec
  13.  
  14. virtual_private=%v4:10.0.0.0/8,%v4:192.168.0.0/16,%v4:172.16.0.0/12,%v6:fd00::/8,%v6:fe80::/10
  15. #contains the networks that are allowed as subnet= for the remote client. In other words, the address ranges that may live behind a NAT router through which a client connects.
  16.  
  17. protostack=netkey
  18. #decide which protocol stack is going to be used.
  19.  
  20. force_keepalive=yes
  21. keep_alive=60
  22. # Send a keep-alive packet every 60 seconds.
  23.  
  24. conn L2TP-PSK-noNAT
  25. authby=secret
  26. #shared secret. Use rsasig for certificates.
  27.  
  28. pfs=no
  29. #Disable pfs
  30.  
  31. auto=add
  32. #the ipsec tunnel should be started and routes created when the ipsec daemon itself starts.
  33.  
  34. keyingtries=3
  35. #Only negotiate a conn. 3 times.
  36.  
  37. ikelifetime=8h
  38. keylife=1h
  39.  
  40. ike=aes256-sha1,aes128-sha1,3des-sha1
  41. phase2alg=aes256-sha1,aes128-sha1,3des-sha1
  42. # https://lists.openswan.org/pipermail/users/2014-April/022947.html
  43. # specifies the phase 1 encryption scheme, the hashing algorithm, and the diffie-hellman group. The modp1024 is for Diffie-Hellman 2. Why 'modp' instead of dh? DH2 is a 1028 bit encryption algorithm that modulo's a prime number, e.g. modp1028. See RFC 5114 for details or the wiki page on diffie hellmann, if interested.
  44.  
  45. type=transport
  46. #because we use l2tp as tunnel protocol
  47.  
  48. left=%SERVERIP%
  49. #fill in server IP above
  50.  
  51. leftprotoport=17/1701
  52. right=%any
  53. rightprotoport=17/%any
  54.  
  55. dpddelay=10
  56. # Dead Peer Dectection (RFC 3706) keepalives delay
  57. dpdtimeout=20
  58. # length of time (in seconds) we will idle without hearing either an R_U_THERE poll from our peer, or an R_U_THERE_ACK reply.
  59. dpdaction=clear
  60. # When a DPD enabled peer is declared dead, what action should be taken. clear means the eroute and SA with both be cleared.
  61. Replace %SERVERIP% with the external IP of your server. You can find it out by:
  62.  
  63. curl http://ip.mtak.nl
  64. Do note that the config file has changed with this Ubuntu release. If you have upgraded Ubuntu or followed an earlier tutorial, make sure you change the config for ipsec.
  65.  
  66. The shared secret
  67.  
  68. The shared secret is defined in the /etc/ipsec.secrets file. Make sure it is long and random:
  69.  
  70. %SERVERIP% %any: PSK "69EA16F2C529E74A7D1B0FE99E69F6BDCD3E44"
  71. Yet again, replace %SERVERIP% with the IP of your server here. If you want to generate a random key you can use the following openssl command:
  72.  
  73. openssl rand -hex 30
  74. Example output:
  75.  
  76. c12cf75b47c210b9d7094ce10e3b3544c6927ff49ca2d949252b5a94ccf5
  77. Verify IPSEC Settings
  78.  
  79. Now to make sure IPSEC works, execute the following command:
  80.  
  81. ipsec verify
  82. My output looks like this:
  83.  
  84. Checking your system to see if IPsec got installed and started correctly:
  85. Version check and ipsec on-path [OK]
  86. Linux Openswan U2.6.38/K3.13.0-24-generic (netkey)
  87. Checking for IPsec support in kernel [OK]
  88. SAref kernel support [N/A]
  89. NETKEY: Testing XFRM related proc values [OK]
  90. [OK]
  91. [OK]
  92. Checking that pluto is running [OK]
  93. Pluto listening for IKE on udp 500 [OK]
  94. Pluto listening for NAT-T on udp 4500 [OK]
  95. Checking for 'ip' command [OK]
  96. Checking /bin/sh is not /bin/dash [WARNING]
  97. Checking for 'iptables' command [OK]
  98. Opportunistic Encryption Support [DISABLED]
  99. The /bin/sh and Opportunistic Encryption warnings can be ignored. The first one is a openswan bug and the second one causes xl2tpd to trip.
  100.  
  101. Configure xl2tpd
  102.  
  103. Use your favorite editor to edit the following file:
  104.  
  105. /etc/xl2tpd/xl2tpd.conf
  106. Replace the contents with the following:
  107.  
  108. [global]
  109. ipsec saref = yes
  110. saref refinfo = 30
  111.  
  112. ;debug avp = yes
  113. ;debug network = yes
  114. ;debug state = yes
  115. ;debug tunnel = yes
  116.  
  117. [lns default]
  118. ip range = 172.16.1.30-172.16.1.100
  119. local ip = 172.16.1.1
  120. refuse pap = yes
  121. require authentication = yes
  122. ;ppp debug = yes
  123. pppoptfile = /etc/ppp/options.xl2tpd
  124. length bit = yes
  125. ip range = range of IPs to give to the connecting clients
  126. local ip = IP of VPN server
  127. refuse pap = refure pap authentication
  128. ppp debug = yes when testing, no when in production
  129. Local user (PAM / /etc/passwd) authentication
  130.  
  131. To use local user accounts via pam (or /etc/passwd), and thus not having plain text user passwords in a text file you have to do a few extra steps.
  132.  
  133. In your /etc/xl2tpd/xl2tpd.conf add the following line:
  134.  
  135. unix authentication = yes
  136. and remove the following line:
  137.  
  138. refuse pap = yes
  139. In the file /etc/ppp/options.xl2tpd make sure you do not add the following line (below it states to add it, but not if you want to use UNIX authentication):
  140.  
  141. require-mschap-v2
  142. Also in that file (/etc/ppp/options.xl2tpd) add the following extra line:
  143.  
  144. login
  145. Change /etc/pam.d/ppp to this:
  146.  
  147. auth required pam_nologin.so
  148. auth required pam_unix.so
  149. account required pam_unix.so
  150. session required pam_unix.so
  151. (As in, remove existing lines and add these)
  152.  
  153. Add the following to /etc/ppp/pap-secrets:
  154.  
  155. * l2tpd "" *
  156. (And, skip the chap-secrets file below (adding users).)
  157.  
  158. Configuring PPP
  159.  
  160. Use your favorite editor to edit the following file:
  161.  
  162. /etc/ppp/options.xl2tpd
  163. Replace the contents with the following:
  164.  
  165. require-mschap-v2
  166. ms-dns 8.8.8.8
  167. ms-dns 8.8.4.4
  168. auth
  169. mtu 1200
  170. mru 1000
  171. crtscts
  172. hide-password
  173. modem
  174. name l2tpd
  175. proxyarp
  176. lcp-echo-interval 30
  177. lcp-echo-failure 4
  178. ms-dns = The dns to give to the client. I use googles public DNS.
  179. proxyarp = Add an entry to this systems ARP [Address Resolution Protocol] table with the IP address of the peer and the Ethernet address of this system. This will have the effect of making the peer appear to other systems to be on the local ethernet.
  180. name l2tpd = is used in the ppp authentication file.
  181. Adding users
  182.  
  183. Every user should be defined in the /etc/ppp/chap-secrets file. Below is an example file.
  184.  
  185. # Secrets for authentication using CHAP
  186. # client server secret IP addresses
  187. alice l2tpd 0F92E5FC2414101EA *
  188. bob l2tpd DF98F09F74C06A2F *
  189. client = username for the user
  190. server = the name we define in the ppp.options file for xl2tpd
  191. secret = password for the user
  192. IP Addresses = leave to * for any address or define addresses from were a user can login.
  193. Testing it
  194.  
  195. To make sure everything has the newest config files restart openswan and xl2tpd:
  196.  
  197. /etc/init.d/ipsec restart
  198. /etc/init.d/xl2tpd restart
  199. On the client connect to the server IP address (or add a DNS name) with a valid user, password and the shared secret. Test if you have internet access and which IP you have (via for example http://whatsmyip.org. If it is the VPN servers IP then it works.
  200.  
  201. If you experience problems make sure to check the client log files and the ubuntu /var/log/syslog and /var/log/auth.log files. If you google the error messages you most of the time get a good answer.

原文内容

最后是我的配置,我的配置跟上面的有不同的。现在的运行环境是(ubuntu 14.04 LTS)

ipsec.conf

  1. version 2.0
  2.  
  3. config setup
  4. dumpdir=/var/run/pluto/
  5. nat_traversal=yes
  6. virtual_private=%v4:10.0.0.0/,%v4:192.168.0.0/,%v4:172.16.0.0/,%v4:!192.168.42.0/
  7. oe=off
  8. protostack=netkey
  9. nhelpers=
  10. interfaces=%defaultroute
  11.  
  12. conn vpnpsk
  13. connaddrfamily=ipv4
  14. auto=add
  15. left=108.61.180.230
  16. leftid=108.61.180.230
  17. leftprotoport=/
  18. rightprotoport=/%any
  19. right=%any
  20. rightsubnetwithin=0.0.0.0/
  21. forceencaps=yes
  22. authby=secret
  23. pfs=no
  24. type=transport
  25. auth=esp
  26. ike=3des-sha1,aes-sha1
  27. phase2alg=3des-sha1,aes-sha1
  28. rekey=no
  29. keyingtries=
  30. dpddelay=
  31. dpdtimeout=
  32. dpdaction=clear

rc.local

  1. #!/bin/sh -e
  2. #
  3. # rc.local
  4. #
  5. # This script is executed at the end of each multiuser runlevel.
  6. # Make sure that the script will "exit 0" on success or any other
  7. # value on error.
  8. #
  9. # In order to enable or disable this script just change the execution
  10. # bits.
  11. #
  12. # By default this script does nothing.
  13. /usr/sbin/service ipsec restart
  14. /usr/sbin/service xl2tpd restart
  15.  
  16. ssserver -c /etc/shadowsocks.json -d start # ss开机启动
  17. exit

optios.xl2tpd

  1. ipcp-accept-local
  2. ipcp-accept-remote
  3. ms-dns 8.8.8.8
  4. ms-dns 8.8.4.4
  5. noccp
  6. auth
  7. crtscts
  8. idle
  9. mtu
  10. mru
  11. lock
  12. lcp-echo-failure
  13. lcp-echo-interval
  14. connect-delay

xl2tpd.config

  1. [global]
  2. port =
  3.  
  4. ;debug avp = yes
  5. ;debug network = yes
  6. ;debug state = yes
  7. ;debug tunnel = yes
  8.  
  9. [lns default]
  10. ip range = 192.168.42.10-192.168.42.250
  11. local ip = 192.168.42.1
  12. require chap = yes
  13. refuse pap = yes
  14. require authentication = yes
  15. name = l2tpd
  16. ;ppp debug = yes
  17. pppoptfile = /etc/ppp/options.xl2tpd
  18. length bit = yes

设置VPN帐号 /etc/ppp/chap-secrets

  1. # Secrets for authentication using CHAP
  2. # client server secret IP addresses
  3. alice l2tpd 0F92E5FC2414101EA *
  4. bob l2tpd DF98F09F74C06A2F *

设置共享密钥 /etc/ipsec.secrets

  1. YOUR_SERVER_IP %any: PSK "www.coolicer.com"

VPS L2TP配置的更多相关文章

  1. 亚马逊云服务器VPS Amazon EC2 免费VPS主机配置CentOS及其它内容

    Amazon目前提供为期一年的免费VPS服务,可到地址http://aws.amazon.com 进行申请. 现在对账号申请成功后,对VPS主机配置CentOS的过程做个图文介绍 1.创建实例(Ins ...

  2. VPS安全配置

    VPS安全配置 购买VPS后重装操作系统,以windows server 2008为例. 1 登录服务器 重装操作系统后,第一时间登录服务器,迅速进行安全配置. VPN-->Remote Des ...

  3. 【记录】haphost免费vps初始配置

    1.配置德国epel源 yum install yum-priorities rpm -Uvh http://ftp-stud.hs-esslingen.de/pub/epel/6/i386/epel ...

  4. VPS环境配置预备篇

    VPS买到手了,在配置环境前要做哪些操作呢?老谢说一下自己的习惯,希望对和老谢一样的菜鸟有帮助更新系统内核和rpm包#安装yum-fastestmirror插件yum -y install yum-f ...

  5. Ubuntu 14.04 VPS安装配置***的方法

    #安装*** $ sudo apt-get update $ sudo apt-get install python-gevent python-pip $ sudo pip install shad ...

  6. pfsense 2.2RC下的L2TP配置

    还不有测试完成,不过,基本上应该差不多了. 主要参考以下文档: http://blog.sina.com.cn/s/blog_541a3cf10101ard3.html http://thepract ...

  7. 2014.1.23 Discuz论坛迁移+VPS配置手记

    虽说这也不是我第一次转移这个论坛了,但毕竟还是第一次自己配置VPS,写点东西记一下 一:关于VPS的配置 1.用TeamViewer连接服务器 这个VPS的IDC自己带有一个远程控制的页面,用浏览器打 ...

  8. Ubuntu下配置L2TP

    发现PPTP已经不可用了,不知是不是又被墙了.只能尝试L2TP了. Ubuntu可视化配置界面network-manager默认是没有L2TP配置选项的,需要安装第三方插件软件: sudo apt-a ...

  9. 初识vps,域名与购买,初步配置

    终于还是到了这一天,不管我们是不是程序员,当我们想拥有自己的一个的博客,当我们想有自己的一个空间,当我们想在网上有一个自己可以随心所欲编写任何不被限制的仅仅是酷炫的效果,当我们想收录自己的技术,经历, ...

随机推荐

  1. HUAS 1477 经营与开发(贪心)

    考虑DP,令dp[i][j][k]当前在第i个星球,用了j次维修,k次开采后所获得的最大价值.复杂度为O(n^3).超时 如果我们发现,对于初始时能力值为w所能产生的最大价值y,初始时能力值为1所能产 ...

  2. Java语言有哪些特点?

    1)简单 如果同学们学过C++语言,就会感觉Java眼熟,因为Java中许多基本语句的语法和C++是一样的,像常用的循环语句.控制语句等和C++几乎相同.需要注意的是,Java和C++时两种完全不同的 ...

  3. (转)java +libsvm 安装与测试:

    libsvm 用SVM实现简单线性分类  (转自:http://www.cnblogs.com/freedomshe/archive/2012/10/09/2717356.html) 0. 下载lib ...

  4. [洛谷P5057][CQOI2006]简单题

    题目大意:有一个长度为$n$的$01$串,两个操作: $1\;l\;r:$把区间$[l,r]$翻转($0->1,1->0$) $2\;p:$求第$p$位是什么 题解:维护前缀异或和,树状数 ...

  5. UVA.10305 Ordering Tasks (拓扑排序)

    UVA.10305 Ordering Tasks 题意分析 详解请移步 算法学习 拓扑排序(TopSort) 拓扑排序的裸题 基本方法是,indegree表示入度表,vector存后继节点.在tops ...

  6. sass的颜色函数

    sass中有些非常实用的颜色处理函数,总结如下 1.颜色加深或变浅 lighten($color,$amount) //颜色变浅 darken($color,$amount) //颜色加深 例如: l ...

  7. NOIP2015Day2T2子串(字符串dp)

    又被“if(a=b)”坑了QAQ...写C++还是得开Warning,这么久了pascal还没改过来咋回事啊QWQ 题目大意就不说了OWO 网上的题解都不怎么看得懂啊...好像写得都很乱?还是我太sb ...

  8. mysql五补充部分:SQL逻辑查询语句执行顺序

    一 SELECT语句关键字的定义顺序 SELECT DISTINCT <select_list> FROM <left_table> <join_type> JOI ...

  9. Efficient Deblurring for Shaken and Partially Saturated Images

    Try the online demo: http://willow-fd.rocq.inria.fr/unshake/ Overview One common feature of “shaken” ...

  10. GYM 101875 2018 USP-ICMC

    3月自训 (1):10/12 A: 题意:每个人可以连边,最远连到第(i+k)%n个人,边权为这个人与另一个人连边距离,求生成一颗最大生成树的权值和是多少 题解:可以证明的是,我们每一个人都向接下来的 ...