搭建open×××服务器

 

概述:

Open×××允许参与建立×××的单点使用共享**,电子证书,用户名/密码来进行身份验证,它大量使用了OpenSSL加密码库中的SSLv3/TLSv1协议函式库. 目前Open×××能在Solaris, Linux, OpenBSD, FreeBSD, NetBSD, Mac OS X与Windows 2000/XP/Vista上运行,并包含了许多安全性的功能, 它并不是一个基于Web的×××软件, 也不与IPsec及其它×××软件包兼容.Open×××所有的通信都能基于一个单一的IP端口, 默认且推荐使用UDP协议通讯, 同时TCP也被支持,Open×××连接能通过大多数的代理服务器,并且能够在NAT的环境中很好地工作, 服务端具有向客户端”推送”某些网络配置信息的功能,这些信息包括:IP地址, 路由设置等.Open×××提供了两种虚拟网络接口:通用Tun/Tap驱动,通过它们,可以建立三层IP隧道,或者虚拟二层以太网,后者可以传送任何类型的二层以太网络数据,

Open×××的官方端口为1194, Open×××2.0以后版本每个进程可以同时管理数个并发的隧道.Open×××使用通用网络协议(TCP UDP)的特点使它成为IPsec 等协议的理想替代,尤其是在ISPInternet service provider)过滤某些特定××× 协议的情况下。在选择协议时候,需要注意2个加密隧道之间的网络状况,如有高延迟或者丢包较多的情况下,请选择TCP协议作为底层协议,UDP协议由于

存在无连接和重传机制,导致要隧道上层的协议进行重传,效率非常低下。

Open××× 作用:

隧道就是要两台主机通信的时候就像在一个局域网内通信一样,但是为了安全可以用ssl 加密。

虚拟专用网×××:加密隧道

可以用ssl 或者ipsec 加密

1ssl 加密==> 软件open×××,支持各种操作系统,简单易用工作中常用

2psec 加密==> 软件freebsd 以后将成为内核默认支持加密的概念

3PTP/L2TP ==> 主要用于windows 点对点协义// 二层隧道协议

 

一、实验目标

1、Open××× 概述

2、搭建Open××× 服务器

二:实验环境

系统版本

服务端/客户端

主机名

  网卡

模式

IP地址

网关

Rhel 6.5

服务端

xuegod63

eth1

Vmnet4

192.168.2.63

192.168.2.64

Rhel 6.5

服务端

xuegod63

eth0

桥接

192.168.1.63

192.168.1.1

Rhel 6.5

客户端

xuegod64

eth0

Vmnet4

192.168.2.64

192.168.2.63

实验拓扑:

搭建open***服务器 

三:实验代码

1、配置服务端/客户端基础环境

1)配置服务端网络环境:添加一块网卡 

[[email protected] ~]# service network restart

[[email protected] ~]# ifconfig

eth0 Link encap:Ethernet HWaddr 00:0C:29:12:EC:1E

inet addr:192.168.1.63 Bcast:192.168.1.255 Mask:255.255.255.0

eth1 Link encap:Ethernet HWaddr 00:0C:29:12:EC:28

inet addr:192.168.2.63 Bcast:192.168.2.255 Mask:255.255.255.0

[[email protected] ~]# route -n

Destination Gateway Genmask Flags Metric Ref Use Iface

0.0.0.0 192.168.2.64 0.0.0.0 UG 0 0 0 eth1

2)开启路由转发功能:

[[email protected] Desktop]# vim /etc/sysctl.conf

net.ipv4.ip_forward = 1

[[email protected] Desktop]# sysctl -p

3测试xuegod63 和xuegod64 连通性:

[[email protected] ~]#service network restart

[[email protected] ~]# ping 192.168.2.64

PING 192.168.2.64 (192.168.2.64) 56(84) bytes of data.

64 bytes from 192.168.2.64: icmp_seq=1 ttl=64 time=27.3 ms

64 bytes from 192.168.2.64: icmp_seq=2 ttl=64 time=0.842 ms

2、搭建×××服务端服务器

1)安装依赖环境包

[[email protected] ~]# yum install -y openssl openssl-devel gcc

[[email protected] ~]# yum install -y openssl openssl-devel gcc

2)配置xuegod63 为open*** 服务器:

1安装lzo 包: lzo 软件包用于压缩隧道通信数据以加快传输速度

[[email protected] ~]# tar zxvf lzo-2.03.tar.gz

[[email protected] ~]# cd lzo-2.03

[[email protected] lzo-2.03]#./configure --prefix=/usr/ && make -j 4 && make install

2安装open*** 包:

[[email protected] ~]# tar zxvf open***-2.2.2.tar.gz

[[email protected] ~]# cd open***-2.2.2

[[email protected] open***-2.2.2]# ./configure --with-lzo-lib=/usr/ && make && make install

3建立CA 认证中心

[[email protected] ~]# cd /root/open***-2.2.2/easy-rsa/2.0/

[[email protected] 2.0]# vim vars #配置CA 认证中心相关的变量

改:

64 export KEY_COUNTRY="US"

65 export KEY_PROVINCE="CA"

66 export KEY_CITY="SanFrancisco"

67 export KEY_ORG="Fort-Funston" # Organization Name, 组织或公司名

68 export KEY_EMAIL="[email protected]"

为:

export KEY_COUNTRY="CN"

export KEY_PROVINCE="beijing"

export KEY_CITY="beijing"

export KEY_ORG="xuegod"

[[email protected] 2.0]# source vars # 加载变量

[[email protected] 2.0]# ./clean-all

[[email protected] 2.0]# ls keys/

index.txt serial

[[email protected] 2.0]# cat keys/serial #CA 认证签名的次数

01

[[email protected] 2.0]# cat keys/index.txt # 记录给哪个客户签过名。

 

4生成认证配置文件

[[email protected] 2.0]# cp openssl-1.0.0.cnf openssl.cnf #生成CA 认证配置文件

5)配置CA 认证中心:

[[email protected] 2.0]# ./build-ca # 使用build-ca ,不用使用openssl 来生成CA 相关文件

Generating a 1024 bit RSA private key

writing new private key to 'ca.key'

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

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

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

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

Organizational Unit Name (eg, section) [changeme]:IT

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

Name [changeme]:docker

Email Address [[email protected]]:[email protected]

[[email protected] 2.0]# ls keys/ #已经配置好CA,后期需要给*** server 和*** client 分别颁发证书

ca.crt #CA 根证书    ca.key #CA的私钥key

6)为*** server (服务端)颁发证书:

[[email protected] 2.0]# ./build-key-server server # 这个server 是××× 服务器的commonName,或主机名

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

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

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

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

Organizational Unit Name (eg, section) [changeme]:IT

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

Name [changeme]: #回车

Email Address [[email protected]]: #回车

A challenge password []: #回车

An optional company name []: #回车

Certificate is to be certified until Dec 24 14:25:37 2024 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

查看*** server 生成的相关文件:

[[email protected] 2.0]# ls keys/server.*

keys/server.crt keys/server.csr keys/server.key

server.key 服务器的私钥

server.csr 服务器的证书请求文件

server.crt 服务器的证书

查看***和已经使用CA 颁发过证书的文件:

[[email protected] 2.0]# cat keys/serial

02

[[email protected] 2.0]# cat keys/index.txt

V    250511111216Z    01    unknown

/C=CN/ST=beijing/L=beijing/O=xuegod/OU=IT/CN=server/name=changeme/emailA

[email protected]

7*** client(客户端) 颁发证书:

[[email protected] 2.0]# ./build-key yonghu

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

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

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

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

Organizational Unit Name (eg, section) [changeme]:IT

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

Name [changeme]:#回车

Email Address [[email protected]]:#回车

A challenge password []:#回车

An optional company name []:#回车

Using configuration from /root/open***-2.2.2/easy-rsa/2.0/openssl.cnf

Signature ok

Sign the certificate? [y/n]:y

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

查看证书的**:

[[email protected] 2.0]# ls keys/yonghu.*

keys/yonghu.crt keys/yonghu.csr keys/yonghu.key

查看***和已经使用CA 颁发过证书的文件:

[[email protected] 2.0]# cat keys/serial

03

[[email protected] 2.0]# cat keys/index.txt

V 250511111216Z 01 unknown

/C=CN/ST=beijing/L=beijing/O=xuegod/OU=IT/CN=server/name=changeme/emailA

[email protected]

V 250511111620Z 02 unknown

/C=CN/ST=beijing/L=beijing/O=xuegod/OU=IT/CN=yonghu/name=changeme/email

[email protected]

注:CA 认证确认身份,确认身份以后,客户端和服务端需要协商出来一对对称**,来加密数据。

建立Diffie Hellman parameters。作用, 通信时,来协商对称**。

[[email protected] 2.0]# ./build-dh #生成对称**

Generating DH parameters, 1024 bit long safe prime, generator 2

This is going to take a long time

注:产生1024 位长的DH 参数,这将花费很长的时间。

[[email protected] 2.0]# ls keys/dh1024.pem

keys/dh1024.pem

[[email protected] 2.0]# cat keys/dh1024.pem

-----BEGIN DH PARAMETERS-----

MIGHAoGBALcATDd5lbrztIM3RgcZMuRasgBB/mj6iAjshQVwUnapwPtbR7b45J1h

9QnqFxZTnqe+oseMSi63+Jjf6wOPdNxPRcurRvvI2mvC5lgN2l8VddGFeTiQSHXQ

LThk7mEje7dT4+HEQYoQRzWxDC2RIuEiJQkYoMdMys6JU5i/tmdzAgEC

-----END DH PARAMETERS-----

3、配置××× 服务端:

1生成配置文件:修改配置文件,搭建open***

[[email protected] 2.0]# cp /root/open***-2.2.2/sample-config-files/server.conf

/etc/server.conf

[[email protected] 2.0]# vim /etc/server.conf

修改的第一处

改:36 proto udp

为:36 proto tcp #即服务启动用TCP 1194 端口。

修改的第二处

指定open××× 服务器对应的证书等相关文件,将ca 那4 行内容改成如下所示的形式(记得写绝对路径):

改:

78 ca ca.crt

79 cert server.crt

80 key server.key # This file should be kept secret

87 dh dh1024.pem

为:

ca /root/open***-2.2.2/easy-rsa/2.0/keys/ca.crt

cert /root/open***-2.2.2/easy-rsa/2.0/keys/server.crt

key /root/open***-2.2.2/easy-rsa/2.0/keys/server.key

dh /root/open***-2.2.2/easy-rsa/2.0/keys/dh1024.pem

注:

ca /root/open***-2.2.2/easy-rsa/2.0/keys/ca.crt #ca 后面接的是CA 中心的根证书,它使用

的是buid-ca 生成的,用于验证客户端证书是否合法的。

cert /root/open***-2.2.2/easy-rsa/2.0/keys/server.crt # open*** 服务器的证书

key /root/open***-2.2.2/easy-rsa/2.0/keys/server.key # open*** 服务器的**

dh /root/open***-2.2.2/easy-rsa/2.0/keys/dh1024.pem ##在传输中,交换**时用到的迪菲赫

尔曼参数

修改的第三处

server 那行改为如下内容,这里做实验就直接使用原有的10.8.0.0 :

97 server 10.8.0.0 255.255.255.0 #每一个客户端连接到××× 服务器时,动态分配到的内网地址。(其

10.8.0.1 是保留××× 服务器自己用的。)

修改的第四处

#定义日志级别。级别越高,日志记录越多

改:295 verb 3

为:295 verb 4

修改的第五处

添加一条路由:在138 行,插入以下内容:

138 push "route 192.168.1.0 255.255.255.0"

配置文件说明:

25 ;local a.b.c.d       #open*** 服务端网卡的IP,也可以不写

32 port 1194         #服务端端口号,根据需要自行修改

36 proto utp         #默认通过utp 协议连接,根据需要自行修改

53 dev tun           #路由模式,linux 下为tun,windows 下必须设为tap。

61 ;dev-node MyTap  #Windows 需要tap-win32 适配器名称从网络连接面板,如果你有一个以上的。  XP SP2 或更高,你可能需要有选择地对阀门适配器在Windows 防火墙放   行或关闭windwos 防火墙,非windows 系统不需要开启此选项。

103 ifconfig-pool-persist ipp.txt       #实时分配虚拟IP 记录的保存文件名称,此处在

/root/open***-2.2.2/easy-rsa/2.0/ip.txt

188 ;push "redirect-gateway def1 bypass-dhcp"

#如果启用,该指令将配置所有的客户端重定向到其默认网关通过×××,导致所有IP 流量如网页浏览和DNS 查找通过×××(Open××× 服务端需要NAT 或TUN/TAP   接口的网络才能正常工作)。即让客户端发起的所有IP 请求都通过Open××× 服务器

197 ;push "dhcp-option DNS 208.67.220.220" #用于windows 特定网络设置中,可向客户端推送DNS 或WINS 服务器地址。

205 ;client-to-client   #如果开启则让客户端之间允许互相访问。

218 ;duplicate-cn #如果你没有产生为每个客户端个人证书/**对,每个都有自己独特的

“共名”,注释掉这行。即这条常用于测试用途,开启该条可实现限制一个证书在同一时刻只能有一个客户端接入。

227 keepalive 10 120 #keepalive 使用ping 命令来检测对方心跳,让双方都知道对方的状态。

 每隔10 秒ping 一次,假设在120 秒的时间内没有收到任何ping 的 反馈包则认为对方已down 机。

252 comp-lzo #开启后允许数据压缩,此选项需与客户端保持一致。

256 ;max-clients 100 #服务端允许连接的最大客户端数目(最大客户端并发数量)。

263 ;user nobody

264 ;group nobody #在非Windows 系统上可以注释掉这项。定义运行open*** 的用户

用于用户认证可以不采用用户认证

270 persist-key#通过keepalive 检测超时后,重新启动×××,不重新读取keys,保留第一次使用的keys

271 persist-tun#通过keepalive 检测超时后,重新启动×××,一直保持tun 或者tap 设备是linkup 的,否则网络连接会先linkdown 然后linkup

276 status open***-status.log      #定期把open*** 的一些状态信息写到文件中,以便自己写程序计费或者进行其他操作。

285 ;log open***.log

286 ;log-append open***.log    #开启此选项讲指定open*** 日志存放的文件名,路径在程序目录下,未开启时日志默认在rsyslog 里的message 里。2 个选项只能开启一个。

295 verb 3 #设置日志的冗长级别

300 ;mute 20 #如果开启此选项可设置重复日志记录限额

 

2)启动OPEN××× SERVER 端:

[[email protected] Desktop]# which open***

/usr/local/sbin/open***

[[email protected] Desktop]# /usr/local/sbin/open*** --config /etc/server.conf

#看到以下信息,××× 启动成功

。。。

Thu May 14 19:51:57 2015 IFCONFIG POOL: base=10.8.0.4 size=62

Thu May 14 19:51:57 2015 IFCONFIG POOL LIST

Thu May 14 19:51:57 2015 MULTI: TCP INIT maxclients=1024 maxevents=1028

Thu May 14 19:51:57 2015 Initialization Sequence Completed

注:如果看到最后显示: Initialization Sequence Completed 表示启动成功

[[email protected] Desktop]# netstat -antup | grep 1194

tcp 0 0 0.0.0.0:1194 0.0.0.0:* LISTEN

3376/open***

查看tun 网卡上的IP 地址:

[[email protected] ~]# ifconfig

tun0 Link encap:UNSPEC HWaddr

00-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

4、搭建×××客户端服务器

1)复制软件包:

[[email protected] ~]# scp lzo-2.03.tar.gz open***-2.2.2.tar.gz 192.168.2.64:/root/

2)安装lzo 库

[[email protected] ~]# tar -zxvf lzo-2.03.tar.gz

[[email protected] ~]# cd lzo-2.03

[[email protected] lzo-2.03]# ./configure --prefix=/usr/ && make && make install

3)安装open ***

[[email protected] ~]# tar zxvf open***-2.2.2.tar.gz

[[email protected] ~]# cd open***-2.2.2

[[email protected] open***-2.2.2]# ./configure --with-lzo-lib=/usr/ && make && make install

4)把之前签名的用户证书和**传给xuegod64 客户端:

[[email protected]64 ~]# mkdir /etc/open*** #创建一个存放证书的目录

[[email protected] keys]# cd /root/open***-2.2.2/easy-rsa/2.0/keys

[[email protected] keys]# scp ca.crt yonghu.crt yonghu.key 192.168.2.64:/etc/open***/

[email protected]'s password:

ca.crt 100% 1294 1.3KB/s 00:00

yonghu.crt 100% 3866 3.8KB/s 00:00

yonghu.key 100% 916 0.9KB/s 00:00

5、配置××× 客户端:

[[email protected]64 ~]# cp /root/open***-2.2.2/sample-config-files/client.conf

/etc/open***/

[[email protected] ~]# vim /etc/open***/client.conf #修改以一下内容

改:37 proto udp

为:37 proto tcp

改:42 remote my-server-1 1194

为:42 remote 192.168.2.63 1194

改:

88 ca ca.crt

89 cert client.crt

90 key client.key

为:

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

cert /etc/open***/yonghu.crt

key /etc/open***/yonghu.key

重要参数:

16 client #表示自己是客户端

117 comp-lzo # 这里压缩使用的库

120 verb 3 # 客户端的日志在/var/log/messages 文件中,如果连接不上,在这看日志息。

48 ;remote-random     #从远程列表中选择一个随机主机来进行负载均衡。

54 resolv-retry infinite   #继续尝试下去解决Open××× 服务器的主机名。非常有用的机器,这是没有永久连接到互联网,如笔记本电脑。这样无需人为重新启动,即可重新接入×××。

58 nobind              #默认是nobind 在本机不绑定任何端口监听incoming 数据,Client 无需此操作,除非一对一的××× 有必要。

74 ;http-proxy-retry     # retry on connection failures #如果你使用HTTP 代理连接××× Server,

Proxy 的IP 地址和端口写到下面

75 ;http-proxy [proxy server] [proxy port #]      #如果代理需要验证,请使用此选项,其中authfile

是一个2 行的文本文件,用户名和密码各占一行,auth-method 可以省略,详细信息查看Manual。

103 ns-cert-type server #Server 使用build-key-server 脚本什成的,在x509 v3 扩展中加入

ns-cert-type 选项,防止××× client 使用他们的keys + DNS hack 欺骗*** client 连接他们

假冒的××× Server。

6)启动客户端:--config /etc/open***/client.conf

[[email protected] ~]# /usr/local/sbin/open***  --config /etc/open***/client.conf

。。。

Thu May 14 20:22:39 2015 TUN/TAP device tun0 opened

Thu May 14 20:22:39 2015 TUN/TAP TX queue length set to 100

Thu May 14 20:22:39 2015 /sbin/ifconfig tun0 10.8.0.6 pointopoint 10.8.0.5 mtu 1500

Thu May 14 20:22:39 2015 /sbin/route add -net 10.8.0.1 netmask 255.255.255.255 gw

10.8.0.5

Thu May 14 20:22:39 2015 Initialization Sequence Completed

6、测试

1)打开另一个xuegod64 的客户端,测试:

[[email protected] ~]# ssh 192.168.2.64

[email protected]'s password:

2)查看:

[[email protected] ~]# ifconfig tun0

tun0 Link encap:UNSPEC HWaddr

00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00

inet addr:10.8.0.6 P-t-P:10.8.0.5 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)

3)测试:通信

[[email protected] ~]# ping 10.8.0.1

PING 10.8.0.1 (10.8.0.1) 56(84) bytes of data.

64 bytes from 10.8.0.1: icmp_seq=1 ttl=64 time=35.1 ms

64 bytes from 10.8.0.1: icmp_seq=2 ttl=64 time=1.90 ms

64 bytes from 10.8.0.1: icmp_seq=3 ttl=64 time=3.29 ms

64 bytes from 10.8.0.1: icmp_seq=4 ttl=64 time=6.96 ms

[[email protected] lzo-2.03]# ping 192.168.1.63

PING 192.168.1.63 (192.168.1.63) 56(84) bytes of data.

64 bytes from 192.168.1.63: icmp_seq=1 ttl=64 time=2.00 ms

 

实战

此时xuegod63 上,开启一台内部重要资料的ftp 服务器,只允许内网访问。分公司人员需要访问时,可以先登录×××,再访问:192.168.1.63 或10.8.0.1

1)xuegod63 配置成FTP 服务器:

[[email protected] keys]# rpm -ivh /mnt/Packages/vsftpd-2.2.2-6.el6_0.1.x86_64.rpm

[[email protected] keys]# service vsftpd restart

2)xuegod64 上使用内网,测试访问ftp 服务器:

[[email protected]4 ~]# rpm -ivh /mnt/Packages/vsftpd-2.2.2-6.el6_0.1.x86_64.rpm

[[email protected] ~]# lftp 192.168.1.63

lftp 192.168.1.63:~> ls

drwxr-xr-x 2 0 0 4096 Mar 04 2011 pub

lftp 192.168.1.63:/> exit

[[email protected] ~]# lftp 10.8.0.1

lftp 10.8.0.1:~> ls

drwxr-xr-x 2 0 0 4096 Mar 04 2011 pub

lftp 10.8.0.1:/> exit

3)xuegod63 开启iptables 规则,只允许10.8.0.0/24 网段访问20,21 端口。

[[email protected] ~]# iptables -t filter -A INPUT -s 10.8.8.0/24 -p tcp --dport 20 -j ACCEPT

[[email protected] ~]# iptables -t filter -A INPUT -s 10.8.8.0/24 -p tcp --dport 21 -j ACCEPT