1.一些预先准备的环境

  1. yum install -y make gcc gmp-devel xmlto bison flex xmlto libpcap-devel lsof vim-enhanced man

复制代码

2.安装

  1. yum install openswan ppp xl2tpd

复制代码

3.配置

(1)编辑 /etc/ipsec.conf

  1. vi  /etc/ipsec.conf

复制代码

替换为如下内容,把下面0.0.0.0换成腾讯云服务器的外网IP,其他的不用修改。
注意:第一行两个**的地方是s e t u(自行更改,字母之间无空格)

  1. config setup
  2. nat_traversal=yes
  3. virtual_private=%v4:10.0.0.0/8,%v4:192.168.0.0/16,%v4:172.16.0.0/12
  4. oe=off
  5. protostack=netkey
  6. conn L2TP-PSK-NAT
  7. rightsubnet=vhost:%priv
  8. also=L2TP-PSK-noNAT
  9. conn L2TP-PSK-noNAT
  10. authby=secret
  11. pfs=no
  12. auto=add
  13. keyingtries=3
  14. rekey=no
  15. ikelifetime=8h
  16. keylife=1h
  17. type=transport
  18. left=0.0.0.0
  19. leftprotoport=17/1701
  20. right=%any
  21. rightprotoport=17/%any

复制代码

(2)编辑/etc/ipsec.secrets

  1. vi /etc/ipsec.secrets
  2. include /etc/ipsec.d/*.secrets
  3. 0.0.0.0 %any: PSK "YourPsk"

复制代码

0.0.0.0换成腾讯云服务器的外网IP, YourPsk你自己定一个。

(3) 修改/添加 /etc/sysctl.conf并生效

  1. vim /etc/sysctl.conf

复制代码

在/etc/sysctl.conf的末尾加上如下内容。

  1. net.ipv4.ip_forward = 1
  2. net.ipv4.conf.default.rp_filter = 0
  3. net.ipv4.conf.all.send_redirects = 0
  4. net.ipv4.conf.default.send_redirects = 0
  5. net.ipv4.conf.all.log_martians = 0
  6. net.ipv4.conf.default.log_martians = 0
  7. net.ipv4.conf.default.accept_source_route = 0
  8. net.ipv4.conf.all.accept_redirects = 0
  9. net.ipv4.conf.default.accept_redirects = 0
  10. net.ipv4.icmp_ignore_bogus_error_responses = 1

复制代码

生效上面的修改使用如下命令

  1. sysctl -p

复制代码

(4)验证ipsec运行状态

  1. ipsec restart
  2. ipsec verify

复制代码

如果出现如下内容,说明已经成功

  1. Checking your system to see if IPsec got installed and started correctly:
  2. Version check and ipsec on-path                                 [OK]
  3. Linux Openswan U2.6.32/K2.6.32-431.20.3.0.1.el6.centos.plus.x86_64 (netkey)
  4. Checking for IPsec support in kernel                            [OK]
  5. SAref kernel support                                           [N/A]
  6. NETKEY:  Testing for disabled ICMP send_redirects              [OK]
  7. NETKEY detected, testing for disabled ICMP accept_redirects     [OK]
  8. Checking that pluto is running                                  [OK]
  9. Pluto listening for IKE on udp 500                             [OK]
  10. Pluto listening for NAT-T on udp 4500                          [OK]
  11. Checking for 'ip' command                                       [OK]
  12. Checking /bin/sh is not /bin/dash                               [OK]
  13. Checking for 'iptables' command                                 [OK]
  14. Opportunistic Encryption Support                                [DISABLED]

复制代码

(5) 编辑 /etc/xl2tpd/xl2tpd.conf  这一步可以跳过
ip range 写客户端的内网IP段,local ip写客户端内网IP

  1. vim /etc/xl2tpd/xl2tpd.conf
  2. [lns default]
  3. ip range = 10.3.154.192-10.3.154.254
  4. local ip = 10.3.154.202
  5. require chap = yes
  6. refuse pap = yes
  7. require authentication = yes
  8. name = LinuxVPNserver
  9. ppp debug = yes
  10. pppoptfile = /etc/ppp/options.xl2tpd
  11. length bit = yes

复制代码

(6)配置用户名,密码:编辑 /etc/ppp/chap-secrets

  1. vim /etc/ppp/chap-secrets

复制代码

username 写登录vpn的用户名,userpass 写登录vpn的密码

  1. # Secrets for authentication using CHAP
  2. # client        server  secret                  IP addresses
  3. username * "userpass" *

复制代码

(7)重启xl2tp

  1. service xl2tpd restart

复制代码

(8)添加自启动

  1. chkconfig xl2tpd on
  2. chkconfig iptables on
  3. chkconfig ipsec on

复制代码

接下来就是你通过电脑连接vpn

iptables -t nat -A POSTROUTING -s 192.168.20.0/24 -j SNAT --to-source 47.88.104.108
service iptables save
service iptables restart
/etc/init.d/iptables status
iptables -t nat -D POSTROUTING 1
service iptables save
service iptables restart
/etc/init.d/iptables status

Centos上搭建基于L2TP的VPN的更多相关文章

  1. CentOs上搭建git服务器

    CentOs上搭建git服务器 首先安装setuptools wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0 ...

  2. 在CentOS 上搭建nginx来部署静态页面网站

    在centOs 上搭建nginx来部署静态页面网站 一.部署服务器环境 nginx:轻量级.高性能的HTTP及反向代理服务器,占用内存少,并发能力强,相比老牌的apache作为web服务器,性能更加卓 ...

  3. Mac 上搭建基于 Hexo + GitHub 个人博客

    环境配置 本人电脑系统:macOS Node.js 生成静态页面.安装Node.js Git 用于将本地 Hexo 内容提交到 Github.Xcode自带Git(前提:macOS已经安装了Xcode ...

  4. OpenWrt上搭建纯L2TP服务器[ZT]

    转自:http://www.openwrt.pro/post-389.html 纯L2TP(l2tp + ppp,无IPSec) 首先安装xl2tpd软件包 opkg update opkg inst ...

  5. CentOs上搭建nginx

    目录 CentOs上搭建nginx 1. 在root环境下安装nginx 1.1 常用工具安装 1.2 关闭iptables规则 1.3 关闭SELinux 1.4 安装C/C++环境和PCRE库 1 ...

  6. centos上搭建git服务--3

    前言:当我们想要实现几个小伙伴合作开发同一个项目,或者建立一个资源分享平台的时候,GIT就是一个很好的选择.当然,既然是一个共有平台,那么把这个平台放到个人计算机上明显是不合适的,因此就要在服务器上搭 ...

  7. 如何在ASP.NET 5上搭建基于TypeScript的Angular2项目

    一.前言 就在上月,公司的一个同事建议当前的前端全面改用AngularJs进行开发,而我们采用的就是ASP.NET 5项目,原本我的计划是采用TypeScript直接进行Angular2开发.所以借用 ...

  8. CentOS上搭建java WEB开发环境Tomcat+MySQL+JDK

    对于初学者来说,想在linux系统上搭建一个java web服务器,不知道什么方案可行, 这篇文章主要是告诉这些基础和概念相对薄弱的同学,这样搭建是可行的,大体上没问 题的,出问题也是细节问题.所以此 ...

  9. 在centOS上搭建wordpress博客系统

    一.主要内容 1.安装LAMP服务器系统(Linux.Apache.MySQL.PHP ); 2.安装wordpress: 二.具体步骤 一.LAMP环境设置 1.安装LAMP系统,在centOS上可 ...

随机推荐

  1. System memory,AGP memory和video memory【转】

    system  memory就是电脑的内存条上的,一般都很大.显卡不能访问 . video memory就是显示卡上的显存,一般是32,64,128M这样,速度最快,显卡可直接访问 .用来描述电脑上一 ...

  2. Windows 7 常用快捷键

    常用的快捷键 Win键+D 回到桌面/当前界面(切换)Win键+M 回到桌面Win键+E 资源管理器Win键+R 运行 Win键+U 控制面板->所有控制面板项->轻松访问中心 Win键+ ...

  3. Thinking in Java——笔记(17)

    Containers in Depth Full container taxonomy You can usually ignore any class that begins with " ...

  4. C++ 用RGB 三种颜色绘图

    #include <iostream> #include <cmath> #include <cstdlib> #define DIM 1024 #define D ...

  5. (。・・)ノ~个人java学习随笔记录

    基本认识 1.编程思维 根据这几天的java学习,编写程序最重要的就是要有一个清晰的思路.语法上的错误可以跟随着不断的联系与学习来弥补,清晰的思维却只有自己来前期模仿,后面慢慢摸索形成一套属于自己的思 ...

  6. Java中OutOfMemoryError(内存溢出)的三种情况及解决办法

    转载自:http://blog.sina.com.cn/s/blog_701c951f0100n1sp.html 相信有一定java开发经验的人或多或少都会遇到OutOfMemoryError的问题, ...

  7. PostgreSQL JSON函数

    https://www.postgresql.org/docs/9.6/static/functions-json.html PostgreSQL 9.6.1 Documentation Prev U ...

  8. http之Session&Cookie

    百度了一波session与Cookie,我发现这东西远比我想象中更复杂(可能是因为我不明白底层的运行原理).网上也是一堆的关于Session与Cookie区别/联系的文章,然而,我看完了还是一脸懵逼的 ...

  9. 弱网测试IOS

    IOS测弱网非常方便,在设置-开发者-NETWORK LINK CONDITIONER的Status 进入后可以看到IOS自带了100%LOSS.3G.WiFi等常见场景 可以点击图标i进行查看或编辑 ...

  10. NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds

     Bugly:  Trapped uncaught exception 'NSRangeException', reason: 'NSMutableRLEArray objectAtIndex:eff ...