1. ***介绍

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

Open×××是一个用于创建虚拟专用网络加密通道的软件包,Open×××允许参与简历×××的单点使用预设的私钥,第三方证书,或者用户名/密码来进行身份验证。它大量使用了OpenSSL加密库,以及SSLv3/TLSv1协议。Open×××能在linuxxBSDMac OS、与windows上运行。他并不是一个基于web×××软件,也不与IPsec及其他×××软件兼容。

 wKiom1e5NADSsUB0AADoMpiXvJ0020.png-wh_50

2. 生产环境实战部署

2.1 环境需求

设备/项目

IP

笔记本或PCadsl上网)

192.168.1.0/24(办公室DHCP

open***(双网卡)

eth0:192.168.1.80(外网)  eth1192.168.2.80(内网)

IDC机房内部局域网的服务器

192.168.2/24IDC机房局域网服务器无外网IP,又希望adsl上网笔记本(即运维人员),在不同网络内能够直接访问他)

实现需求

在远端通过***客户端(笔记本)拨号到***server然后可以直接访问***server所在局域网内的多个servers,然后进行管理维护

2.2 查看系统环境

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

Red Hat Enterprise Linux Server release 6.5 (Santiago)

[root@localhost ~]# uname -r

2.6.32-431.el6.x86_64

[root@localhost ~]# uname -m

x86_64

[root@localhost ~]# lsb_release -a

LSB Version::base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch

Distributor ID:RedHatEnterpriseServer

Description:Red Hat Enterprise Linux Server release 6.5 (Santiago)

Release:6.5

Codename:Santiago

2.3 配置***服务器时间同步

手工执行如下命令

[root@localhost ~]# /usr/sbin/ntpdate 0.rhel.pool.ntp.org

28 May 17:24:15 ntpdate[9603]: step time server 182.92.12.11 offset 12334577.587590 sec

加入到定时任务

echo '*/5 * * * * /usr/sbin/ntpdate 0.rhel.pool.ntp.org >/dev/null 2>&1' >> /var/spool/cron/root

2.4 安装open***相关依赖软件

2.4.1 建立Open***软件存放目录

[root@localhost ~]# mkdir -p /home/yan/tools/open***

[root@localhost ~]# cd /home/yan/tools/open***

2.4.2 安装lzo压缩模块

tar -xf lzo-2.06.tar.gz

cd lzo-2.06

./configure

make && make install

2.4.3 安装open***软件

tar -xf open***-2.0.9.tar.gz

cd open***-2.0.9

./configure --with-lzo-headers=/usr/local/include --with-lzo-lib=/usr/local/lib

(需要安装依赖包yum -y install openssl-devel

make && make install

注意:可执行文件安装路径:/usr/local/sbin/open***

ll /usr/local/sbin/open***

-rwxr-xr-x. 1 root root 1875647 5月  28 17:47 /usr/local/sbin/openvp

2.4.4 配置open*** server-建立CA证书

初始化配置

cd open***-2.0.9/easy-rsa/2.0/

cp vars vars.yan.20160228

vim vars  (删除最后五行)

增加如下内容

# by yan 20160528

export KEY_COUNTRY="CN"

export KEY_PROVINCE="BJ"

export KEY_CITY="Beijing"

export KEY_ORG="yan"

export KEY_EMAIL="824412801@qq.com"

或者:(不通过vim编辑)

sed -i '$d' vars

cat >>vars<< EOF

> # by yan 20160528

> export KEY_COUNTRY="CN"

> export KEY_PROVINCE="BJ"

> export KEY_CITY="Beijing"

> export KEY_ORG="yan"

> export KEY_EMAIL="824412801@qq.com"

> EOF

开始初始化PKI

修改完vars文件后,执行source vars使前面对vars

[root@localhost 2.0]# source vars

NOTE: If you run ./clean-all, I will be doing a rm -rf on /home/yan/tools/open***/open***-2.0.9/easy-rsa/2.0/keys

然后根据提示执行

[root@localhost 2.0]# ./clean-all    清除所有证书

[root@localhost 2.0]# ./build-ca   生成CA证书

Generating a 1024 bit RSA private key

...++++++

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

writing new private key to 'ca.key'

-----

You are about to be asked to enter information that will be incorporated

into your certificate request.

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

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [CN]:  回车

State or Province Name (full name) [BJ]:  回车

Locality Name (eg, city) [Beijing]:  回车

Organization Name (eg, company) [yan]:  回车

Organizational Unit Name (eg, section) []:  回车

Common Name (eg, your name or your server's hostname) [yan CA]:yan

Email Address [824412801@qq.com]:  回车

检查生成的文件

[root@localhost 2.0]# ll keys/

总用量 12

-rw-r--r--. 1 root root 1143 5月  28 18:10 ca.crt

-rw-------. 1 root root  916 5月  28 18:10 ca.key

-rw-r--r--. 1 root root    0 5月  28 18:07 index.txt

-rw-r--r--. 1 root root    3 5月  28 18:07 serial

2.4.5 生成服务器端证书和密钥key文件

[root@localhost 2.0]# ./build-key-server server

Country Name (2 letter code) [CN]:

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

Locality Name (eg, city) [Beijing]:

Organization Name (eg, company) [yan]:

Organizational Unit Name (eg, section) []:

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

Email Address [824412801@qq.com]:

 

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:redhat

An optional company name []:

查看创建的服务端的证书

[root@localhost 2.0]# ll keys/

总用量 40

-rw-r--r--. 1 root root 3756 5月  28 18:19 01.pem

-rw-r--r--. 1 root root 1143 5月  28 18:10 ca.crt

-rw-------. 1 root root  916 5月  28 18:10 ca.key

-rw-r--r--. 1 root root   96 5月  28 18:19 index.txt

-rw-r--r--. 1 root root   21 5月  28 18:19 index.txt.attr

-rw-r--r--. 1 root root    0 5月  28 18:07 index.txt.old

-rw-r--r--. 1 root root    3 5月  28 18:19 serial

-rw-r--r--. 1 root root    3 5月  28 18:07 serial.old

-rw-r--r--. 1 root root 3756 5月  28 18:19 server.crt

-rw-r--r--. 1 root root  688 5月  28 18:19 server.csr

-rw-------. 1 root root  916 5月  28 18:19 server.key

2.4.6 生成客户端证书和密钥key文件

生成client证书和key文件。若建立多个客户证书,则重复如下步骤即可。只需修改Common Nameyan的名称

建立两份客户端证书,名称分别为yanjing,操作过程

[root@localhost 2.0]# ./build-key yan

-----

Country Name (2 letter code) [CN]:

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

Locality Name (eg, city) [Beijing]:

Organization Name (eg, company) [yan]:

Organizational Unit Name (eg, section) []:

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

Email Address [824412801@qq.com]:

 

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:redhat

An optional company name []:

查看创建的客户端证书

[root@localhost 2.0]# ll keys/

总用量 64

-rw-r--r--. 1 root root 3756 5月  28 18:19 01.pem

-rw-r--r--. 1 root root 3628 5月  28 18:26 02.pem

-rw-r--r--. 1 root root 1143 5月  28 18:10 ca.crt

-rw-------. 1 root root  916 5月  28 18:10 ca.key

-rw-r--r--. 1 root root  189 5月  28 18:26 index.txt

-rw-r--r--. 1 root root   21 5月  28 18:26 index.txt.attr

-rw-r--r--. 1 root root   21 5月  28 18:19 index.txt.attr.old

-rw-r--r--. 1 root root   96 5月  28 18:19 index.txt.old

-rw-r--r--. 1 root root    3 5月  28 18:26 serial

-rw-r--r--. 1 root root    3 5月  28 18:19 serial.old

-rw-r--r--. 1 root root 3756 5月  28 18:19 server.crt

-rw-r--r--. 1 root root  688 5月  28 18:19 server.csr

-rw-------. 1 root root  916 5月  28 18:19 server.key

-rw-r--r--. 1 root root 3628 5月  28 18:26 yan.crt

-rw-r--r--. 1 root root  684 5月  28 18:26 yan.csr

-rw-------. 1 root root  916 5月  28 18:26 yan.key

依次类推生成其他客户端证书/key,也可以使用build-key-pass命令与build-key,区别是build-key-pass加上了密码保护(客户端拨号时需要密码)

./build-key-pass jing

Generating a 1024 bit RSA private key

..++++++

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

writing new private key to 'jing.key'

Enter PEM pass phrase:

Verifying - Enter PEM pass phrase:

-----

You are about to be asked to enter information that will be incorporated

into your certificate request.

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

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [CN]:

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

Locality Name (eg, city) [Beijing]:

Organization Name (eg, company) [yan]:

Organizational Unit Name (eg, section) []:

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

Email Address [824412801@qq.com]:

2.4.7 生成generate diffie hellman parameters

生成传输进行密钥交换时用到的交换密钥协议文件

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

Filename

Needed By

Purpose

Secret

ca.crt

server+all clients

Root CA Certificate

NO

ca.key

key signing machine only

Root CA key

YES

dh{n}.pem

server only

Diffie Hellman parameters

NO

server.crt

server only

Server Certificate

NO

server.key

server only

Server Key

YES

client1.crt

client1 only

Client1 Certificate

NO

client1.key

client1 only

Client1 Key

YES

jing.crt

jing only

jing Certificate

NO

jing.key

jing only

jing Key

YES

yan.crt

yan only

yan Certificate

NO

yan.key

yan only

yan Key

YES

 

2.4.9 配置服务器端×××配置文件server.conf

1)拷贝keys及配置

把所有的keys和配置拷贝到/etc/open***目录下

操作命令:

mkdir -p /etc/open***  

cp -a /home/yan/tools/open***/open***-2.0.9/easy-rsa/2.0/keys/ /etc/open***/

cp -a /home/yan/tools/open***/open***-2.0.9/sample-config-files/*.conf /etc/open***/

cd /etc/open***/

cp server.conf server.conf.yan.20160528

egrep -v "^#|^$|;" server.conf (过滤配置文件)

egrep -v "^#|^$|;" server.conf >yan-***.conf  (追加到新文件)

[root@localhost open***]# cat yan-***.conf

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

2)企业级***配置文件

[root@localhost open***]# vim yan-***.conf

local 192.168.1.80

port 52115

proto tcp

dev tun

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

cert /etc/open***/keys/server.crt

key /etc/open***/keys/server.key

dh /etc/open***/keys/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

push "route 192.168.2.0 255.255.255.0"   #(内网IP)

client-to-client

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

2.4.10 启动服务端的***服务

1)取消服务器上防火墙iptablesopen***(默认1191,本例52115)的拦截

iptables -A INPUT -p tcp --dport 52115 -s 192.168.1.0/24 -j ACCEPT

2)开启内核转发功能:

sed -i 's#net.ipv4.ip_forward = 0#net.ipv4.ip_forward = 1#g' /etc/sysctl.conf

sysctl -p

3)启动×××

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

netstat -ntlpu | grep 52115

tcp        0      0 192.168.1.80:52115          0.0.0.0:*                   LISTEN      55345/open***

4)设置开机自启动

echo "#startup open*** by yan at 20160525" >> /etc/rc.local

echo "/usr/local/sbin/open*** --config /etc/open***/yan-***.conf &" >> /etc/rc.local

或者:

cp /home/yan/tools/open***/open***-2.0.9/sample-scripts/open***.init /etc/init.d/open***

chmod 755 /etc/init.d/open***

chkconfig open*** on

chkconfig --list open***

注:启动失败,查看日志文件

[root@localhost open***]# cat /var/log/open***.log

Fri Jun  3 09:43:32 2016 Open××× 2.0.9 x86_64-unknown-linux [SSL] [LZO] [EPOLL] built on Jun  3 2016

Fri Jun  3 09:43:32 2016 Cannot open /etc/open***/keys/dh1024.pem for DH parameters: error:02001002:system library:fopen:No such file or directory: error:2006D080:BIO routines:BIO_new_file:no such file

Fri Jun  3 09:43:32 2016 Exiting

解决办法:cp /home/yan/tools/open***/open***-2.0.9/sample-keys/dh1024.pem /etc/open***/keys/

 

3. 安装windows ×××客户端配置***连接

3.1

3.2配置客户端配置文件

egrep -v "^#|^;|^$" client.conf > c-yan.conf  (过滤配置文件并追加到一新文件中)

vim c-yan.conf

client

dev tun

proto tcp

remote 192.168.1.80 52115

resolv-retry infinite

nobind

persist-key

persist-tun

ca ca.crt

cert yan.crt

key yan.key

comp-lzo

verb 3

sz c-yan.conf keys/ca.crt keys/yan.*  (拷贝到windows客户端Open×××/config下)

windows上传的c-yan.conf改为c-yan.o***

3.3 测试×××连通性

windowsping 10.8.0.1ping通,ping内网其他地址不通,需要在iptable防火墙加一条规则

iptables -t nat -A POSTROUTING -s 10.8.0.0/255.255.255.0 -o eth1 -j SNAT --to-source 192.168.2.80

此时windows客户端ping 192.168.1.81是通的

 

4. open***负载均衡和高可用多种解决方案

方案一:在***客户端使用多个配置文件实现(由用户选择拨号)

基本说明:

生产场景中比较规范的做法是让作用的××× SERVER尽可能共享一套serverca证书或者连接同一个认证系统(即使是跨机房)。这样只需要一份客户端认证和文件和多份指定不同*** server的配置文件即可实现***负载均衡了

wKioL1e5NFPRtHKKAALnNXJiooI019.png-wh_50 

 

操作步骤:

首先要把一份服务端keys拷贝到所有××× SERVER的服务器上,然后在客户端本地有多个不同的客户端拨号配置文件(仅仅配置文件连接服务器IP有差别),由使用的用户选择拨号。这种方法也同样适合统一认证系统如(本地文件,数据库,RADIUSLDAPactive directory)认证。

总结结论:

1)该负载均衡方案操作简单,不引入多余服务,因此不会增加多余的单点故障,当用户连接的***不能使用时,用户就可以人工选择拨号其他的×××服务器。

2)如果使用者为公司内部工作人员,此方案值得推荐

3)从广义上讲这是在用户端实现的负载均衡

方案2:通过在客户端配置文件实现负载均衡(客户端文件)

方案说明:

通过一个open***客户端文件,例如yan.o***,在这个配置文件里面配置多个***服务端的地址,然后利用客户端的参数功能,在拨号时由客户端随机自动选择服务端,当正在连接的×××服务端宕机时,那么此时不需要人工干预,客户端的×××会自动判断,并自动切换到可用的×××服务器

 vim c-yan.o*** (写多个remote)

remote 192.168.1.80 52115

remote 192.168.1.81 52115

remote 192.168.1.8252115

..........

提示:通方案1.所有××× SERVER需要共享一套serverca证书。open***服务器一套keys的多份拷贝文件

操作步骤:

首先要把一份服务端keys拷贝到所有××× SERVER的服务器上,然后在客户端本地只有一个客户端拨号配置文件,由使用的用户拨号这个配置文件。拨号时会随机选择一个×××服务端,这种方法也同样适合同一认证系统

实践的客户端实战配置(仅一份配置即可):

client

dev tun

proto tcp

remote 192.168.1.80 52115

remote 192.168.1.81 52115

remote-random

resolve-retry 20

resolv-retry infinite

nobind

persist-key

persist-tun

ca ca.crt

cert yan.crt

key yan.key

comp-lzo

verb 3

ns-cert-type server

总结结论:

1)

2)如果使用者为公司内部工作人员,此方案值得推荐。如果使用者是外部人员,那么这个方案依然是可以的

3)本方案是比较标准的在×××用户端,由客户端配置参数实现的负载均衡的方案,是非常这的推荐的方案

4)和方案1对比,方案2的配置更简单,仅需一个配置文件多个remove参数,拨号时客户端会随机自动选择拨号

 

5. open***的统一身份验证解决方案

1)本地文件认证

2)数据库认证

方案一:利用1的脚本程序放弃本地文件去读数据库

方案二:用pam_mysql

3)ldap认证

方法一:open***-auth-ldap

方法二:利用第一个文件认证的思路,去LDAP查询,还可以和本地文件比较(python ldap

4)Radius认证

5)利用微软的活动目录认证

6)结合U盾等设备认证

5.1 open***安全解决方案(配置Open×××使用User/Pass方式验证登录)

1)编辑windows客户端的c-yan.o***

client

dev tun

proto tcp

remote 192.168.1.80 52115

resolv-retry infinite

nobind

persist-key

persist-tun

ca ca.crt   

#cert yan.crt

#key yan.key

comp-lzo

verb 3

auth-user-pass   (加密码提示)

此时登陆会有密码提示

2)在open***服务器上编辑配置文件yan-***.conf

[root@localhost open***]# cp yan-***.conf yan-***.conf.old

[root@localhost open***]# vim yan-***.conf  (在最后添加)

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

auth-user-pass-verify /etc/open***/checkpsw.sh via-env  

#不请求客户端的CA证书,使用User/Pass验证

client-cert-not-required

#使用客户端提供的UserName作为Common Name  

username-as-common-name

提示:/etc/open***/checkpsw.shshell脚本,用来接收***客户端的用户和密码,和本地文件进行对比验证,通过返回值确认是否可以连接***

3)下载checkpsw.sh

cd /etc/open***

chmod +x checkpsw.sh

ll checkpsw.sh

4)建立并管理×××账号密码文件

cat >/etc/open***/psw-file <<EOF

> yan redhat

> test redhat

> EOF

chmod 400 yan-***.conf

chown root.root psw-file

5)重启×××

pkill open***

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