1. CentOS Linux VPS安装IPSec+L2TP VPN
  2.  
  3. 时间 -- :: 天使羊波波闪耀光芒 相似文章 ()
  4. 原文 http://www.live-in.org/archives/818.html
  5. 第二层隧道协议L2TP(Layer Tunneling Protocol)是一种工业标准的Internet隧道协议,它使用UDP1701端口进行通信。L2TP本身并没有任何加密,但是我们可以使用IPSecL2TP包进行加密。L2TP VPNPPTP VPN搭建复杂一些。
  6.  
  7. 一、安装IPsecOpenswanLinux系统上IPsec的一个实现。
  8. 官网: http://www.openswan.org/
  9.  
  10. 、安装必备软件:
  11.  
  12. yum -y install make gcc gmp-devel bison flex lsof xmlto;
  13.  
  14. makegcc我们都知道是干什么用的了。
  15. gmp-devel: Development tools for the GNU MP arbitrary precision library.
  16. bison: A GNU general-purpose parser generator.
  17. flex: A tool for creating scanners (text pattern recognizers).
  18. 看上去好像都和编译器有关?
  19.  
  20. 、安装Openswan
  21. 由于更新源上的版本是2..el5_6.4较老,这里使用源码安装,目前最新版是2.6.35
  22.  
  23. cd /tmp
  24. wget https://download.openswan.org/openswan//old/openswan-2.6/openswan-2.6.21.tar.gz
  25. tar -zxvf openswan-.tar.gz
  26. cd openswan-
  27. make programs install
  28.  
  29. PS:进openswan-2.6.21目录看到已经有Makefile文件了,阅读目录内的INSTALL写着
  30. Building userland:
  31.  
  32. make programs install
  33.  
  34. 、配置IPSec
  35. 编辑配置文件/etc/ipsec.conf
  36.  
  37. cp /etc/ipsec.conf /etc/ipsec.conf.bak
  38. vim /etc/ipsec.conf
  39.  
  40. 查找protostack=auto,修改为:
  41.  
  42. protostack=netkey
  43.  
  44. 在最后加入:
  45.  
  46. conn L2TP-PSK-NAT
  47. rightsubnet=vhost:%priv
  48. also=L2TP-PSK-noNAT
  49.  
  50. conn L2TP-PSK-noNAT
  51. authby=secret
  52. pfs=no
  53. auto=add
  54. keyingtries=
  55. rekey=no
  56. ikelifetime=8h
  57. keylife=1h
  58. type=transport
  59. left=YOUR.SERVER.IP.ADDRESS
  60. leftprotoport=/
  61. right=%any
  62. rightprotoport=/%any
  63. YOUR.SERVER.IP.ADDRESS”换成VPS的外网IP。其中一些设置含义可以参考/etc/ipsec.d/examples/l2tp-psk.conf文件的内容。
  64.  
  65. 、设置共享密钥PSK
  66. 编辑配置文件/etc/ipsec.secrets
  67.  
  68. vim /etc/ipsec.secrets
  69.  
  70. 输入:
  71.  
  72. YOUR.SERVER.IP.ADDRESS %any: PSK "YourSharedSecret"
  73.  
  74. 、修改包转发设置
  75. 复制以下两段代码在终端里运行:
  76.  
  77. for each in /proc/sys/net/ipv4/conf/*
  78. do
  79. echo 0 > $each/accept_redirects
  80. echo 0 > $each/send_redirects
  81. done
  82.  
  83. echo 1 >/proc/sys/net/core/xfrm_larval_drop
  84.  
  85. 修改内核设置,使其支持转发,编辑/etc/sysctl.conf文件:
  86.  
  87. vim /etc/sysctl.conf
  88.  
  89. 将“net.ipv4.ip_forward”的值改为1。
  90.  
  91. 使修改生效:
  92.  
  93. sysctl -p
  94.  
  95. 6、重启IPSec:
  96.  
  97. /etc/init.d/ipsec restart
  98.  
  99. 查看系统IPSec安装和启动的正确性:
  100.  
  101. ipsec verify
  102.  
  103. 没有报[FAILED]就可以了。
  104.  
  105. 我用的这个VPS结果显示如下:
  106.  
  107. 二、安装L2TP(xl2tpd和rp-l2tp)
  108. xl2tpd是由Xelerance Corporation维护的l2tpd应用。但是xl2tpd没有l2tp-control,需要从rp-l2tp这个里面提取。所以要装这两个软件包。
  109.  
  110. 1、安装必备软件:
  111.  
  112. yum install libpcap-devel ppp policycoreutils
  113.  
  114. 2、安装xl2tpd和rp-l2tp:
  115.  
  116. cd /tmp
  117. wget http://sourceforge.net/projects/rp-l2tp/files/rp-l2tp/0.4/rp-l2tp-0.4.tar.gz
  118. tar -zxvf rp-l2tp-0.4.tar.gz
  119. cd rp-l2tp-0.4
  120. ./configure
  121. make
  122. cp handlers/l2tp-control /usr/local/sbin/
  123. mkdir /var/run/xl2tpd/
  124. ln -s /usr/local/sbin/l2tp-control /var/run/xl2tpd/l2tp-control
  125.  
  126. xl2tpd用的是目前最新的xl2tpd-1.3.0:
  127.  
  128. cd /tmp
  129. wget http://www.xelerance.com/wp-content/uploads/software/xl2tpd/xl2tpd-1.3.0.tar.gz
  130. tar -zxvf xl2tpd-1.3.0.tar.gz
  131. cd xl2tpd-1.3.0
  132. make
  133. make install
  134.  
  135. 显示安装了如下一些内容:
  136.  
  137. 3、建立xl2tpd配置文件:
  138.  
  139. mkdir /etc/xl2tpd
  140. vim /etc/xl2tpd/xl2tpd.conf
  141.  
  142. 加入:
  143.  
  144. [global]
  145. ipsec saref = yes
  146.  
  147. [lns default]
  148. ip range = 10.82.88.2-10.82.88.254
  149. local ip = 10.82.88.1
  150. refuse chap = yes
  151. refuse pap = yes
  152. require authentication = yes
  153. ppp debug = yes
  154. pppoptfile = /etc/ppp/options.xl2tpd
  155. length bit = yes
  156.  
  157. 4、配置ppp
  158. 建立options.xl2tpd文件:
  159.  
  160. vim /etc/ppp/options.xl2tpd
  161.  
  162. 加入:
  163.  
  164. require-mschap-v2
  165. ms-dns 8.8.8.8
  166. ms-dns 8.8.4.4
  167. asyncmap 0
  168. auth
  169. crtscts
  170. lock
  171. hide-password
  172. modem
  173. debug
  174. name l2tpd
  175. proxyarp
  176. lcp-echo-interval 30
  177. lcp-echo-failure 4
  178.  
  179. 5、设置拨号用户名和密码:
  180.  
  181. vim /etc/ppp/chap-secrets
  182.  
  183. 6、添加iptables转发规则:
  184.  
  185. iptables --table nat --append POSTROUTING --jump MASQUERADE
  186.  
  187. iptables -t nat -A POSTROUTING -s 10.1.2.0/24 -o eth1 -j MASQUERADE
  188. iptables -I FORWARD -s 10.1.2.0/24 -j ACCEPT
  189. iptables -I FORWARD -d 10.1.2.0/24 -j ACCEPT
  190. /etc/init.d/iptables save
  191. service iptables restart
  192.  
  193. 保存iptables转发规则:
  194.  
  195. /etc/init.d/iptables save
  196.  
  197. 重启iptables:
  198.  
  199. /etc/init.d/iptables restart
  200.  
  201. 7、以debug方式启动l2tp,查看有无错误:
  202.  
  203. xl2tpd -D
  204.  
  205. 显示如下:
  206. xl2tpd[9647]: Enabling IPsec SAref processing for L2TP transport mode SAs
  207. xl2tpd[9647]: IPsec SAref does not work with L2TP kernel mode yet, enabling forceuserspace=yes
  208. xl2tpd[9647]: setsockopt recvref[22]: Protocol not available
  209. xl2tpd[9647]: This binary does not support kernel L2TP.
  210. xl2tpd[9647]: xl2tpd version xl2tpd-1.3.0 started on myserver.localdomain PID:9647
  211. xl2tpd[9647]: Written by Mark Spencer, Copyright (C) 1998, Adtran, Inc.
  212. xl2tpd[9647]: Forked by Scott Balmos and David Stipp, (C) 2001
  213. xl2tpd[9647]: Inherited by Jeff McAdams, (C) 2002
  214. xl2tpd[9647]: Forked again by Xelerance (www.xelerance.com) (C) 2006
  215. xl2tpd[9647]: Listening on IP address 0.0.0.0, port 1701
  216. 说明已经在监听端口了。现在可以在windows上建立L2TP拨号连接了。
  217.  
  218. 三、设置开机启动
  219.  
  220. vim /etc/rc.local
  221.  
  222. 加入:
  223.  
  224. for each in /proc/sys/net/ipv4/conf/*
  225. do
  226. echo 0 > $each/accept_redirects
  227. echo 0 > $each/send_redirects
  228. done
  229.  
  230. echo 1 >/proc/sys/net/core/xfrm_larval_drop
  231.  
  232. /etc/init.d/ipsec restart
  233.  
  234. /usr/local/sbin/xl2tpd
  235.  
  236. 四、建立连接时遇到的问题
  237. windows下新建一个VPN连接,属性-网络-VPN类型选择L2TP IPSec VPN,安全-IPSec设置-输入共享密钥。
  238.  
  239. 提示“错误 768:因为加密数据失败连接尝试失败。”
  240. IPSEC services被关掉了。开始-运行-输入services.msc,然后在服务中启用“IPSEC services”即可。
  241.  
  242. 参考资料:
  243. http://hi.baidu.com/wzypunk/blog/item/4566903cf418663b96ddd8b0.html
  244. http://www.wifay.com/blog/2010/08/21/centos-install-ipsec-l2tp-vpn/
 

CentOS Linux VPS安装IPSec+L2TP VPN的更多相关文章

  1. CENTOS/UBUNTU一键安装IPSEC/IKEV2 VPN服务器

    1.在azure上创建ubuntu虚拟机 选择v15.04 server 版本 2.添加端口号 3.远程桌面到ubuntu 命令行 输入 sudo su  输入创建 ubuntu虚拟机 时候的 密码 ...

  2. setting up a IPSEC/L2TP vpn on CentOS 6 or Red Hat Enterprise Linux 6 or Scientific Linux

    This is a guide on setting up a IPSEC/L2TP vpn on CentOS 6 or Red Hat Enterprise Linux 6 or Scientif ...

  3. CentOS linux下安装和配置Apache+SVN(用浏览器http方式访问SVN目录)

    在CentOS linux下安装SVN,我们可以进行以下步骤: 第一步:安装CentOS Linux操作系统,并在CentOS安装进行的同时,自定义安装这一步,一定要勾选Subversion(在“开发 ...

  4. VMware ESXi CentOS Linux虚拟机安装VMware Tools教

    转自VMware ESXi CentOS Linux虚拟机安装VMware Tools教程 | 一米居 http://www.yimiju.com/articles/548.html 最近一周在学习和 ...

  5. CentOS Linux 系统 安装oracle 11g

    CentOS Linux 系统 安装oracle 11g 在Linux系统上安装oracle是比较麻烦,需要配置各种变量啥的,o(︶︿︶)o ,但是没办法,有些东西你总的去接触,而且接触理解的越早越深 ...

  6. CentOS Linux上安装Oracle11g笔记

    CentOS Linux上安装Oracle11g 到 otn.oracle.com 网站上下载 Linux版的oracle 11g 编辑 /etc/sysctl.conf : kernel.shmal ...

  7. CentOS Linux 7 安装教程

    建立新的虚拟机 将CentOS 7 ISO文件插入到CD-Rom 启动虚拟机,F12选择启动方式为CD/DVD 选择Install CentOS Linux 7 加载安装必要文件 选择安装过程所显示的 ...

  8. CentOS Linux 安装IPSec+L2TP

    第二层隧道协议L2TP(Layer 2 Tunneling Protocol)是一种工业标准的Internet隧道协议,它使用UDP的1701端口进行通信.L2TP本身并没有任何加密,但是我们可以使用 ...

  9. linux vps安装kloxo配置全部过程

    第一步如何登录Linux VPS进行远程(SSH)管理 很多人可能用过免费虚拟主机,但绝没有用过好用的免费服务器租用,仅有的少数免费服务器都只针对有较高访问量的大站(以交换广告为条件),而普通小站是无 ...

随机推荐

  1. Error: [$rootScope:inprog] $digest already in progress

    我在 做一个 服务器分配成功以后需要更新 整个页面,我的思路是 更新成功以后,就手动的 触发一下 搜索按钮,但是在触发后,虽然成功刷新了页面,但是出现了一个 错误提示, Error: [$rootSc ...

  2. 2014-10-2 bug更新5 ecshop和ectouch解决动态ip登录超时和购物车清空问题

    有客户说登陆网站后台操作的时候,会时不时的掉一下,要重新登陆才能继续操作,自动登出的频率快和时间短,针对这个问题是因为: 购物车问题原因的产生是因为动态IP的SESSEION机制导致很多在公司或者其他 ...

  3. jQuery 互相调用iframe页面中js的方法

    1,子iframe内调用父类函数方法: window.parent.func(); 2,子Iframe中获取父界面的元素: $("#xx", window.parent.docum ...

  4. Spring--Spring容器

    在使用Spring所提供的各种丰富而神奇的功能之前,必须要在Spring IoC容器中装配好Bean,并建立Bean和Bean之间的关联关系. Spring提供了多种配置方式来实现Bean的装配.但在 ...

  5. Thinkphp 模板中直接对数据处理 模板中使用函数 中文字符串截取

    1.Thinkphp 模板中直接对数据处理:{$data.name|substr=0,3} 2.中文字符串截取函数:mb_substr=0,14,'utf-8' 3.中文字符串统计:iconv_str ...

  6. 今天是JQ 的slideUp 和 slideDown 的点击事件

    先贴代码,再讲详细事件 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> & ...

  7. firefox的plugin-container.exe进程如何关闭?

    为什么要关闭container进程? 查看firefox所消耗的资源: ff本身: cpu一般是0-10%, 内存一般是400MB左右 plugin-container: cpu所占的比例很高, 可达 ...

  8. 关于Mysql错误:./bin/mysqld_safe --user=mysql& [1] 32710 121003 16:40:22 mysqld_safe Logging to '/var/log/mysqld.log'. 121003 16:40:22 mysqld_s

    [root@www]# ./bin/mysqld_safe --user=mysql&[1] 32710[root@www]# 121003 16:40:22 mysqld_safe Logg ...

  9. QS2016年全球高等教育系统实力排名 中国排名世界第八亚洲第一

    2016年5月18日,QS发布"2016年全球高等教育系统实力排名",中国在此榜单表现优异,排名世界第八亚洲第一. 排名指标 排名指标及计算方法如下: 系统实力:QS大学排名前70 ...

  10. linux下gedit读取txt乱码解决办法

    修改一下gedit的设置来让它显示的txt不再是乱码: 你可以通过以下步骤,使 gedit 正确显示中文编码文件. 按下 Alt-F2,打开“运行应用程序”对话框.在文本框中键入“gconf-edit ...