在EC2上搭建L2TP over IPSec VPN服务器
注意(:wq保存文件 putty登陆用户名为ec2-user)
安装与配置:
环境介绍:
OS:CentOS 6.4 x86_64 Minimal
1. 修改 /etc/sysctl.conf,新增如下配置: # vi /etc/sysctl.conf
# For xl2tpd 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
2. 安装EPEL扩展库 # yum install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
//安装时运行yum报错:
Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again
解决办法:
vi /etc/yum.repos.d/epel.repo
编辑[epel]下的baseurl前的#号去掉,mirrorlist前添加#号。正确配置如下:
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
再运行
yum makecache
3. 安装所需软件包
# yum install wget bind-utils lsof
# yum install openswan xl2tpd ppp
# yum downgrade openswan
4. 通过如下脚本完成配置文件的修改 # vim l2tpvpn.sh (注意要删掉注释)
#!/bin/sh IPSEC_PSK=SharedSecret ;修改以上变量的值,作为共享密码 PRIVATE_IP=`wget -q -O - 'http://instance-data/latest/meta-data/local-ipv4'` PUBLIC_IP=`wget -q -O - 'http://instance-data/latest/meta-data/public-ipv4'` ;修改以上变量的值,我通过命令来自动获取服务器的本地内网IP和公网IP,但仅适用于EC2 cat > /etc/ipsec.conf <<EOF version 2.0 config setup dumpdir=/var/run/pluto/ nat_traversal=yes virtual_private=%v4:10.0.0.0/8,%v4:192.168.0.0/16,%v4:172.16.0.0/12,%v4:25.0.0.0/8,%v6:fd00::/8,%v6:fe80::/10 oe=off protostack=netkey nhelpers=0 interfaces=%defaultroute plutostderrlog=/var/log/pluto.log conn vpnpsk auto=add left=$PRIVATE_IP leftid=$PUBLIC_IP leftsubnet=$PRIVATE_IP/32 leftnexthop=%defaultroute leftprotoport=17/1701 rightprotoport=17/%any right=%any rightsubnetwithin=0.0.0.0/0 forceencaps=yes authby=secret pfs=no type=transport auth=esp ike=3des-sha1 phase2alg=3des-sha1 dpddelay=30 dpdtimeout=120 dpdaction=clear EOF cat > /etc/ipsec.secrets <<EOF $PUBLIC_IP %any : PSK "$IPSEC_PSK" EOF cat > /etc/xl2tpd/xl2tpd.conf <<EOF [global] port = 1701 ;debug avp = yes ;debug network = yes ;debug state = yes ;debug tunnel = yes [lns default] ip range = 172.192.169.10-172.192.169.250 local ip = 172.192.169.1 ;修改以上虚拟地址范围 require chap = yes refuse pap = yes require authentication = yes name = l2tpd ;ppp debug = yes pppoptfile = /etc/ppp/options.xl2tpd length bit = yes EOF cat > /etc/ppp/options.xl2tpd <<EOF ipcp-accept-local ipcp-accept-remote ms-dns 172.31.0.2 ;修改以上DNS服务器 noccp auth crtscts idle 1800 mtu 1280 mru 1280 lock connect-delay 5000 EOF
# chmod +x l2tpvpn.sh # ./l2tpvpn.sh
5. 配置用户名与密码 # vi /etc/ppp/chap-secrets
# 修改以下用户名与密码 # Secrets for authentication using CHAP # client server secret IP addresses "username" * "password" *
6. 配置NAT共享上网(修改如下虚拟地址范围与配置文件中相匹配) # iptables -t NAT -A POSTROUTING -s 172.192.169.0/24 -o eth0 -j MASQUERADE
7. 开放如下端口(EC2需要在SecurityGroup中配置)
# iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 1194 -j ACCEPT
# iptables -A INPUT -p udp -m state --state NEW -m udp --dport 1701 -j ACCEPT
# iptables -A INPUT -p udp -m state --state NEW -m udp --dport 500 -j ACCEPT
# iptables -A INPUT -p udp -m state --state NEW -m udp --dport 4500 -j ACCEPT
8. 启动相关服务,并设置为自动启动
# service ipsec restart
# service xl2tpd restart
# chkconfig ipsec on
# chkconfig xl2tpd on
9. 结束
在EC2上搭建L2TP over IPSec VPN服务器的更多相关文章
- 架设基于StrongSwan的L2tp/IPSec VPN服务器
架设基于StrongSwan的L2tp/IPSec VPN服务器 参考: http://agit8.turbulent.ca/bwp/2011/01/setting-up-a-vpn-server-w ...
- Amazon EC2上搭建VPN服务器
Amazon EC2 提供了一年免费试用,Micro Instance,配置是 1G 内存,共享 CPU,和每月 15G 的流量.搭一个 VPN 服务器绰绰有余了.操作系统我选的是 Amazon Li ...
- 在Azure上搭建L2TP服务器
L2TP是常用的一种point-site的VPN.而目前在Azure上的VPN Gateway只支持IPsec和SSTP两种.如果客户需要L2TP服务器,需要自己在VM中搭建.本文将介绍如何在Azur ...
- 在 CentOS7.0 上搭建 Chroot 的 Bind DNS 服务器
BIND(Berkeley internet Name Daemon)也叫做NAMED,是现今互联网上使用最为广泛的DNS 服务器程序.这篇文章将要讲述如何在 chroot 监牢中运行 BIND,这样 ...
- 在Ubuntu上搭建IntelliJ IDEA license server服务器
1.下载激活文件 2.ubuntu需要使用 IntelliJIDEALicenseServer_linux_amd64 ,把该文件传到服务器的某个目录,我是放在了/jideal 下 3.进入上面的目录 ...
- 在 Linux 上搭建IntelliJ IDEA license server服务器
IntelliJIDEALicenseServer_linux_amd64 ,把该文件传到服务器的某个目录,我是放在了/var/local/software目录下 sudo chmod +x ./In ...
- VPN 隧道协议PPTP、L2TP、IPSec和SSLVPN的区别
最近软矿频繁地介绍了各种VPN,有免费的PacketiX.NET和Hotspot Shield,有付费的Astrill VPN,iVPN和PureVPN.在介绍这些VPN的时候,常常会说到PPTP.L ...
- PPTP、L2TP、IPSec和SSLVPN的区别
VPN (虚拟专用网)发展至今已经不在是一个单纯的经过加密的访问隧道了,它已经融合了访问控制.传输管理.加密.路由选择.可用性管理等多种功能,并在全球的信息安全体系中发挥着重要的作用.也在网络上,有关 ...
- VPN服务器环境搭建
一.VPN服务器环境说明 操作系统:CentOS release 6.4 (Final) 本地网卡: 复制代码 代码如下: # ifconfig em1 Link encap:Ethernet HWa ...
随机推荐
- DbnBase64加密处理
package com.dbn.utils; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; impo ...
- 小识Tableau
关于 Tableau Tableau 帮助人们将数据转化为可以付诸行动的见解.探索无所不能的可视化分析.只需点击几下即可构建仪表板,进行即兴分析. Tableau与R对比: 1.从开发的角度讲,Tab ...
- 30-React JSX IN DEPTH
JSX IN DEPTH JSX 从根本上说,JSX只是提供了语法糖React.createElement(component, props, ...children)的功能.以下JSX代码: < ...
- python 中的 try/except/else/finally语句
1.python中try/except/else/finally正常的语句是这样的: try: normal excute block except A: Except A handle except ...
- consul模板的说明2
保证模板的正常执行 使用||true $ consul-template -template "in.ctmpl:out.file:service nginx restart || true ...
- Spring Security3中的-authentication-manager标签详解
讲解完http标签的解析过程,authentication-manager标签解析部分就很容易理解了 authentication-manager标签在spring的配置文件中的定义一般如下 < ...
- iOS NSURLConnection POST异步请求封装,支持转码GBK,HTTPS等
.h文件 #import <Foundation/Foundation.h> //成功的回调 typedef void(^successBlock)(id responseObj); // ...
- SQL Server优化常用SQL语句
--所有没有主键的表 select name from sysobjects where xtype='U' and id not in ( select i.parent_obj from syso ...
- php : 基础(3)
运算符 算术运算符 基础: 符号有:+ - * / % 说明: 他们都是针对数字进行的运算: 如果他们的两边有不是数字的数据,就会(自动)转换为数字: 其中取余运算(取模运算)%,它只 ...
- Handler+ExecutorService(线程池)+MessageQueue模式+缓存模式
android线程池的理解,晚上在家无事 预习了一下android异步加载的例子,也学习到了一个很重要的东东 那就是线程池+缓存 下面看他们的理解.[size=1.8em]Handler+Runna ...