通过openswan基于Azure平台搭建VPN server
用过Azure的读者都知道,Vnet一直是Azure比较自豪的地方,尤其是VPN,Azure提供了两种VPN以及专线来保证客户数据的安全性,S2S vpn(站点到站点的,基于IPsec的),P2S vpn(点到站点的,基于sstp的),专线express route是和物理链路或者MPLS网络相连接,在这里笔者要提醒大家一句,Azure的vpn身后是两台机器做HA的vpn server,是提供LSA保证的,而无论是阿里还是AWS都没有这样的服务,而且Azure最高提供带宽200M的VPN链路,三线BGP相连(移动 联通 电信),一跳进入骨干网,所以说Azure的vpn并不是吹出来的,我们是有实力的!!!
笔者一直相信一句话,弱势与优势从来只是角度的问题,曾经碰到一个客户,这里不说名字,只谈场景,这个客户在全国有150多个分店,分店都有路由设备,并且要求数据不能走公网走,这样只能考虑vpn,本来Azure的vpn是Azure的优势,但是到这里就变成了劣势,为什么?你求我啊,我就告诉你,开个玩笑,是这样的,Azure的S2S vpn网关分个三个级别,分别对应的隧道数量只有,一个,十个,三十个,显而易见不符合需求,有人肯定会问一个vpn网关不够就用多个呗,但是Azure定义一个VNet只能有一个vpn网关,Vnet之间是隔离的,这是第一个原因,第二个原因是才最主要的,一个高级VPN网关一年的费用就达到三万左右,以这里为例,光五个vpn网关的价格就达到十五万以上,这是一般客户都难以承受的,反而这个时候用虚拟机搭vpn比较合适(这样阿里反而最占优势,因为虚拟机价格便宜),其实事实也并非如此,所以我一直觉得没有什么绝对的优势也没有觉得的劣势,关键在于客户愿意去听什么。
场景:本次poc中,我们选用开源软件openswan,然后在东部数据中心建立一台A1虚拟机,OS为Centos6.5,装上openswan,作为vpnserver,配置iptables,最后使用iphone拨该服务器,达到目的
架构图这里略去,虚拟机的建立过程略去,但是在装openswan之前,我们需要配置一下端口,分别是UDP500和UDP4500,在ASM中需要配置终结点,ARM需要配置NSG,这里的配置过程省去,结果如下

SSH登陆到vm,安装openswan
先确认OS版本,输入 sudo cat /etc/redhat-release

配置yum源
sudo vim /etc/yum.repos.d/epel.repo [epel] name=epel baseurl=http://mirrors.sohu.com/fedora-epel/6/$basearch enabled= gpgcheck=
编辑保存,看到如下结果。

首先通过yum安装
sudo yum install -y ppp iptables make gcc gmp-devel xmlto bison flex xmlto libpcap-devel lsof
看到如下结果,说明安装成功

其次安装IPsec,下载,解压,安装
sudo wget https://download.openswan.org/openswan/openswan-2.6.49.tar.gz --no-check-certificate sudo tar vxf openswan-.tar.gz
sudo cd openswan-2.6.49
sudo make programs install
通过yum安装epel里的xl2tpd
sudo yum install -y xl2tpd
看到如下结果说明安装成功

配置服务
配置IPsec
sudo vim /etc/ipsec.conf # /etc/ipsec.conf - Openswan IPsec configuration file # This file: /usr/local/share/doc/openswan/ipsec.conf-sample # # Manual: ipsec.conf. version 2.0 # conforms to second version of ipsec.conf specification # basic configuration config setup # Do not set debug options to debug configuration issues! # plutodebug / klipsdebug = "all", "none" or a combation from below: # "raw crypt parsing emitting control klips pfkey natt x509 dpd private" # eg: # plutodebug="control parsing" # Again: only enable plutodebug or klipsdebug when asked by a developer # # enable to get logs per-peer # plutoopts="--perpeerlog" # # Enable core dumps (might require system changes, like ulimit -C) # This is required for abrtd to work properly # Note: incorrect SElinux policies might prevent pluto writing the core dumpdir=/var/run/pluto/ # # NAT-TRAVERSAL support, see README.NAT-Traversal nat_traversal=yes # exclude networks used on server side by adding %v4:!a.b.c./ # It seems that T-Mobile in the US and Rogers/Fido in Canada are # / as "private" address space on their 3G network. # This range has not been announced via BGP (at least upto --) virtual_private=%v4:,%v4:,%v4:,%v4:,%v6:fd00::/,%v6:fe80::/ # OE is now off by default. Uncomment and change to on, to enable. oe=off # which IPsec stack to use. auto will try netkey, then klips then mast protostack=netkey #protostack=auto # Use this to log to a file, or disable logging on embedded systems (like openwrt) #plutostderrlog=/dev/null # Add connections here # sample VPN connection # for more examples, see /etc/ipsec.d/examples/ #conn sample # # Left security gateway, subnet behind it, nexthop toward right. # left=10.0.0.1 # leftsubnet= # leftnexthop=10.22.33.44 # # Right security gateway, subnet behind it, nexthop toward left. # right=10.12.12.1 # rightsubnet= # rightnexthop=10.101.102.103 # # To authorize this connection, but not actually start it, # # at startup, uncomment this. # #auto=add conn L2TP-PSK-NAT rightsubnet=vhost:%priv also=L2TP-PSK-noNAT conn L2TP-PSK-noNAT authby=secret pfs=no auto=add keyingtries= rekey=no ikelifetime=8h keylife=1h type=transport left=10.215.92.31 #AWS EC2 Internal IP leftprotoport=/ right=%any rightprotoport=/%any dpddelay= dpdtimeout= dpdaction=clear
在这里,笔者想提醒大家一句,在修改该文件时,尽量不要去动原有的内容格式,只修改要改的内容就好,否则会在后续的过程中出现不必要的错误,看到如下结果说明成功

配置安全规则ipsec.secrets
sudo vim /etc/ipsec.secrets # This file holds shared secrets or RSA private keys for inter-Pluto # authentication. See ipsec_pluto() manpage, and HTML documentation. # RSA private key for this host, authenticating it to any other host # which knows the public part. Suitable public keys, for ipsec.conf, DNS, # or configuration of other implementations, can be extracted conveniently # with "ipsec showhostkey". # this file is managed with debconf and will contain the automatically created RSA keys #include /var/lib/openswan/ipsec.secrets.inc %any %any: PSK "azure"
看到如下结果说明成功

配置sysctl.conf文件
sudo vim /etc/sysctl.conf net.ipv4.ip_forward = net.ipv4.conf. net.ipv4.conf.all.send_redirects = net.ipv4.conf. net.ipv4.conf.all.log_martians = net.ipv4.conf. net.ipv4.conf. net.ipv4.conf.all.accept_redirects = net.ipv4.conf. net.ipv4.icmp_ignore_bogus_error_responses =
看到如下结果则为成功

通过下面的命令,使配置生效
sudo sysctl -p sudo service ipsec start ipsec verify
看到如下结果

输入ipsec verify 会看到如下结果

在这里不需要关心errors,我们只关心我们创建的端口(udp4500和udp500正常工作就好了),其它问题引起的错误不要去纠结,这里不展开去说
配置xl2tpd
sudo vim /etc/xl2tpd/xl2tpd.conf ; ; This is a minimal sample xl2tpd configuration file for use ; with L2TP over IPsec. ; ; The idea is to provide an L2TP daemon to which remote Windows L2TP/IPsec ; clients connect. In this example, the internal (protected) network ; . A special IP range within this network is reserved ; ; (i.e. 192.168.1.128 ... 192.168.1.254) ; ; The listen-addr parameter can be used if you want to bind the L2TP daemon ; to a specific IP address instead of to all interfaces. For instance, ; you could bind it to the interface of the internal LAN (e.g. 192.168.1.98 ; in the example below). Yet another IP address (local ip, e.g. 192.168.1.99) ; will be used by xl2tpd as its address on pppX interfaces. [global] ; listen-addr = 192.168.1.98 ; ; requires openswan- or higher - Also does not yet work in combination ; with kernel mode l2tp + ; ipsec saref = yes ; Use refinfo of or ; when . ; saref refinfo = ; ; force userspace = yes ; ; debug tunnel = yes ipsec saref = no [lns default] ip range = 192.168.1.128-192.168.1.254 local ip = 192.168.1.99 require chap = yes refuse pap = yes require authentication = yes name = LinuxVPNserver ppp debug = yes pppoptfile = /etc/ppp/options.xl2tpd length bit = yes
看到如下结果则成功

配置ppp的用户名和密码
sudo vim /etc/ppp/chap-secrets # Secrets for authentication using CHAP # client server secret IP addresses user * azure *
配置iptables
sudo iptables -t nat -A POSTROUTING -s -o eth0 -j MASQUERADE sudo iptables -I FORWARD -s -j ACCEPT sudo iptables -I FORWARD -d -j ACCEPT sudo service iptables save
看到如下结果说明成功

设置服务
sudo service ipsec restart sudo service xl2tpd restart sudo service iptables restart sudo chkconfig xl2tpd on sudo chkconfig iptables on sudo chkconfig ipsec on
看到如下结果

最后一步设置iphone,这一步这里就不再多说,但是在这里笔者想提醒大家一句,有人在测试的时候发现,iphone无论如何都不能连接vpn server,即使查看了/var/log/下的secure与message文件,也发现没有然后具体报错,如果遇到这种情况说明l2tp vpn server被封掉了,这时候无论你怎么连你都是连不上的,所以笔者的建议最好是以global账户来建立vm,这样就不会碰到这种情况。
通过openswan基于Azure平台搭建VPN server的更多相关文章
- 基于 Azure IaaS 搭建企业官网的规划和实践
本课程主要介绍了基于 Azure IaaS 搭建企业官网的案例分析和实践,实践讲解如何使用 Azure 门户创建虚拟机, 创建虚拟网络, 创建存储账户等. 具体包括项目背景介绍, 项目架构, 准备和实 ...
- 如何基于Azure平台实现MySQL HA(方法论篇)
我们都知道,相较于传统的数据中心,Pulic cloud也有劣势,比如说数据库的HA,很多熟悉公有云平台的读者都知道,因为出于安全性性考虑以及一些技术条件的限制,很多本地数据中心的mysql HA方法 ...
- 基于Proxmox平台搭建3D云教室
背景 本文介绍了在 Proxmox VE 虚拟化平台上使用NVIDIA A16 GPU,开启vGPU特性,利用DoraCloud 搭建3D云教室的方案. Proxmox virtualization ...
- Ubuntu自己主动搭建VPN Server - PPTP的Shell脚本
#!/bin/bash if [ "$UID" != "0" ]; then echo "please use sudo to run $0" ...
- 基于windows平台搭建elasticsearch
部署准备 elasticsearch-6.0.1.zip--https://www.elastic.co/downloads/elasticsearch elasticsearch-head-mast ...
- 基于windows平台搭建elasticsearch 补充
https://www.cnblogs.com/skychen1218/p/8108860.html 参考此大神写的内容,感谢感谢. 不过 好像漏掉了一块内容. 导致出现问题 连接不上的问题.后来修改 ...
- 基于开源软件在Azure平台建立大规模系统的最佳实践
作者 王枫 发布于2014年5月28日 前言 Microsoft Azure 是微软公有云的唯一解决方案.借助这一平台,用户可以以多种方式部署和发布自己的应用. 这是一个开放的平台,除了对于Windo ...
- 【Microsoft Azure 的1024种玩法】三.基于Azure云平台构建Discuz论坛
[简介] Discuz!是一套通用社区论坛软件系统,用户在不需要任何编程的基础上,通过简单的设置和安装,在互联网上搭建起具备完善功能.很强负载能力和可高度定制的论坛服务. [前期文章] [操作步骤] ...
- 通过基于 Linux 的软件 VPN 设备连接到 Windows Azure 虚拟网络
摘要 本文章将说明如何通过使用软件 VPN 设备,将本地办公室或站点连接到 Windows Azure 虚拟网络.在构建原型或在构建可以尽快利用云的"开发/测试"工作流时,软件VP ...
随机推荐
- cg数据类型
Cg 支持7 种基本的数据类型:1. float,32 位浮点数据,一个符号位.浮点数据类型被所有的profile 支持(但是DirectX8 pixel profiles 在一些操作中降低了浮点数的 ...
- Python学习Day2笔记(字符编码和函数)
1.字符编码 #ASCII码里只能存英文和特殊字符 不能存中文 存英文占1个字节 8位#中文编码为GBK 操作系统编码也为GBK#为了统一存储中文和英文和其他语言文字出现了万国码Unicode 所有一 ...
- 【三石jQuery视频教程】01.图片循环展示
视频地址:http://v.qq.com/page/e/5/t/e0149n5he5t.html 大家好,欢迎来到[三石jQuery视频教程],我是您的老朋友 - 三生石上. 今天,我们要通过基本的H ...
- logback 常用配置详解<appender>
logback 常用配置详解 <appender> <appender>: <appender>是<configuration>的子节点,是负责写日志的 ...
- CocoaPods的那些坑
CocoaPods的那些坑 文章转自http://blog.csdn.net/zhanniuniu/article/details/52159362#comments 我跟博主的经历超级像!不过自己用 ...
- odoo8.0 win7 64位 安装配置(补遗)
各种参考博客资源--http://www.cnblogs.com/yiguxianyun/p/6256641.html 最开始蛋疼问题的是安装各种site-packages! 云盘里面有些win764 ...
- 推公式hdu2298
(0,0)点到(x,y)以v射箭 问 最小的角度 不能射到 -1 x=v*cos(a)*t; y=v*sin(a)*t-0.5*g*t*t; 消去t; y=x*tan(a)-0.5*g*x*x/(v* ...
- Python Numpy,Pandas基础笔记
Numpy Numpy是python的一个库.支持维度数组与矩阵计算并提供大量的数学函数库. arr = np.array([[1.2,1.3,1.4],[1.5,1.6,1.7]])#创建ndarr ...
- java学习笔记之线程2wait和notifyAll
2.乐观锁和悲观锁 悲观锁(Pessimistic Lock), 顾名思义,就是很悲观,每次去拿数据的时候都认为别人会修改,所以每次在拿数据的时候都会上锁,这样别人想拿这个数据就会block直到它拿到 ...
- C#面向对象设计模式纵横谈——5.Factory Method 工厂方法模式(创建型模式)
动机 (Motivation) 在软件系统中,经常面临着“某个对象”的创建工作; 由于需求的变化,这个对象经常面临着剧烈的变化,但是它却拥有比较稳定的接口. 如何应对这种变化?如何提供一种“封装机制” ...