前期准备,购买外服,选择vultr服务商,可选择洛杉矶的,系统为Ubuntu 14.04 x64

一、安装L2TP/IPSec

wget --no-check-certificate https://raw.githubusercontent.com/teddysun/across/master/l2tp.sh

  

chmod +x l2tp.sh

  

./l2tp.sh

  

Please input IP-Range:
(Default Range: 192.168.18):
输入本地IP段范围(本地电脑连接到VPS后给分配的一个本地IP地址),直接回车意味着输入默认值192.168.18

Please input PSK:
(Default PSK: teddysun.com):
PSK意为预共享密钥,即指定一个密钥将来在连接时需要用到,直接回车意味着输入默认值teddysun.com

Please input Username:
(Default Username: teddysun):
Username意为用户名,即第一个默认用户。直接回车意味着输入默认值teddysun

Please input teddysun’s password:
(Default Password: Q4SKhu2EXQ):
输入用户的密码,默认会随机生成一个10位包含大小写字母和数字的密码,当然你也可以指定密码。

ServerIP:your_server_main_IP
显示你的 VPS 的主 IP(如果是多 IP 的 VPS 也只显示一个)

Server Local IP:192.168.18.1
显示你的 VPS 的本地 IP(默认即可)

Client Remote IP Range:192.168.18.2-192.168.18.254
显示 IP 段范围

PSK:teddysun.com
显示 PSK

Press any key to start…or Press Ctrl+c to cancel
按下任意按键继续,如果想取消安装,请按Ctrl+c键

  

默认设置,全部回车安装

apt-get install openswan xl2tpd ppp lsof

二、设置防火墙和sysctl

iptables -t nat -A POSTROUTING -j SNAT --to-source VPS的ip -o eth+
echo "net.ipv4.ip_forward = 1" |  tee -a /etc/sysctl.conf
echo "net.ipv4.conf.all.accept_redirects = 0" |  tee -a /etc/sysctl.conf
echo "net.ipv4.conf.all.send_redirects = 0" |  tee -a /etc/sysctl.conf
echo "net.ipv4.conf.default.rp_filter = 0" |  tee -a /etc/sysctl.conf
echo "net.ipv4.conf.default.accept_source_route = 0" |  tee -a /etc/sysctl.conf
echo "net.ipv4.conf.default.send_redirects = 0" |  tee -a /etc/sysctl.conf
echo "net.ipv4.icmp_ignore_bogus_error_responses = 1" |  tee -a /etc/sysctl.conf

  

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

 使sysctl生效

sysctl -p

 开机自启

将如下内容加入到/etc/rc.local(需要加载exit 0前面)

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

  

三、配置Openswan (IPSEC)

将/etc/ipsec.conf替换为如下内容(推荐备份原文件)

version 2 # conforms to second version of ipsec.conf specification

config setup
    dumpdir=/var/run/pluto/
    #in what directory should things started by setup (notably the Pluto daemon) be allowed to dump core?

    nat_traversal=yes
    #whether to accept/offer to support NAT (NAPT, also known as "IP Masqurade") workaround for IPsec

    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
    #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.

    protostack=netkey
    #decide which protocol stack is going to be used.

    force_keepalive=yes
    keep_alive=60
    # Send a keep-alive packet every 60 seconds.

conn L2TP-PSK-noNAT
    authby=secret
    #shared secret. Use rsasig for certificates.

    pfs=no
    #Disable pfs

    auto=add
    #the ipsec tunnel should be started and routes created when the ipsec daemon itself starts.

    keyingtries=3
    #Only negotiate a conn. 3 times.

    ikelifetime=8h
    keylife=1h

    ike=aes256-sha1,aes128-sha1,3des-sha1
    phase2alg=aes256-sha1,aes128-sha1,3des-sha1
    # https://lists.openswan.org/pipermail/users/2014-April/022947.html
    # 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.

    type=transport
    #because we use l2tp as tunnel protocol

    left=45.63.48.198你的Vpn地址
    #fill in server IP above

    leftprotoport=17/1701
    right=%any
    rightprotoport=17/%any

    dpddelay=10
    # Dead Peer Dectection (RFC 3706) keepalives delay
    dpdtimeout=20
    #  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.
    dpdaction=clear
    # When a DPD enabled peer is declared dead, what action should be taken. clear means the eroute and SA with both be cleared.

四、设置shared secret

修改文件/etc/ipsec.secrets

VPS的ip  %any:   PSK "你的L2Tp的共享密钥"

五、检验IPSEC

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.38/K3.13.0-24-generic (netkey)
Checking for IPsec support in kernel                            [OK]
 SAref kernel support                                           [N/A]
 NETKEY:  Testing XFRM related proc values                      [OK]
    [OK]
    [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                               [WARNING]
Checking for 'iptables' command                                 [OK]
Opportunistic Encryption Support                                [DISABLED]

实际出错

Checking your system to see if IPsec got installed and started correctly:
Version check and ipsec on-path                                 [OK]
Linux Openswan U2.6.38/K3.13.0-132-generic (netkey)
Checking for IPsec support in kernel                            [OK]
 SAref kernel support                                           [N/A]
 NETKEY:  Testing XFRM related proc values                      [OK]
        [OK]
        [OK]
Hardware RNG detected, testing if used properly                 [FAILED]

  Hardware RNG is present but 'rngd' or 'clrngd' is not running.
  No harware random used!

Checking that pluto is running                                  [OK]
 Pluto listening for IKE on udp 500                             [OK]
 Pluto listening for NAT-T on udp 4500                          [OK]
Two or more interfaces found, checking IP forwarding            [FAILED]
Checking NAT and MASQUERADEing                                  [OK]
Checking for 'ip' command                                       [OK]
Checking /bin/sh is not /bin/dash                               [WARNING]
Checking for 'iptables' command                                 [OK]
Opportunistic Encryption Support                                [DISABLED]

【解决问题】

  

Hardware RNG detected, testing if used properly [FAILED]

  

安装rng-tools
apt-get install rng-tools

 

Two or more interfaces found, checking IP forwarding            [FAILED]

  检查以上配置文件中的vps的ip是否写错

六、配置xl2tpd

配置文件/etc/xl2tpd/xl2tpd.conf

[global]
ipsec saref = yes
saref refinfo = 30

;debug avp = yes
;debug network = yes
;debug state = yes
;debug tunnel = yes

[lns default]
ip range = 172.16.1.30-172.16.1.100
local ip = 172.16.1.1
refuse pap = yes
require authentication = yes
;ppp debug = yes
pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes

 七、本地用户授权

修改文件/etc/xl2tpd/xl2tpd.conf,加入如下内容

unix authentication = yes

  移除如下内容

refuse pap = yes

  修改文件/etc/ppp/options.xl2tpd,加入如下内容

 

login

  修改文件/etc/pam.d/ppp

auth    required        pam_nologin.so
auth    required        pam_unix.so
account required        pam_unix.so
session required        pam_unix.so

  修改文件/etc/ppp/pap-secrets,加入如下内容

*       l2tpd           ""              *

八、修改ppp

修改文件/etc/ppp/options.xl2tpd

require-mschap-v2
ms-dns 8.8.8.8
ms-dns 8.8.4.4
auth
mtu 1200
mru 1000
crtscts
hide-password
modem
name l2tpd
proxyarp
lcp-echo-interval 30
lcp-echo-failure 4

  九、增加用户

修改文件/etc/ppp/chap-secrets

# Secrets for authentication using CHAP
# client       server  secret                  IP addresses
用户名          l2tpd   你的连接密码            *

十、重启生效

/etc/init.d/ipsec restart
/etc/init.d/xl2tpd restart

vultr服务器L2TP搭建的更多相关文章

  1. vultr服务器上搭建PHP运行环境-centos7

    安装nginx: yum install nginx 开启Nginx systemctl start nginx 访问你的域名或者ip 例如:quantaedu.com 安装PHP 查看系统版本lsb ...

  2. Vultr日本vps搭建ss/ssr/openvpn免流教程

    每个月的手机流量不够用,运营商流量套餐价格偏高,怎么才能省钱?你在淘宝上,搜索手机免流,可找到很多奸商销售免流套餐,一块钱可买1GB流量,免流原理是什么?自己能搞吗? 手机免流原理 手机运营商中国电信 ...

  3. Ubuntu服务器如何搭建PPTPD(原创保证可用)

    Ubuntu是一款基于linux的操作系统,无需许可和订购的费用,Ubuntu Server可以帮助您高效地扩展您的数据中心.它精简的架构和自动化部署的能力让您只需花费更少的运算能力和资源,便可提供更 ...

  4. 在MAC服务器上搭建docker-registry(转)

    在MAC服务器上搭建docker-registry 2014-03-14      0个评论    来源:在MAC服务器上搭建docker-registry   收藏    我要投稿 本文介绍如何在M ...

  5. LNAMP服务器环境搭建(手动编译安装)

    LNAMP服务器环境搭建(手动编译安装) 一.准备材料 阿里云主机一台,操作系统CentOS 6.5 64位 lnamp.zip包(包含搭建环境所需要的所有软件) http://123.56.144. ...

  6. 在Ubuntu14.04系统POWER8服务器上搭建Docker Registry服务

    本文描述了如何在POWER8服务器上搭建一个本地化的Docker镜像仓库,主要涉及镜像制作,Docker Registry服务启动等.希望能够对在非X86服务器上搭建Docker仓库的同学提供参考. ...

  7. 【干货】ECS服务器OPENVPN搭建,方便管理所有内网服务器

    [干货]ECS服务器OPENVPN搭建,方便管理所有内网服务器 使用场景 一台有外网的ECS服务器+N台无外网的ECS服务器,使用OPENVPN管理全部的ECS服务器(包括无外网的ECS服务器). 鉴 ...

  8. 分布式搜索ElasticSearch单机与服务器环境搭建

    从上方插件官网中下载适合的dist包,然后解压.进入bin目录,可以看到一堆sh脚本.在bin目录下创建一个test.sh: bin=/home/csonezp/Dev/elasticsearch-j ...

  9. git 服务器的搭建

    文章转载地址:http://www.linuxidc.com/Linux/2015-05/117502.htm 亲测可行,已经自己搭建一个正在使用中,搭建完成后,结合着pycharm +git,就能直 ...

随机推荐

  1. (5)在tomcat运行自己的javaweb项目

    A:在MyEclipse下方的Servers栏中启动服务器,运行项目: 1,选中项目所在的tomcat服务器 2,点击“启动按钮”,见下图 3,启动以后,看控制台输出日志: B:从服务器按钮启动: 1 ...

  2. XMU 1613 刘备闯三国之三顾茅庐(一) 【并查集】

    1613: 刘备闯三国之三顾茅庐(一) Time Limit: 1000 MS  Memory Limit: 128 MBSubmit: 99  Solved: 29[Submit][Status][ ...

  3. HDU3829 Cat VS Dog —— 最大独立集

    题目链接:https://vjudge.net/problem/HDU-3829 Cat VS Dog Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  4. HDU1151 Air Raid —— 最小路径覆盖

    题目链接:https://vjudge.net/problem/HDU-1151 Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory L ...

  5. 并不对劲的bzoj4651:loj2084:uoj220:p1173:[NOI2016]网格

    题目大意 有一个\(n*m\)(\(n,m\leq10^9\))的网格,每个格子是空地或障碍(\(障碍数\leq10^5\)) 定义两块空地连通,当且仅当它们是"相邻的两块空地"或 ...

  6. 使用反射机制恢复xml文件表示的对象

    完成如下功能:1)有一个(任意)对象,里面有N个properties以及getter和setter方法2)有一个properties文件,有N个key,value来描述对象中property的值3)有 ...

  7. 《JAVA与模式》之责任链模式

    责任链模式是一种对象的行为模式.在责任链模式里,很多对象由每一个对象对其下家的引用而连接起来形成一条链.请求在这个链上传递,直到链上的某一个对象决定处理此请求.发出这个请求的客户端并不知道链上的哪一个 ...

  8. ChartCtrl源码剖析之——CChartScrollBar类

    CChartScrollBar类用来针对每个轴的数据进行滚动,将那些不在当前区域内的数据通过滚动展示出来. CChartScrollBar类的头文件. #pragma once class CChar ...

  9. Python2.7 Queue模块学习

    前面了解了一下threading,发现一般都是和queue模块配合使用的,queue产生一个队列,队列模式有3种,针对这三种队列分别有三个构造函数: 1 FIFO队列先进先出:class Queue. ...

  10. nginx下配置虚拟主机

    linux 虚拟机下配置虚拟主机 nginx.conf 文件不动, 在 conf.d 或者 conf 目录下 新建项目.conf server { listen 80; server_name loc ...