Centos上搭建基于L2TP的VPN
1.一些预先准备的环境
- yum install -y make gcc gmp-devel xmlto bison flex xmlto libpcap-devel lsof vim-enhanced man
复制代码
2.安装
- yum install openswan ppp xl2tpd
复制代码
3.配置
(1)编辑 /etc/ipsec.conf
- vi /etc/ipsec.conf
复制代码
替换为如下内容,把下面0.0.0.0换成腾讯云服务器的外网IP,其他的不用修改。
注意:第一行两个**的地方是s e t u(自行更改,字母之间无空格)
- 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=0.0.0.0
- leftprotoport=17/1701
- right=%any
- rightprotoport=17/%any
复制代码
(2)编辑/etc/ipsec.secrets
- vi /etc/ipsec.secrets
- include /etc/ipsec.d/*.secrets
- 0.0.0.0 %any: PSK "YourPsk"
复制代码
0.0.0.0换成腾讯云服务器的外网IP, YourPsk你自己定一个。
(3) 修改/添加 /etc/sysctl.conf并生效
- vim /etc/sysctl.conf
复制代码
在/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
复制代码
(4)验证ipsec运行状态
- ipsec restart
- ipsec verify
复制代码
如果出现如下内容,说明已经成功
- Checking your system to see if IPsec got installed and started correctly:
- Version check and ipsec on-path [OK]
- Linux Openswan U2.6.32/K2.6.32-431.20.3.0.1.el6.centos.plus.x86_64 (netkey)
- Checking for IPsec support in kernel [OK]
- SAref kernel support [N/A]
- NETKEY: Testing for disabled ICMP send_redirects [OK]
- NETKEY detected, testing for disabled ICMP accept_redirects [OK]
- Checking that pluto is running [OK]
- Pluto listening for IKE on udp 500 [OK]
- Pluto listening for NAT-T on udp 4500 [OK]
- Checking for 'ip' command [OK]
- Checking /bin/sh is not /bin/dash [OK]
- Checking for 'iptables' command [OK]
- Opportunistic Encryption Support [DISABLED]
复制代码
(5) 编辑 /etc/xl2tpd/xl2tpd.conf 这一步可以跳过
ip range 写客户端的内网IP段,local ip写客户端内网IP
- vim /etc/xl2tpd/xl2tpd.conf
- [lns default]
- ip range = 10.3.154.192-10.3.154.254
- local ip = 10.3.154.202
- require chap = yes
- refuse pap = yes
- require authentication = yes
- name = LinuxVPNserver
- ppp debug = yes
- pppoptfile = /etc/ppp/options.xl2tpd
- length bit = yes
复制代码
(6)配置用户名,密码:编辑 /etc/ppp/chap-secrets
- vim /etc/ppp/chap-secrets
复制代码
username 写登录vpn的用户名,userpass 写登录vpn的密码
- # Secrets for authentication using CHAP
- # client server secret IP addresses
- username * "userpass" *
复制代码
(7)重启xl2tp
- service xl2tpd restart
复制代码
(8)添加自启动
- chkconfig xl2tpd on
- chkconfig iptables on
- 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的更多相关文章
- CentOs上搭建git服务器
CentOs上搭建git服务器 首先安装setuptools wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0 ...
- 在CentOS 上搭建nginx来部署静态页面网站
在centOs 上搭建nginx来部署静态页面网站 一.部署服务器环境 nginx:轻量级.高性能的HTTP及反向代理服务器,占用内存少,并发能力强,相比老牌的apache作为web服务器,性能更加卓 ...
- Mac 上搭建基于 Hexo + GitHub 个人博客
环境配置 本人电脑系统:macOS Node.js 生成静态页面.安装Node.js Git 用于将本地 Hexo 内容提交到 Github.Xcode自带Git(前提:macOS已经安装了Xcode ...
- OpenWrt上搭建纯L2TP服务器[ZT]
转自:http://www.openwrt.pro/post-389.html 纯L2TP(l2tp + ppp,无IPSec) 首先安装xl2tpd软件包 opkg update opkg inst ...
- CentOs上搭建nginx
目录 CentOs上搭建nginx 1. 在root环境下安装nginx 1.1 常用工具安装 1.2 关闭iptables规则 1.3 关闭SELinux 1.4 安装C/C++环境和PCRE库 1 ...
- centos上搭建git服务--3
前言:当我们想要实现几个小伙伴合作开发同一个项目,或者建立一个资源分享平台的时候,GIT就是一个很好的选择.当然,既然是一个共有平台,那么把这个平台放到个人计算机上明显是不合适的,因此就要在服务器上搭 ...
- 如何在ASP.NET 5上搭建基于TypeScript的Angular2项目
一.前言 就在上月,公司的一个同事建议当前的前端全面改用AngularJs进行开发,而我们采用的就是ASP.NET 5项目,原本我的计划是采用TypeScript直接进行Angular2开发.所以借用 ...
- CentOS上搭建java WEB开发环境Tomcat+MySQL+JDK
对于初学者来说,想在linux系统上搭建一个java web服务器,不知道什么方案可行, 这篇文章主要是告诉这些基础和概念相对薄弱的同学,这样搭建是可行的,大体上没问 题的,出问题也是细节问题.所以此 ...
- 在centOS上搭建wordpress博客系统
一.主要内容 1.安装LAMP服务器系统(Linux.Apache.MySQL.PHP ); 2.安装wordpress: 二.具体步骤 一.LAMP环境设置 1.安装LAMP系统,在centOS上可 ...
随机推荐
- 【转】自学成才秘籍!机器学习&深度学习经典资料汇总
小编都深深的震惊了,到底是谁那么好整理了那么多干货性的书籍.小编对此人表示崇高的敬意,小编不是文章的生产者,只是文章的搬运工. <Brief History of Machine Learn ...
- linux-系统调用
p { margin-bottom: 0.1in; line-height: 120% } ● Fork() 创建子进程. 创建单个子进程: pid_t pid; pid = fork(); if(p ...
- laravel 获取 当前url 的方法, 有的是获取 全部url 有的只获取 主页其他 部分
1. 使用 Request 类: $url = Request::getRequestUri(); 2. 使用 $request 对象: public function show(Request $r ...
- sonarqube插件开发(一) 环境搭建
1. 下载Docker容器 # 最新版本镜像 docker pull sonarqube # 长期支持版镜像 docker pull sonarqube:lts 2. 将已有的插件导出(使用docke ...
- jvisualVM 分析heapdump
代码很简单,eclipse里面设置下最大堆空间为128m,: @Test public void testOutOfMemory() { List<NewsAddDto> document ...
- linux实践之ELF文件分析
linux实践之ELF文件分析 下面开始elf文件的分析. 我们首先编写一个简单的C代码. 编译链接生成可执行文件. 首先,查看scn15elf.o文件的详细信息. 以16进制形式查看scn15elf ...
- 数据库连接池:Druid
转自: http://www.cnblogs.com/windlaughing/p/3287501.html Java连接数据库方法概述 java.sql提供了一些接口和类,用于支持数据库增删改查等相 ...
- 使用PowerShell解三道测试开发笔试题
在网上看到了三道测试开发的笔试题,答案是用Python解的.这段时间正好在学PowerShell,练习一下:) 1. 验证邮箱格式 2. 获取URL的后缀名 3. 获取前一天时间或前一秒 我的解法是: ...
- 关于python,一些整理
参数传递 1 a = 1 2 def fun(a): 3 a = 2 4 fun(a) 5 print a 6 7 # 输出: 1 a = [] def fun(a): a.append(1) fun ...
- java字典序排序
import java.util.Comparator; import java.util.ArrayList; import java.util.Collections; public class ...