通过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 ...
随机推荐
- 字符串匹配算法--Brute-Force算法
Brute-Force(暴力)算法是字符串匹配中最简单也是最容易理解的算法. 主要思想是 按顺序遍历母串,将每个字符作为匹配的起始字符,判断是否匹配字串.若第一个字符与字串匹配,则比较下一个字符,否则 ...
- HTTP状态码(HTTP Status Code)
一些常见的状态码为: 200 - 服务器成功返回网页 404 - 请求的网页不存在 503 - 服务不可用 所有状态解释: 1xx(临时响应)表示临时响应并需要请求者继续执行操作的状态代码. 代码 说 ...
- CSS3 基于关系的选择器
常见的基于关系的选择器 选择器 选择的元素 A E 元素A的任一后代元素E (后代节点指A的子节点,子节点的子节点,以此类推) A > E 元素A的任一子元素E(也就是直系后代) E:first ...
- 代码管理工具 --- git的学习笔记一《git的个人开发》
重点摘要: 创建了一个文件后首先先通过git add . 添加到暂缓区,然后通过git commit -m "提交的名字" 提交到本地仓库,最后才可能push到远程仓库. 1. 个 ...
- javascript中一些常见的兼容性问题
下面是一些Javascript的IE和Firefox(火狐)兼容性的常用例子 1. document.formName.item("itemName") 问题 说明:IE下,可以使 ...
- Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...
- ElasticSearch+Kibana 索引操作( 附源码)
一 前言 ElasticiSearch 简介 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.Elastics ...
- ajax 多级联动 下拉框 Demo
写了ajax实现级联下拉框,考虑常用,并且级联个数随不同业务个数不同,于是就整理了一下,实现了 ajax + N级联动 下拉框的效果 效果图 HTML 代码 <h2> 省级联动</h ...
- [转]Android自定义控件三部曲系列完全解析(动画, 绘图, 自定义View)
来源:http://blog.csdn.net/harvic880925/article/details/50995268 一.自定义控件三部曲之动画篇 1.<自定义控件三部曲之动画篇(一)—— ...
- ThreadPoolTimer -延迟执行, 周期执行
介绍重新想象 Windows 8 Store Apps 之 线程池 通过 ThreadPoolTimer 实现延迟执行 通过 ThreadPoolTimer 实现周期执行 通过 ThreadPool ...