本次ubuntu的版本
root@node2:~# lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 12.04.5 LTS Release: 12.04 Codename: precise
ip地址
root@node2:~# ip a 1: lo:mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo 2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:16:3e:00:3f:b0 brd ff:ff:ff:ff:ff:ff inet 10.168.198.51/21 brd 10.168.199.255 scope global eth0 3: eth1: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:16:3e:00:48:5d brd ff:ff:ff:ff:ff:ff inet 121.41.48.13/22 brd 121.41.51.255 scope global eth1
一、open***原理
open***通过使用公开密钥(非对称密钥,加密解密使用不同的key,一个称为Publice key,另外一个是Private key)对数据进行加密的。这种方式称为TLS加密
open***使用TLS加密的工作过程是,首先××× Sevrver端和××× Client端要有相同的CA证书,双方通过交换证书验证双方的合法性,用于决定是否建立×××连接。
然后使用对方的CA证书,把自己目前使用的数据加密方法加密后发送给对方,由于使用的是对方CA证书加密,所以只有对方CA证书对应的Private key才能解密该数据,这样就保证了此密钥的安全性,并且此密钥是定期改变的,对于窃听者来说,可能还没有破解出此密钥,×××通信双方可能就已经更换密钥了。
二、安装open***
1、直接使用apt-get安装
sudo apt-get -y install open*** libssl-dev openssl
2、查看版本
root@node2:~# open*** --version Open××× 2.2.1 x86_64-linux-gnu [SSL] [LZO2] [EPOLL] [PKCS11] [eurephia] [MH] [PF_INET6] [IPv6 payload 20110424-2 (2.2RC2)] built on Dec 1 2014 Originally developed by James Yonan Copyright (C) 2002-2010 Open××× Technologies, Inc.
3、准备工作
root@node2:~# cp -a /usr/share/doc/open***/examples/easy-rsa/2.0/ /etc/open***/easy-rsa root@node2:~# cp /usr/share/doc/open***/examples/sample-config-files/server.conf.gz /etc/open***/ root@node2:~# cp /usr/share/doc/open***/examples/sample-config-files/client.conf /etc/open***/ root@node2:~# cd /etc/open*** && gzip -d server.conf.gz root@node2:/etc/open***# ls easy-rsa server.conf update-resolv-conf
三、制作相关证书(使用root权限)
1、编辑vars文件
root@node2:/etc/open***# cd easy-rsa root@node2:/etc/open***/easy-rsa# vim vars export KEY_COUNTRY="CN" export KEY_PROVINCE="NJ" export KEY_CITY="NanJing" export KEY_ORG="health" export KEY_EMAIL="[email protected]" export KEY_NAME='***-server' export KEY_OU='health' root@node2:/etc/open***/easy-rsa# source vars NOTE: If you run ./clean-all, I will be doing a rm -rf on /etc/open***/easy-rsa/keys root@node2:/etc/open***/easy-rsa# ./clean-all
2、制作CA证书
root@node2:/etc/open***/easy-rsa# ./build-ca # 一路回车即可 root@node2:/etc/open***/easy-rsa# ls keys ca.crt ca.key index.txt serial
3、制作server端证书
root@node2:/etc/open***/easy-rsa# ./build-key-server ***-server # 证书名,vars中的KEY_NAME,同样一路回车 root@node2:/etc/open***/easy-rsa# ls /keys 01.pem ca.crt ca.key index.txt index.txt.attr index.txt.old serial serial.old ***-server.crt ***-server.csr ***-server.key
4、生成加密交换时的Diffie-Hellman文件
root@node2:/etc/open***/easy-rsa# ./build-dh root@node2:/etc/open***/easy-rsa# ls /keys 01.pem ca.crt ca.key dh1024.pem index.txt index.txt.attr index.txt.old serial serial.old ***-server.crt ***-server.csr ***-server.key
5、制作client端证书
root@node2:/etc/open***/easy-rsa# ./build-key ***-client # 证书名随意,一路回车 root@node2:/etc/open***/easy-rsa# ls /keys 01.pem ca.crt ca.key dh1024.pem ***-client.crt ***-client.csr ***-client.key index.txt index.txt.attr index.txt.old serial serial.old ***-server.crt ***-server.csr ***-server.key
6、编辑server端配置文件
root@node2:/etc/open***/easy-rsa# cd .. root@node2:/etc/open***# egrep '^[^(#|;)].*' server.conf port 1194 proto tcp # 修改成tcp协议 dev tun ca /etc/open***/easy-rsa/keys/ca.crt # 修改成ca证书的路径 cert /etc/open***/easy-rsa/keys/***-server.crt # ×××路径 key /etc/open***/easy-rsa/keys/***-server.key # 修改密钥路径 dh /etc/open***/easy-rsa/keys/dh1024.pem # 修改Diffie-Hellman文件路径 server 10.8.0.0 255.255.255.0 ifconfig-pool-persist ipp.txt push "route 10.168.198.0 255.255.255.0" client-config-dir ccd keepalive 10 120 comp-lzo persist-key persist-tun status open***-status.log verb 3
四、启动服务
root@node2:/etc/open***# service open*** start root@node2:/etc/open***# ss -tnl | grep 1194 # 端口已经开启 LISTEN 0 1 *:1194 *:*
五、配置windows客户端
1、直接安装与server端相同的版本
2、将ca证书,客户端证书,客户端密钥,客户端配置文件放到windows的配置文件路径下
3、编辑client配置文件
4、启动
5、显示已连接
六、配置linux客户端
以centos 6.5 为例
1、直接yum安装open***
[root@test ~]# yum install -y open***
2、新建配置文件目录
[root@test ~]# mkdir /etc/open***/client && cd /etc/open***/client
3、将ca证书,客户端证书,客户端密钥,客户端配置文件放到配置文件目录
[root@test client]# ls ca.crt client.o*** ***-client.crt ***-client.key
4、配置文件与win的相同
[root@test client]# egrep '^[^(#|;)].*' client.o*** client dev tun proto tcp remote 121.41.48.133 1194 resolv-retry infinite nobind persist-key persist-tun ca /etc/open***/client/ca.crt cert /etc/open***/client/***-client.crt key /etc/open***/client/***-client.key ns-cert-type server comp-lzo verb 3
5、后台启动
[root@test client]# /usr/sbin/open*** --config /etc/open***/client/client.o*** > /var/log/open***.log &
6、查看ip地址,多了一个tun0
[root@haproxy client]# [root@haproxy client]# ip a 1: lo:mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 52:54:00:c3:69:30 brd ff:ff:ff:ff:ff:ff inet 192.168.3.201/24 brd 192.168.3.255 scope global eth0 inet6 fe80::5054:ff:fec3:6930/64 scope link valid_lft forever preferred_lft forever 4: tun0: mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 100 link/[65534] inet 10.8.0.6 peer 10.8.0.5/32 scope global tun0
7、测试
客户端尝试ping服务端
[root@test client]# ping 10.8.0.1 -c 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=10.4 ms [root@test client]# ping 10.168.198.51 -c 1 PING 10.168.198.51 (10.168.198.51) 56(84) bytes of data. 64 bytes from 10.168.198.51: icmp_seq=1 ttl=64 time=10.4 ms
服务器端尝试ping客户端
root@node2:/etc/open***# ping 10.8.0.6 -c 1 PING 10.8.0.6 (10.8.0.6) 56(84) bytes of data. 64 bytes from 10.8.0.6: icmp_req=1 ttl=64 time=9.93 ms
测试成功!