III(二十一)Open×××(1)

 

×××virtual private network,虚拟专用网络,是依靠ISPNSP,在公共网络中建立专用的数据通信网络的技术,可以为企业间或个人与企业间提供安全的数据传输隧道服务,在×××中任意两点之间的连接并没有传统专网所需的端到端的物理链路,而是利用公共网络资源动态组成的,可理解为通过私有的隧道技术在公共数据网络上模拟出来的,和专网有同样的功能(点到点的专线技术),所谓虚拟是指不需要去拉实际的长途物理链路,借用公共internet实现;

×××的作用:帮助公司里的远程用户(出差或家里)、公司的分支机构、商业合作伙伴、供应商等公司和自己的公司内部网络之间建立可信的安全连接或是局域网连接,确保数据的加密安全传输和业务访问,对运维来说,可连接不同的机房为LAN处理相关业务流;

 

×××分类,根据常见的企业应用分4类:

1、远程访问×××服务(个人电脑远程拨号到企业办公网络,访问域控制器,file serverOA systemERPHTTP服务,内网聊天工具等LAN应用),对运维人员,个人电脑远程拨号到企业网站IDC机房,远程维护IDC内网服务器、DB、存储等,一般server无外网IP),牤牛阵法;

2、企业内部网络之间×××服务(公司分支机构的LAN和总部的LAN×××连接),如超市间业务结算等;

3、互联网公司多IDC机房间×××服务(运维、架构人员考虑,不同机房间业务管理和业务访问数据流动);

4、企业外部×××服务(供应商、合作伙伴的LAN和本公司的LAN间建立×××服务);

5、访问国外的网站(×××应用)

 

 

常见的隧道协议:

PPTPpoint point tunneling protocolmicrosoft3com公司开发使用PAPCHAPMPPE加密算法,通过跨越基于tcp/ip的数据网络创建×××PPTP允许加密IP通讯,典型的Linux平台的开源软件pptp,常用于用户client到远端企业办公,不擅长企业与企业间通信;

L2TPlayer 2 tunneling protocol,第2层隧道协议,是IETF基于L2Fcisco的第二层转发转发协议)开发的PPTP后续版本,是一种工业标准internet隧道协议;

IPSecIP security,实际上是一套协议包而不是一个独立的协议,IPSec隧道模式的整个过程是封装路由与解封装,隧道将原始数据包隐藏(或封装)在新的数据包内部,新封装的数据包可能会有新的寻址与路由信息,从而通过网络传输,隧道与数据结合使用时,在网络上窃听通讯的人将无法获取原始数据包及最原始的源和目标,封装的数据包到达目的地后,会删除封装,原始数据包头用于将数据包路由到最终目的地,IDC机房间互联组成LAN常用IPSec

SSL ×××SSL协议(传输层和应用层之间)提供了数据私密性、端点验证、信息完整性等特性,SSL由许多子协议组成(握手协议和记录协议),握手协议允许serverclient在应用协议传输第一个数据字节以前,彼此确认,协商一种加密算法和密码钥匙,在数据传输期间,记录协议利用握手协议生成的密钥加密和解密来交换数据;SSL独立于应用,任何一个应用程序都可享受它的安全性而不必理会执行细节;SSL本身被几乎所有的web browser支持;后面这两点是SSL能应用于×××的关键,典型的SSL ×××应用为open ***

注:

PPTPL2TP都使用PPP协议对数据进行封装,再添加附加包头用于数据在互联网上传输;

PPTP只在两端点间建立单一隧道,L2TP支持在两端点间使用多隧道;

PPTP要求互联网络为tcp/ip网络,而L2TP范围更广只要求隧道媒介提供面向数据包的点对点连接,如帧中继等;

PPTP不支持隧道验证,而L2TP可提供隧道验证;

一般在使用PPTPL2TP时都要结合IPSec一同使用,由IPSec提供隧道验证加密数据等工作

 

wKioL1eQHqDhc-S_AABEevm4BLc378.jpg

 

×××的开源实现:

PPTP ×××(最大优势无需在win上安装客户端,OS上本身就有拨号软件,默认支持PPTP ×××拨号连接,适合远程的企业用户拨号到企业进行办公,点对点应用,很多小区的网络设备不支持PPTP导致无法访问);

SSL ×××open ***,不但适用于PPTP×××的场景,还适合针对企业异地总公司和分公司之间不间断的×××连接,如ERPOA、即时通讯工具等企业级应用,需安装客户端软件);

IPSec ×××open swan,适用于异地总公司和分公司之间或多个IDC机房间的×××不间断按需连接,在部署上使用上简单方便);

 

根据企业生产场景需求选择×××方案建议:

1、如果公司财力宽裕,可选择硬件产品,如防火墙firewallLB负载均衡器等硬件产品都附带×××功能);

2、对于互联网公司,为体现运维架构师的价值,首选开源产品,优势:省钱、可扩展性强,每个机房可有两台×××做高可用、可二次开发;

3、对于开源产品,个人拨号选open***(功能强大,稳定可靠),若不想单独安装client拨号软件,可选择PPTP;多个企业之间互连或多个IDC机房间互连选择IPSec ***open***,这两个可以满足各种企业需求;

 

 

open***C/S架构,Linux下开源×××的先锋,提供了良好的访问性能和友好的用户GUI,允许用户使用私钥、第三方证书、用户名/密码来进行身份验证,它大量使用了openssl加密库(依赖opnenssl)和SSLv3/TLSv1协议,它可在LinuxxBSDMacwin平台上运行,open ***不是一个基于web***软件,也不与IPSec及其它×××软件包兼容,是C/S架构的软件需单独安装open ***客户端(不如PPTP的唯一一点));

SSLsecure sockets layer,安全套接层,是一种安全协议,诞生的目的是为网络通信提供安全及数据完整性保障,SSL在传输层中对网络通信进行加密,SSL采用公开密钥技术,保证两个应用间通信的保密性和可靠性,使客户和server应用之间的通信不被***者窃听,是互联网保密通讯的工业标准;

TLSSSL的继任者,transportlayer security,利用密钥算法在互联网上提供端点身份认证与通讯保密,其基础是公钥基础设施PKIpublic key infrastructure

open***加密通信原理:使用TLS加密,通过使用公开密钥(非对称密钥,public keyprivate key)对数据进行加密,server端和client要有相同CA签发的证书,双方通过交换证书验证双方的合法性,决定是否建立×××连接,然后使用对方的CA把自己目前使用的数据加密方法加密后发送给对方,由于使用对方CA加密的只有对方CA对应的private key才能解密该字串,保证了此密钥的安全性,并且此密钥定期改变,对于窃听者还没破解出密钥,通信双方已更换密钥了;

open***的多种身份验证方式:预享密钥(最简单,只能用于点对点的×××);基于PKI的第三方证书(功能最完善,但需额外精力维护PKI体系);用户名/密码(需CA证书要作加密);其它(LDAP或统一验证);

open***通信原理(基于单一的ip port1194,默认UDPTCP也支持,技术核心(虚拟网卡和SSL协议实现));

 

用户远程拨号到企业Open ×××的场景:

wKiom1eQHtHAF9HAAAAz3qCG4AA828.jpg

上图注:

172.16.1.xLAN地址,10.96.20.113模拟外网地址,用户通过连接×××server即可访问到局域网内的任何一台计算机;

***服务启动后有虚拟网卡地址10.8.0.xclient拨号到××× server上后访问LAN内的server时用的是10.8.0.x这个地址;

clientLAN server双方间建立通信,有两种方案:

方案一:LAN server{1,2...}要么添加172.16.1.11这个地址为默认网关,要么添加网络路由,否则client将收不到LAN server{1,2}的包信息;

方案二:在××× server上实现NAT,在××× server上由10.8.0.x改为172.16.1.11

 

企业IDC机房互连(IPCSec ×××):

wKioL1eQHyCB2o96AABHsVvYgJo446.jpg

上图注:

××× server使用open***,要一端是server端,另一端是client,由client请求连接server端;

××× serverIPCSec×××,两端都是server端,若IDC机房多的话,要避免环状连接,要一对多互联;

3IDC机房做ldap认证,有一个IDC机房是open***-serverldap-primary,其它机房均为open***-clientldap-slave,机房间任何通信走***通道,各自机房负责自己的认证,仅当主崩溃时slave替代主做远程使用

注:open***ipsec做机房互连,更多的是功能应用,若大数据传输,实时性要求不高,这不适合应走光纤专线

wKiom1eQHz-i79X0AAAzXfOfssw816.jpg

上图注:

应用场景:企业间互连;数据同步、备份;异地数据读取/写入(同一业务跨机房集群架构最好是写,尽量少读)

 

 

open***实战(在个人电脑的物理机上安装open***客户端工具,在远端拨号到***server,管理LAN内的多个server):

win-client10.96.20.252

××× servervmware的虚拟机上,桥接,eth0:10.96.20.113eth1:172.16.1.11

LAN server1vmware的虚拟机上,桥接,eth0:172.16.1.12

wKioL1eQH1PhcWwdAAAz3qCG4AA905.jpg

 

*** server端:

[root@localhost ~]# cat /etc/redhat-release

Red Hat Enterprise Linux Server release 6.5(Santiago)

[root@localhost ~]# uname -rm

2.6.32-431.el6.x86_64 x86_64

[root@localhost ~]# yum grouplist

……

Installed Groups:

  Additional Development

   Base

   Compatibility libraries

   Debugging Tools

  Desktop

  Desktop Platform

  Desktop Platform Development

   Development tools

   Dial-up Networking Support

  Directory Client

  E-mail server

  Fonts

  General Purpose Desktop

  Graphical Administration Tools

   Hardware monitoring utilities

  Internet Browser

  Legacy UNIX compatibility

  Legacy X Window System compatibility

  MySQL Database client

  Network Infrastructure Server

  Networking Tools

   Performance Tools

  Perl Support

……

[root@localhost ~]# service ntpd status

ntpd is stopped

[root@localhost ~]# ntpdate pool.ntp.org   #(当前同步,或与wintime.windows.com

14 Jul 03:02:51 ntpdate[3187]: step timeserver 115.28.122.198 offset -61.726348 sec

[root@localhost ~]# date

Thu Jul 14 03:02:55 PDT 2016

[root@localhost ~]# crontab -e

#time sync

*/5 * * * * /usr/sbin/ntpdate pool.ntp.org &> /dev/null

[root@localhost ~]# service crond restart

Stopping crond:                                           [  OK  ]

Starting crond:                                           [  OK  ]

[root@localhost ~]# mkdir -pv /home/webgame/tools/open***   #(指定一目录存放要安装的软件,所有人安装软件都应在指定的目录下)

mkdir: created directory`/home/webgame/tools'

mkdir: created directory`/home/webgame/tools/open***'

[root@localhost ~]# cd !$

cd /home/webgame/tools/open***

 

http://www.oberhumer.com/opensource/lzo/lzo下载)

https://open***.net/index.php/download/community-downloads.html(最新版下载)

http://swupdate.open***.org/community/releases/(旧版本下载)

 

[root@localhost open***]# rz

[root@localhost open***]# ll

total 1476

-rw-r--r--. 1 root root 594855 Jul 14 03:48lzo-2.09.tar.gz

-rw-r--r--. 1 root root 911158 Jul 14 03:58open***-2.2.2.tar.gz

 

[root@localhost open***]# tar xflzo-2.09.tar.gz

[root@localhost open***]# cd lzo-2.09

[root@localhost lzo-2.09]# ./configure

[root@localhost lzo-2.09]# make

[root@localhost lzo-2.09]# echo $?

0

[root@localhost lzo-2.09]# make install

……

[root@localhost lzo-2.09]# cd ../

[root@localhost open***]# rpm -qa openssl-devel

openssl-devel-1.0.1e-15.el6.x86_64

[root@localhost open***]# tar xf open***-2.2.2.tar.gz

[root@localhost open***]# cd open***-2.2.2

[root@localhost open***-2.2.2]# ./configure --with-lzo-headers=/usr/local/include --with-lzo-lib=/usr/local/lib

注:编译安装2.3.11版本时,要先安装openssl-devepam-devellzo-devel包,编译时不用选项—with-lzo-headers—with-lzo-lib2.3.11没自带easy-rsa要下载https://github.com/Open×××/easy-rsa/archive/master.zip

[root@localhost open***-2.2.2]# make && make install

……

[root@localhost open***-2.2.2]# cd ..

[root@localhost open***]# which open***

/usr/local/sbin/open***

 

[root@localhost open***]# cd open***-2.2.2/easy-rsa/2.0/   #(该目录下均是脚本文件,pkitool脚本直接使用vars脚本文件,非交互生成证书)

[root@localhost 2.0]# ls

build-ca    build-key        build-key-server  clean-all      Makefile           openssl-1.0.0.cnf  revoke-full whichopensslcnf

build-dh    build-key-pass    build-req         inherit-inter  openssl-0.9.6.cnf  pkitool            sign-req

build-inter build-key-pkcs12 build-req-pass    list-crl       openssl-0.9.8.cnf  README             vars

[root@localhost 2.0]# cp vars vars.backup_20160714

[root@localhost 2.0]# vim vars   #2.0.95条)和2.2.211条)此文件内容不一样,此文件最后export内容为创建环境变量,设置所要用的变量脚本)

……

export KEY_COUNTRY="CN"

export KEY_PROVINCE="SH"

export KEY_CITY="ShangHai"

export KEY_ORG="qikai"

exportKEY_EMAIL="chaizaowen@163.com"

export KEY_EMAIL=chaizaowen@163.com

export KEY_CN=CN

export KEY_NAME=qikai

export KEY_OU=qikai

export PKCS11_MODULE_PATH=changeme

export PKCS11_PIN=1234

[root@localhost 2.0]# source vars

NOTE: If you run ./clean-all, I will bedoing a rm -rf on /home/webgame/tools/open***/open***-2.2.2/easy-rsa/2.0/keys

[root@localhost 2.0]# ./clean-all   #(清除所有相关证书,创建生成ca证书及密钥文件所需的文件及目录)

 

[root@localhost 2.0]# ./build-ca

Generating a 1024 bit RSA private key

.++++++

........++++++

writing new private key to 'ca.key'

-----

You are about to be asked to enterinformation that will be incorporated

into your certificate request.

What you are about to enter is what iscalled a Distinguished Name or a DN.

There are quite a few fields but you canleave some blank

For some fields there will be a defaultvalue,

If you enter '.', the field will be leftblank.

-----

Country Name (2 letter code) [CN]:

State or Province Name (full name) [SH]:

Locality Name (eg, city) [ShangHai]:

Organization Name (eg, company) [qikai]:

Organizational Unit Name (eg, section)[qikai]:

Common Name (eg, yourname or your server's hostname) [CN]:qikai

Name [qikai]:

Email Address [chaizaowen@163.com]:

[root@localhost 2.0]# ll keys/   #crtcertificateca.keyprivate key

total 12

-rw-r--r--. 1 root root 1310 Jul 14 04:30ca.crt

-rw-------. 1 root root  916 Jul 14 04:30 ca.key

-rw-r--r--. 1 root root    0 Jul 14 04:28 index.txt

-rw-r--r--. 1 root root    3 Jul 14 04:28 serial

 

[root@localhost 2.0]# ./build-key-server server  #(生成×××server的密钥)

Generating a 1024 bit RSA private key

...........++++++

..............++++++

writing new private key to 'server.key'

-----

You are about to be asked to enterinformation that will be incorporated

into your certificate request.

What you are about to enter is what iscalled a Distinguished Name or a DN.

There are quite a few fields but you canleave some blank

For some fields there will be a defaultvalue,

If you enter '.', the field will be leftblank.

-----

Country Name (2 letter code) [CN]:

State or Province Name (full name) [SH]:

Locality Name (eg, city) [ShangHai]:

Organization Name (eg, company) [qikai]:

Organizational Unit Name (eg, section)[qikai]:

Common Name (eg, yourname or your server's hostname) [server]:               

Name [qikai]:

Email Address [chaizaowen@163.com]:

Please enter the following 'extra'attributes

to be sent with your certificate request

A challenge password []:123456

An optional company name []:qikai

Using configuration from/home/webgame/tools/open***/open***-2.2.2/easy-rsa/2.0/openssl-1.0.0.cnf

Check that the request matches thesignature

Signature ok

The Subject's Distinguished Name is asfollows

countryName           :PRINTABLE:'CN'

stateOrProvinceName   :PRINTABLE:'SH'

localityName          :PRINTABLE:'ShangHai'

organizationName      :PRINTABLE:'qikai'

organizationalUnitName:PRINTABLE:'qikai'

commonName            :PRINTABLE:'server'

name                  :PRINTABLE:'qikai'

emailAddress          :IA5STRING:'chaizaowen@163.com'

Certificate is to be certified until Jul 1306:15:27 2026 GMT (3650 days)

Sign the certificate? [y/n]:y

1 out of 1 certificate requests certified,commit? [y/n]y

Write out database with 1 new entries

Data Base Updated

 

[root@localhost 2.0]# ll keys/   #(生成了server.crtserver.keyserver.csr

total 40

-rw-r--r--. 1 root root 4000 Jul 14 23:1501.pem

-rw-r--r--. 1 root root 1310 Jul 14 04:30ca.crt

-rw-------. 1 root root  916 Jul 14 04:30 ca.key

-rw-r--r--. 1 root root  121 Jul 14 23:15 index.txt

-rw-r--r--. 1 root root   21 Jul 14 23:15 index.txt.attr

-rw-r--r--. 1 root root    0 Jul 14 04:28 index.txt.old

-rw-r--r--. 1 root root    3 Jul 14 23:15 serial

-rw-r--r--. 1 root root    3 Jul 14 04:28 serial.old

-rw-r--r--. 1 root root 4000 Jul 14 23:15server.crt

-rw-r--r--. 1 root root  769 Jul 14 23:15 server.csr

-rw-------. 1 root root  916 Jul 14 23:15 server.key

 

[root@localhost 2.0]# ./build-key test   (生成client的密钥,使用build-key这种方式生成的密钥拨号不再需要密码,而用build-key-pass脚本生成的密钥拨号时要输入密码即拨号的密码,公司中的每一个人(每一个远程登录的用户)都应有.crt.key这样的文件)

Generating a 1024 bit RSA private key

..............++++++

.............................++++++

writing new private key to 'test.key'

-----

You are about to be asked to enterinformation that will be incorporated

into your certificate request.

What you are about to enter is what iscalled a Distinguished Name or a DN.

There are quite a few fields but you canleave some blank

For some fields there will be a defaultvalue,

If you enter '.', the field will be leftblank.

-----

Country Name (2 letter code) [CN]:

State or Province Name (full name) [SH]:

Locality Name (eg, city) [ShangHai]:

Organization Name (eg, company) [qikai]:

Organizational Unit Name (eg, section)[qikai]:

Common Name (eg, yourname or your server's hostname) [test]:

Name [qikai]:

Email Address [chaizaowen@163.com]:

Please enter the following 'extra'attributes

to be sent with your certificate request

A challenge password []:123456

An optional company name []:qikai

Using configuration from/home/webgame/tools/open***/open***-2.2.2/easy-rsa/2.0/openssl-1.0.0.cnf

Check that the request matches thesignature

Signature ok

The Subject's Distinguished Name is asfollows

countryName           :PRINTABLE:'CN'

stateOrProvinceName   :PRINTABLE:'SH'

localityName          :PRINTABLE:'ShangHai'

organizationName      :PRINTABLE:'qikai'

organizationalUnitName:PRINTABLE:'qikai'

commonName            :PRINTABLE:'test'

name                  :PRINTABLE:'qikai'

emailAddress          :IA5STRING:'chaizaowen@163.com'

Certificate is to be certified until Jul 1306:22:10 2026 GMT (3650 days)

Sign the certificate? [y/n]:y

1 out of 1 certificate requests certified,commit? [y/n]y

Write out database with 1 new entries

Data Base Updated

[root@localhost 2.0]# ll keys/

total 64

-rw-r--r--. 1 root root 4000 Jul 14 23:1501.pem

-rw-r--r--. 1 root root 3872 Jul 14 23:2202.pem

-rw-r--r--. 1 root root 1310 Jul 14 04:30ca.crt

-rw-------. 1 root root  916 Jul 14 04:30 ca.key

-rw-r--r--. 1 root root  240 Jul 14 23:22 index.txt

-rw-r--r--. 1 root root   21 Jul 14 23:22 index.txt.attr

-rw-r--r--. 1 root root   21 Jul 14 23:15 index.txt.attr.old

-rw-r--r--. 1 root root  121 Jul 14 23:15 index.txt.old

-rw-r--r--. 1 root root    3 Jul 14 23:22 serial

-rw-r--r--. 1 root root    3 Jul 14 23:15 serial.old

-rw-r--r--. 1 root root 4000 Jul 14 23:15server.crt

-rw-r--r--. 1 root root  769 Jul 14 23:15 server.csr

-rw-------. 1 root root  916 Jul 14 23:15 server.key

-rw-r--r--. 1 root root 3872 Jul 14 23:22test.crt

-rw-r--r--. 1 root root  765 Jul 14 23:22 test.csr

-rw-------. 1 root root  916 Jul 14 23:22 test.key

 

[root@localhost 2.0]# ./build-key-pass ett  #(生成client密钥,此种方式生成的拨号时需输入密码)

Generating a 1024 bit RSA private key

.............++++++

..++++++

writing new private key to 'ett.key'

Enter PEM pass phrase:

Verifying - Enter PEMpass phrase:

-----

You are about to be asked to enterinformation that will be incorporated

into your certificate request.

What you are about to enter is what iscalled a Distinguished Name or a DN.

There are quite a few fields but you canleave some blank

For some fields there will be a defaultvalue,

If you enter '.', the field will be leftblank.

-----

Country Name (2 letter code) [CN]:

State or Province Name (full name) [SH]:

Locality Name (eg, city) [ShangHai]:

Organization Name (eg, company) [qikai]:

Organizational Unit Name (eg, section)[qikai]:

Common Name (eg, your name or your server'shostname) [ett]:

Name [qikai]:

Email Address [chaizaowen@163.com]:

Please enter the following 'extra'attributes

to be sent with your certificate request

A challenge password []:123456

An optional company name []:qikai

Using configuration from/home/webgame/tools/open***/open***-2.2.2/easy-rsa/2.0/openssl-1.0.0.cnf

Check that the request matches thesignature

Signature ok

The Subject's Distinguished Name is asfollows

countryName           :PRINTABLE:'CN'

stateOrProvinceName   :PRINTABLE:'SH'

localityName          :PRINTABLE:'ShangHai'

organizationName      :PRINTABLE:'qikai'

organizationalUnitName:PRINTABLE:'qikai'

commonName            :PRINTABLE:'ett'

name                  :PRINTABLE:'qikai'

emailAddress          :IA5STRING:'chaizaowen@163.com'

Certificate is to be certified until Jul 1306:28:05 2026 GMT (3650 days)

Sign the certificate? [y/n]:y

1 out of 1 certificate requests certified,commit? [y/n]y

Write out database with 1 new entries

Data Base Updated

[root@localhost 2.0]# ll keys/

total 80

-rw-r--r--. 1 root root 4000 Jul 14 23:1501.pem

-rw-r--r--. 1 root root 3872 Jul 14 23:2202.pem

-rw-r--r--. 1 root root 3871 Jul 14 23:2803.pem

-rw-r--r--. 1 root root 1310 Jul 14 04:30ca.crt

-rw-------. 1 root root  916 Jul 14 04:30 ca.key

-rw-r--r--. 1 root root 3871 Jul 14 23:28ett.crt

-rw-r--r--. 1 root root  765 Jul 14 23:28 ett.csr

-rw-------. 1 root root 1041 Jul 14 23:28ett.key

-rw-r--r--. 1 root root  358 Jul 14 23:28 index.txt

-rw-r--r--. 1 root root   21 Jul 14 23:28 index.txt.attr

-rw-r--r--. 1 root root   21 Jul 14 23:22 index.txt.attr.old

-rw-r--r--. 1 root root  240 Jul 14 23:22 index.txt.old

-rw-r--r--. 1 root root    3 Jul 14 23:28 serial

-rw-r--r--. 1 root root    3 Jul 14 23:22 serial.old

-rw-r--r--. 1 root root 4000 Jul 14 23:15server.crt

-rw-r--r--. 1 root root  769 Jul 14 23:15 server.csr

-rw-------. 1 root root  916 Jul 14 23:15 server.key

-rw-r--r--. 1 root root 3872 Jul 14 23:22test.crt

-rw-r--r--. 1 root root  765 Jul 14 23:22 test.csr

-rw-------. 1 root root  916 Jul 14 23:22 test.key

 

[root@localhost 2.0]# ./build-dh   #(生成deffie-Hellman文件,generate deffie hellmanparameters生成传输进行密钥交换时用到的交换密钥协议文件)

Generating DH parameters, 1024 bit longsafe prime, generator 2

This is going to take a long time

.....................................+……

[root@localhost 2.0]# ll keys/dh1024.pem

-rw-r--r--. 1 root root 245 Jul 14 23:32keys/dh1024.pem

 

[root@localhost 2.0]# open*** --genkey --secret keys/ta.key   #(为防止DDosudp portfloating,生成HMAC firewall

[root@localhost 2.0]# ll keys/ta.key

-rw-------. 1 root root 636 Jul 14 23:38keys/ta.key

 

注:#./make-crl ***crl.pem(生成证书吊销链文件,防止之后有人丢失证书,被非法用户接入×××

 

[root@localhost 2.0]# mkdir -p /etc/open***

[root@localhost 2.0]# cp -ap /home/webgame/tools/open***/open***-2.2.2/easy-rsa/2.0/keys/ /etc/open***

[root@localhost 2.0]# cp /home/webgame/tools/open***/open***-2.2.2/sample-config-files/{server.conf,client.conf} /etc/open***

[root@localhost 2.0]# tree /etc/open***

/etc/open***

├── client.conf

├── keys

   ├── 01.pem

   ├── 02.pem

   ├── 03.pem

   ├── ca.crt

   ├── ca.key

   ├── dh1024.pem

   ├── ett.crt

   ├── ett.csr

   ├── ett.key

   ├── index.txt

   ├── index.txt.attr

   ├── index.txt.attr.old

   ├── index.txt.old

   ├── serial

   ├── serial.old

   ├── server.crt

   ├── server.csr

   ├── server.key

   ├── ta.key

   ├── test.crt

   ├── test.csr

   └── test.key

└── server.conf

1 directory, 24 files

[root@localhost 2.0]# cd /etc/open***

[root@localhost open***]# egrep -v ";|#|^$" server.conf   #local IP_ADDRESSopen***启动时监听的地址,外网IPclient访问时指定的IP,类似nginx*:80);port 1194(默认1194,为安全改为52115);proto udp(默认udp,为稳定改为tcp);dev tun***server的模式采用路由模式,可选taptun);ca ca.crtcacerticate,此文件要和server.conf在一个目录下,否则要用绝对路径);server 10.8.0.0 255.255.255.0***server动态分配给***client的地址池);push "route 172.16.1.0 255.255.255.0"***server的内网网段,***server将路由推至client,公司内部网络已划分vLAN的话可写多个push);client-to-client(多个client连在一个***server上,有此项则他们之间是可通信的);duplicate-cn(允许多个client使用同一个帐号连接***server);keepalive 10 120(每10s ping一次,若是120s未收到包则认定client断线);comp-lzo(开启压缩功能);persist-key(当***超时后,再次重启***后,保持上一次使用的私钥,而不重新读取私钥);persist-tun(通过keepalive检测***超时后,再重启后,保持tuntap设备自动连接状态);status open***-status.log(日志状态信息);log/var/log/open***.log(指定日志位置);verb 3(指定日志文件冗余))

port 1194

proto udp

dev tun

ca ca.crt

cert server.crt

dh dh1024.pem

server 10.8.0.0 255.255.255.0

ifconfig-pool-persist ipp.txt

keepalive 10 120

comp-lzo

persist-key

persist-tun

status open***-status.log

verb 3

 

[root@localhost open***]# egrep -v ";|#|^$" client.conf

client

dev tun

proto udp

remote my-server-1 1194

resolv-retry infinite

nobind

persist-key

persist-tun

ca ca.crt

cert client.crt

key client.key

ns-cert-type server

comp-lzo

verb 3

 

[root@localhost open***]# vim server.conf

-----------file start--------------

local 10.96.20.113

port 52115

proto tcp

dev tun

ca keys/ca.crt

cert keys/server.crt

key keys/server.key

dh keys/dh1024.pem

server 10.8.0.0 255.255.255.0

ifconfig-pool-persist ipp.txt

push "route 172.16.1.0255.255.255.0"

client-to-client

keepalive 10 120

comp-lzo

persist-key

persist-tun

status open***-status.log

log /var/log/open***.log

verb 3

-------------file end------------------

 

[root@localhost open***]# service iptables stop   #(若开启防火墙,不仅要开启对应的52115portforward链也要打开)

[root@localhost open***]# getenforce   #selinux

Permissive

[root@localhost open***]# sed -i 's/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/' /etc/sysctl.conf

[root@localhost open***]# sysctl -p

net.ipv4.ip_forward = 1

net.ipv4.conf.default.rp_filter = 1

net.ipv4.conf.default.accept_source_route =0

……

 

[root@localhost open***]# echo "/usr/local/sbin/open*** --config /etc/open***/server.conf &" >> /etc/rc.local   #(开机自启)

[root@localhost open***]# tail -1 /etc/rc.local

tail: inotify cannot be used, reverting topolling

/usr/local/sbin/open*** --config/etc/open***/server.conf &

 

[root@localhost open***]# open*** --config /etc/open***/server.conf &

[1] 18159

[root@localhost open***]# netstat -tnulp | grep :52115

tcp       0      0 10.96.20.113:52115       0.0.0.0:*                   LISTEN      18159/open***      

[root@localhost open***]# lsof -i :52115

COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

open*** 18159 root    5u IPv4 111541      0t0  TCP 10.96.20.113:52115 (LISTEN)

[root@localhost open***]# tail -100 /var/log/open***.log

……

Fri Jul 15 01:04:02 2016 MULTI: TCP INITmaxclients=1024 maxevents=1028

Fri Jul 15 01:04:02 2016 InitializationSequence Completed

[root@localhost open***]# ifconfig tun0   #(本地会多出虚拟网卡tun010.8.0.1

tun0     Link encap:UNSPEC  HWaddr00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 

         inet addr:10.8.0.1  P-t-P:10.8.0.2  Mask:255.255.255.255

         UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500  Metric:1

         RX packets:0 errors:0 dropped:0 overruns:0 frame:0

         TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

         collisions:0 txqueuelen:100

         RX bytes:0 (0.0 b)  TX bytes:0(0.0 b)

 

[root@localhost open***]# cp /home/webgame/tools/open***/open***-2.2.2/sample-scripts/open***.init /etc/init.d/open***   #open***自带有脚本,启动前要对脚本文件稍作如下修改才能用)

[root@localhost open***]# vim /etc/init.d/open***   #(修改148行的*.confserver.conf或确保/etc/open***下仅有server.conf这一个.conf结尾的文件;修改154行为/usr/local/sbin/open***--daemon --writepid /var/run/open***/server.pid --config server.conf --cd/etc/open***

[root@localhost open***]# ll /etc/init.d/open***

-rwxr-xr-x. 1 root root 5481 Jul 15 01:11/etc/init.d/open***

[root@localhost open***]# chkconfig --add open***

[root@localhost open***]# chkconfig --list open***

open***           0:off 1:off 2:off 3:on 4:on 5:on 6:off

[root@localhost open***]# pkill open***

[root@localhost open***]# netstat -tnulp | grep :52115

[1]+ Done                    open***--config /etc/open***/server.conf

[root@localhost open***]# lsof -i :52115

[root@localhost open***]# service open*** start

Starting open***:                                         [  OK  ]

[root@localhost open***]# service open*** restart

Shutting down open***:                                     [  OK  ]

Starting open***:                                         [  OK  ]

 

win上部署client

注:通过测试,vmware上用win的虚机能成功连接*** server但不能连接LAN的主机;直接在物理机的win OS上正常,既能连通*** server又能成功连通LAN的主机

在物理机的win上安装open***-2.2.2-install.exe

client的安装目录下的config/下创建test/目录;

*** server/etc/open***/keys/{ca.crt,test.crt,test.key}拷贝至win的Open××× GUI安装目录D:\Program Files (x86)\Open×××\config\test\下;

[root@localhost open***]# egrep -v ";|#|^$" client.conf   #(在***server端将client.conf此文件修改好,拷贝到winconfig/test/下并改名为test.o***

client

dev tun

proto tcp

remote 10.96.20.113 52115

resolv-retry infinite

nobind

persist-key

persist-tun

ca ca.crt

cert test.crt

key test.key

ns-cert-type server

comp-lzo

verb 3

wKioL1eQIOzQ4FxlAABOwnunhBA637.jpg

打开win上的Open××× GUI,在任务栏图标右键Connect,图标变绿表示成功,黄和红均是有问题,右键View Log(也可查看*** server上的日志),*** server给此client分配的地址为10.8.0.6

wKioL1eQIPmiylHgAABaJciyOm0070.jpg

wKioL1eQIQ7jMnXHAAAxspGZV6E932.jpg

wKiom1eQIR6TIrBlAADXjLs8fGQ452.jpg

wKiom1eQIR-BKwp_AABPGQriE5E829.jpg

win上测试与*** server的连通性,ping 10.8.0.1看是否能ping

wKioL1eQITCzzHy2AACAH0JkSMA829.jpg

win的命令行下,在***拨通情况下>route print > ed.txt,然后断开Open×××,执行>route print > pre.txt,再用BeyondCompare工具比较两个文件的差别,172.16.1.0/24*** server push过来的

wKioL1eQIT3AzX5VAACws9Y4VyY679.jpg

 

LAN-server1端(172.16.1.12):

三种方案:

1、将*** server上的地址添加为默认路由,不常用

#route add default gw 172.16.1.11

wKiom1eQIVrRYqUBAAA15ToKph4813.jpg

2、添加网络路由,这是生产中常见的做法,所有LAN的主机都要添加这一条网络路由

#route add -net 10.8.0.0/24 gw 172.16.1.11

wKioL1eQIWbDMZ0DAABFjRxMEUE838.jpg

3、在*** server上用NAT方式实现

open***port要开放,FORWARDaccept

[root@etiantian ~]# iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth1 -j SNAT --to-source 172.16.1.11

[root@etiantian ~]# iptables -t nat -L -n

……

Chain POSTROUTING (policy ACCEPT)

target    prot opt source              destination        

SNAT      all  --  10.8.0.0/24          0.0.0.0/0           to:172.16.1.11

……

[root@etiantian ~]# vim /home/webgame/tools/open***/open***-2.2.2/sample-config-files/firewall.sh   #(安装目录下有程序提供的firewall防火墙的设置脚本)

 

 

注:若没有操作以上三种方案中的任何一种,那client能连上*** server,但LAN server1的包无法返回,在clientping 172.16.1.12不通

wKiom1eQIbjjVk0IAABQNQBhCJc752.jpg

LAN server1上抓包,只有ICMP echo request而没有ICMP echo reply

wKioL1eQIcbwPCwvAAB6G2J15yg343.jpg

按以上三种方案中任一一种操作,在LAN-server1上抓包,同时在clientping

wKiom1eQIdPiiAXUAACIKo_BKUM279.jpg

wKioL1eQId6DsdHgAAC3MBbF070702.jpg

 

 

注:配置静态路由方法,三种:

1#echo "any net 10.8.0.0/24 gw 172.16.111" > /etc/sysconfig/static-routes

wKiom1eQIerjS7AxAACP_pPTVFY117.jpg

2#echo "10.8.0.0/24 via 172.16.1.11" > /etc/sysconfig/network-scripts/route-eth0

wKioL1eQIgXipQ6AAACpG0hBfvU813.jpg

3#echo "route add -net 10.8.0.0/24 gw 172.16.1.11" >> /etc/rc.local   #(使得开机可自动执行生效)

 

使用build-key-pass增加用户jowin

[root@etiantian ~]# cd /home/webgame/tools/open***/open***-2.2.2/easy-rsa/2.0/

[root@etiantian 2.0]# source vars

NOTE: If you run ./clean-all, I will bedoing a rm -rf on /home/webgame/tools/open***/open***-2.2.2/easy-rsa/2.0/keys

[root@etiantian 2.0]# ./build-key-pass jowin

Enter PEM pass phrase:

Verifying - Enter PEM pass phrase:

Common Name (eg, your name or your server'shostname) [jowin]:

A challenge password []:123456

An optional company name []:qikai

[root@etiantian 2.0]# ll keys/jowin*

-rw-r--r--. 1 root root 3877 Jul 20 00:27keys/jowin.crt

-rw-r--r--. 1 root root  769 Jul 20 00:26 keys/jowin.csr

-rw-------. 1 root root 1041 Jul 20 00:26keys/jowin.key

[root@etiantian 2.0]# cp keys/{jowin.crt,jowin.key} /etc/open***/keys/

[root@etiantian 2.0]# szkeys/{jowin.crt,jowin.key,ca.crt}   #(上传至clientconfig/下)

[root@etiantian 2.0]# vim/etc/open***/client.conf   #(修改certkey

……

remote 10.96.20.113 52115

……

ca ca.crt

cert jowin.crt

key jowin.key

……

[root@etiantian 2.0]# sz /etc/open***/client.conf   #(上传至clientconfig/下)

wKioL1eQIjyCKZO8AABMoeEtNsU375.jpg

wKiom1eQIk7RYJcXAAAf5g2AGgI168.jpg

 使用jowin 连接,用build-key-pass创建的用户需键入密码

wKioL1eQInfhM5ToAABaW9DAMlc784.jpg

wKiom1eQIneygdQoAAAi86sAjqM212.jpg

[root@etiantian2.0]# cat /etc/open***/open***-status.log   #(在*** server端通过查看此文件,可知当前有谁在登录,通过查看可将离职员工的证书吊销,若仍旧登录时还可实现报警功能)

Open×××CLIENT LIST

Updated,WedJul 20 00:49:43 2016

CommonName,Real Address,Bytes Received,Bytes Sent,Connected Since

jowin,10.96.20.252:2715,8562,6368,WedJul 20 00:47:43 2016

ROUTINGTABLE

VirtualAddress,Common Name,Real Address,Last Ref

10.8.0.10,jowin,10.96.20.252:2715,WedJul 20 00:47:44 2016

GLOBALSTATS

Maxbcast/mcast queue length,0

END

 

吊销单个证书(以用户test为例):

[root@etiantian2.0]# pwd

/home/webgame/tools/open***/open***-2.2.2/easy-rsa/2.0

[root@etiantian2.0]# source vars

NOTE: Ifyou run ./clean-all, I will be doing a rm -rf on/home/webgame/tools/open***/open***-2.2.2/easy-rsa/2.0/keys

[root@etiantian2.0]# vim openssl-1.0.0.cnf   #(若open***2.0.0版本,要注释掉这个文件中的后6行,若open***2.2.2版本此处忽略)

[root@etiantian2.0]# ./revoke-full test

Usingconfiguration from/home/webgame/tools/open***/open***-2.2.2/easy-rsa/2.0/openssl-1.0.0.cnf

RevokingCertificate 02.

DataBase Updated

Usingconfiguration from/home/webgame/tools/open***/open***-2.2.2/easy-rsa/2.0/openssl-1.0.0.cnf

test.crt:C = CN, ST = SH, L = ShangHai, O = qikai, OU = qikai, CN = test, name = qikai,emailAddress = chaizaowen@163.com

error 23at 0 depth lookup:certificate revoked

[root@etiantian2.0]# ll keys/crl.pem    #(吊销后生成此文件)

-rw-r--r--.1 root root 548 Jul 20 00:56 keys/crl.pem

[root@etiantian2.0]# date

Wed Jul20 00:57:32 PDT 2016

[root@etiantian2.0]# cat keys/index.txt   #(查看此文件,吊销用户后标记为R

V       260713061527Z                01     unknown         /C=CN/ST=SH/L=ShangHai/O=qikai/OU=qikai/CN=server/name=qikai/emailAddress=chaizaowen@163.com

R       260713062210Z       160720075655Z       02     unknown         /C=CN/ST=SH/L=ShangHai/O=qikai/OU=qikai/CN=test/name=qikai/emailAddress=chaizaowen@163.com

V       260713062805Z                03     unknown         /C=CN/ST=SH/L=ShangHai/O=qikai/OU=qikai/CN=ett/name=qikai/emailAddress=chaizaowen@163.com

V       260718072655Z                04     unknown         /C=CN/ST=SH/L=ShangHai/O=qikai/OU=qikai/CN=jowin/name=qikai/emailAddress=chaizaowen@163.com

[root@etiantian2.0]# cp keys/crl.pem /etc/open***/keys/

[root@etiantian2.0]# vim /etc/open***/server.conf   #(在此文件末尾加入crl-verify内容,若要恢复之前吊销的用户将此行注释掉即可)

crl-verify      /etc/open***/keys/crl.pem

[root@etiantian2.0]# service open*** restart

Shuttingdown open***:                                    [  OK  ]

Startingopen***:                                         [  OK  ]

注:吊销多个用户的证书与上述步骤相同,最后将./revoke-full USERNAME生成的crl.pem文件覆盖掉之前生成的即可

 

Linux下使用open***client10.96.20.117角色与win相同):

适用场景:多机房或多企业互连时;将公司内网中svn server的资源推送至IDC机房;跨机房的数据备份

[root@localhost~]# hostname ***client

[root@localhost~]# logout

环境准备,lzoopen***-2.2.2软件安装同***server

[root@***client~]# mkdir /etc/open***

[root@***client~]# cd /etc/open***

[root@***clientopen***]# ll

total 0

[root@***clientopen***]# scp 10.96.20.113:/etc/open***/keys/{ca.crt,jowin.crt,jowin.key} ./

[root@***clientopen***]# scp 10.96.20.113:/etc/open***/client.conf ./   #client.conf不用改名)

[root@***clientopen***]# vim client.conf   #(更改密钥文件路径)

ca/etc/open***/ca.crt

cert/etc/open***/jowin.crt

key/etc/open***/jowin.key

[root@***clientopen***]# cp /home/webgame/tools/open***/open***-2.2.2/sample-scripts/open***.init /etc/init.d/open***

[root@***clientopen***]# service open*** start   #jowin用户是用build-key-pass生成的每次都需输入密码)

Startingopen***: Enter Private Key Password:

                                                          [  OK  ]

[root@***clientopen***]# ping 10.8.0.1

PING10.8.0.1 (10.8.0.1) 56(84) bytes of data.

64 bytesfrom 10.8.0.1: icmp_seq=1 ttl=64 time=0.532 ms

64 bytesfrom 10.8.0.1: icmp_seq=2 ttl=64 time=0.547 ms

64 bytesfrom 10.8.0.1: icmp_seq=3 ttl=64 time=0.373 ms

……

[root@***clientopen***]# ping 172.16.1.12   pingLAN-server1通,并在LAN-server1上抓包)

PING172.16.1.12 (172.16.1.12) 56(84) bytes of data.

64 bytesfrom 172.16.1.12: icmp_seq=1 ttl=63 time=0.565 ms

64 bytesfrom 172.16.1.12: icmp_seq=2 ttl=63 time=0.522 ms

64 bytesfrom 172.16.1.12: icmp_seq=3 ttl=63 time=0.821 ms

[root@***clientopen***]# ssh 172.16.1.12   #(可成功登录到LAN-server1

root@172.16.1.12'spassword:

Lastlogin: Wed Jul 20 02:18:36 2016 from 172.16.1.11

#tcpdump-nnn -s 10000 |grep ICMP

wKioL1eQItqy5JlBAACHvaylcz8173.jpg

注:*** server使用的是NAT方式(方案三)

#tcpdump-nnn -i eth0 -s 10000 ' port 52115 and src host 10.96.20.117'

wKiom1eQIufjv1RgAADUhb2P3cM442.jpg