1、Open***简介
node
Open*** 是一个基于 OpenSSL 库的应用层 *** 实现。和传统 *** 相比,它的优势是简单易用。linux
Open***容许参与创建***的单点使用共享金钥,电子证书,或者用户名/密码来进行身份验证。它大量使用了OpenSSL加密库中的SSLv3/TLSv1 协议函式库。Open***能在Solaris、Linux、OpenBSD、FreeBSD、NetBSD、Mac OS X与Windows 2000/XP/Vista上运行,并包含了许多安全性的功能。它并非一个基于Web的***软件,也不与IPsec及其余***软件包兼容。git
Open***2.0后引入了用户名/口令组合的身份验证方式,它能够省略客户端证书,可是仍有一份服务器证书须要被用做加密。 Open***全部的通讯都基于一个单一的IP端口, 默认且推荐使用UDP协议通信,同时TCP也被支持。Open***链接能经过大多数的代理服务器,而且可以在NAT的环境中很好地工做。服务端具备向客 户端“推送”某些网络配置信息的功能,这些信息包括:IP地址、路由设置等。Open***提供了两种虚拟网络接口:通用Tun/Tap驱动,经过它们, 能够创建三层IP隧道,或者虚拟二层以太网,后者能够传送任何类型的二层以太网络数据。传送的数据可经过LZO算法压缩。在选择协议时候,须要注意2个加密隧道之间的网络情况,若有高延迟或者丢包较多的状况下,请选择TCP协议做为底层协议,UDP协议因为存在无链接和重传机制,致使要隧道上层的协议进行重传,效率很是低下。github
2、Open***的安装算法
Open***服务器
vim
内外地址:10.0.0.41安全
外网地址:211.152.xx.xxbash
本地客户端
服务器
网段:192.168.0.0网络
本机IP:192.168.0.125
一、安装前的准备工做
请关闭防火墙和selinux,简单的安装方法就是使用yum安装,首先咱们应该先安装epel软件仓库。
service iptables stop setenforce 0 rpm -ivh http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
二、开启服务器端路由转发功能
sysctl -w net.ipv4.ip_forward=1
三、设置nat转发
注:保证***地址池可路由出外网
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
四、安装open***,他会自动解决依赖关系
我使用的open***版本是2.3.7,建议你们也使用这个版本,附件有
yum install open*** -y
五、安装好以后咱们查看安装了哪些文件,其中标记红色的部分的是咱们后面配置须要的
[root@*** ~]# rpm -ql open***
……
……
/usr/share/doc/open***-2.3.7/sample/sample-config-files
/usr/share/doc/open***-2.3.7/sample/sample-config-files/README
/usr/share/doc/open***-2.3.7/sample/sample-config-files/client.conf
/usr/share/doc/open***-2.3.7/sample/sample-config-files/firewall.sh
/usr/share/doc/open***-2.3.7/sample/sample-config-files/home.up
/usr/share/doc/open***-2.3.7/sample/sample-config-files/loopback-client
/usr/share/doc/open***-2.3.7/sample/sample-config-files/loopback-server
/usr/share/doc/open***-2.3.7/sample/sample-config-files/office.up
/usr/share/doc/open***-2.3.7/sample/sample-config-files/open***-shutdown.sh
/usr/share/doc/open***-2.3.7/sample/sample-config-files/open***-startup.sh
/usr/share/doc/open***-2.3.7/sample/sample-config-files/roadwarrior-client.conf
/usr/share/doc/open***-2.3.7/sample/sample-config-files/roadwarrior-server.conf
/usr/share/doc/open***-2.3.7/sample/sample-config-files/server.conf
下面两行是运行在预共享的静态密钥下的示例配置文件
/usr/share/doc/open***-2.3.7/sample/sample-config-files/static-home.conf
/usr/share/doc/open***-2.3.7/sample/sample-config-files/static-office.conf
下面两行是运行在SSL/TLS模式下的示例配置文件
/usr/share/doc/open***-2.3.7/sample/sample-config-files/tls-home.conf
/usr/share/doc/open***-2.3.7/sample/sample-config-files/tls-office.conf
/usr/share/doc/open***-2.3.7/sample/sample-config-files/xinetd-client-config
/usr/share/doc/open***-2.3.7/sample/sample-config-files/xinetd-server-config
/usr/share/doc/open***-2.3.7/sample/sample-keys
/usr/share/doc/open***-2.3.7/sample/sample-keys/.gitignore
/usr/share/doc/open***-2.3.7/sample/sample-keys/README
/usr/share/doc/open***-2.3.7/sample/sample-keys/ca.crt
/usr/share/doc/open***-2.3.7/sample/sample-keys/ca.key
/usr/share/doc/open***-2.3.7/sample/sample-keys/client-ec.crt
/usr/share/doc/open***-2.3.7/sample/sample-keys/client-ec.key
/usr/share/doc/open***-2.3.7/sample/sample-keys/client-pass.key
/usr/share/doc/open***-2.3.7/sample/sample-keys/client.crt
/usr/share/doc/open***-2.3.7/sample/sample-keys/client.key
/usr/share/doc/open***-2.3.7/sample/sample-keys/client.p12
/usr/share/doc/open***-2.3.7/sample/sample-keys/dh2048.pem
/usr/share/doc/open***-2.3.7/sample/sample-keys/gen-sample-keys.sh
/usr/share/doc/open***-2.3.7/sample/sample-keys/openssl.cnf
/usr/share/doc/open***-2.3.7/sample/sample-keys/server-ec.crt
/usr/share/doc/open***-2.3.7/sample/sample-keys/server-ec.key
/usr/share/doc/open***-2.3.7/sample/sample-keys/server.crt
/usr/share/doc/open***-2.3.7/sample/sample-keys/server.key
/usr/share/doc/open***-2.3.7/sample/sample-plugins
……
……
3、Open***的配置
首先把主要配置文件复制到/etc/open***
cp /usr/share/doc/open***-2.3.7/sample/sample-config-files/server.conf /etc/open***/
网上有不少是编译安装的***,也主要讲解了如何生成证书,我这里就不演示证书建立的过程了,由于咱们安装的open***里面自带了测试的证书(上面红色部分)等等,若是想自建证书的话请看本篇附录,为了简便,我这里运行open***的权限是root,若是要使用open***权限运行的话,务必修改一些文件的权限,好比证书等等。
vim /etc/open***/server.conf
port 1194 proto tcp dev tun ca /usr/share/doc/open***-2.3.7/sample/sample-keys/ca.crt cert /usr/share/doc/open***-2.3.7/sample/sample-keys/server.crt key /usr/share/doc/open***-2.3.7/sample/sample-keys/server.key dh /usr/share/doc/open***-2.3.7/sample/sample-keys/dh2048.pem server 10.8.0.0 255.255.255.0 ifconfig-pool-persist ipp.txt push "route 10.0.0.0 255.255.255.0" push "redirect-gateway def1 bypass-dhcp" push "dhcp-option DNS 114.114.114.114" topology subnet client-to-client keepalive 10 120 comp-lzo persist-key persist-tun status /var/log/open***/open***-status.log log-append /var/log/open***/open***.log verb 3
注:可按照默认模板配置,本例为自定义配置文件,";"还有"#"开头的是注释
--------------------------
# 设置监听IP,默认是监听全部IP
;local a.b.c.d
# 设置监听端口,必需要对应的在防火墙里面打开
port 1194
# 设置用TCP仍是UDP协议?(用UDP会比较快些)
;proto tcp
proto tcp
# 设置建立tun的路由IP通道,仍是建立tap的以太网通道路,因为IP容易控制,因此推荐使用tun;但若是IPX等必须使用第二层才能经过的通信,则能够用tap方式,tap也就是以太网桥接
;dev tap
dev tun
# Windows服务端须要给网卡一个名称,linux不须要
;dev-node MyTap
# 这里是重点,必须指定SSL/TLS root certificate (ca),certificate(cert), and private key (key),ca文件是服务端和客户端都必须使用的,但不须要ca.key,服务端和客户端指定各自的.crt和.key,请注意路径,可使用以配置文件开始为根的相对路径,也可使用绝对路径,请当心存放.key密钥文件
ca /usr/share/doc/open***-2.3.7/sample/sample-keys/ca.crt
cert /usr/share/doc/open***-2.3.7/sample/sample-keys/server.crt
key /usr/share/doc/open***-2.3.7/sample/sample-keys/server.key
# 指定Diffie hellman parameters.
dh /usr/share/doc/open***-2.3.7/sample/sample-keys/dh2048.pem
# 配置服务器模式和***使用的网段,Open***会自动提供基于该网段的DHCP服务,但不能和任何一方的局域网段重复,***服务器将会把10.8.0.1留给本身,其他的分配给***客户端,每个客户端都会从10.8.0.1这个IP到达Open***服务端,若是使用dev tap模式,则须要注释掉该指令。
server 10.8.0.0 255.255.255.0
# 维持一个客户端和virtual IP的对应表,以方便客户端从新链接能够得到一样的IP
ifconfig-pool-persist ipp.txt
# 配置为以太网桥模式(dev tap),但须要使用系统的桥接功能,这里不须要使用
;server-bridge 10.8.0.4 255.255.255.0 10.8.0.50 10.8.0.100
# 为客户端建立对应的路由,以另其通达公司网内部服务器,但记住,公司网内部服务器也须要有可用路由返回到客户端,这里主要填写open***所在局域网的网段,个人open***所在的局域网是10.0.0.0,若是你的open***所在的局域网是其余的网段,下面请填写其余网段,能够填写多个网段。
;push "route 192.168.20.0 255.255.255.0"
push "route 10.0.0.0 255.255.255.0"
# 若客户端但愿全部的流量都经过***传输,则可使用该语句,其会自动改变客户端的网关为***服务器,推荐关闭,一旦设置,请当心服务端的DHCP设置问题,若是须要抓取因此链接***客户端的流量信息,须要开启,这就是网络上面所说的***。
;push "redirect-gateway def1 bypass-dhcp" 全部数据都经过***
# 用Open***的DHCP功能为客户端提供指定的DNS、WINS等
push "dhcp-option DNS 114.114.114.114"
;push "dhcp-option WINS 10.8.0.1"
# 默认客户端之间是不能直接通信的,除非把下面的语句注释掉
client-to-client
# 若是您但愿有相同Common Name的客户端均可以登录,也能够注释下面的语句,推荐每一个客户端都使用不用的Common Name,开启的话,一个证书能够多个客户端链接
;duplicate-cn
# 设置服务端检测的间隔和超时时间
keepalive 10 120
# 使用lzo压缩的通信,服务端和客户端都必须配置
comp-lzo
# 设置最大用户数
;max-clients 100
# 让Open***以nobody用户和组来运行(安全)
;user nobody
;group nobody
#持续选项会尽可能避免访问某些资源的从新启动可能不能够由于特权的降级。
persist-key
persist-tun
# 输出短日志,每分钟刷新一次,以显示当前的客户端
status /var/log/open***/open***-status.log
# 缺省日志会记录在系统日志中,但也能够导向到其余地方建议调试的使用先不要设置,调试完成后再定义,只能使用其中的一个,log会每次启动前先清楚日志,log-append会对数据追加
;log /var/log/open***/open***.log
log-append /var/log/open***/open***.log
# 设置日志的级别
verb 3
--------------------------
其中咱们只须要修改一下红色的部分,不少其余不经常使用的参数并无列举出来,若是须要能够查阅配置文件。
4、Open***的启动
service open*** start
[root@*** ~]# netstat -tlnp
Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2381/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1425/master tcp 0 0 0.0.0.0:1194 0.0.0.0:* LISTEN 12947/open***
5、客户端的安装
1.下载客户端,并默认安装:
如何你不能够下载的话,能够经过个人附件下载,在最下面
http://***tech.googlecode.com/files/open***-2.1.1-gui-1.0.3-install-cn-64bit.zip
2.将服务端内ca.crt、client.crt、client.key、client.conf复制到客户端C:\Program Files (x86)\Open***\config下。
3.把client.conf更名为client.o***
client dev tun proto tcp remote 211.152.x.x 1194 resolv-retry infinite nobind persist-key persist-tun ca ca.crt cert client.crt key client.key comp-lzo verb 3
# 定义是一个客户端
client
# 定义使用路由IP模式,与服务端一致
;dev tap
dev tun
# 定义Windows下使用的网卡名称,linux不须要
;dev-node MyTap
# 定义使用的协议,与服务端一致
;proto tcp
proto tcp
# 指定服务端地址和端口,能够用多行指定多台服务器实现负载均衡高可用(从上往下尝试)
remote 211.152.x.x 1194
;remote my-server-2 1194
# 若上面配置了多台服务器,让客户端随机链接,以便实现负载均衡
;remote-random
# 解析服务器域名
resolv-retry infinite
# 客户端不须要绑定端口
nobind
# Try to preserve some state across restarts.
persist-key
persist-tun
# 重点,就是指定ca和客户端的证书
ca ca.crt
cert client.crt
key client.key
# 使用lzo压缩,与服务端一致
comp-lzo
# Set log file verbosity.
verb 3
-----------------------
client里面能够只填写上面红色的参数,其余的参数能够所有删掉。
五、链接
在右下角的open***图标上右击,选择“Connect”,若能正常分配IP,则链接成功。
我获取的IP是10.8.0.6
先去看一下咱们的路由信息
由于咱们使用了push "route 10.0.0.0 255.255.255.0" ,因此open***给咱们推送了一条路由信息,咱们在查看一下open***上面的IP信息
那咱们去ping一下服务器的内外IP,还有服务器内外外的另外一台设备,看看是否能够连入机房内网。
事实证实咱们的配置是成功的!
目前咱们使用的是证书登陆,若是须要修改为帐号密码登陆,请查看本博客下一篇文章,谢谢!
6、客户端IP地址的使用
在--topology mode选项中,mode有三种取值,即net30、subnet和p2p。
当运行在--dev tun模式下时,能够经过--topology mode选项来配置虚拟地址的拓扑结构。而对于--dev tap而言,该选项没有任何意义,由于在--dev tap模式下,老是使用子网拓扑若是在服务器端设置了--topology mode选项,那么--server和--server-bridge选项将会很好地自动地把拓扑模式推送到客户端。该选项也能够被手动的推送到客户端,相似于--dev选项,另外,还要求服务器端和客户端必须支持该选项。
一、net30
Open***默认的子网掩码是/30,也就是255.255.225.252。在这样的状况下,每组网络四个地址,只有两个地址可使用,一个给服务端,一个给客户端,另一个是网络地址,一个是广播地址,这样地址是很浪费的,这是Open*** 2.0的默认模式。
在Open***的2.0版本中,Open***能经过虚拟一个TUN虚拟接口处理多个客户端,要处理这种技术,能够把服务器上看到的PtP链接看做是一个操做系统和Open***之间的链接,而在Open***内部还须要为每个客户端建立另外一个PtP。如何全部的O/S在TUN接口上真正的支持PtP链接,那么这将会是的Open***服务器仅使用一个IP地址,而且一个客户端也使用一个IP地址。
在OS系统和Open***之间首先要有一个10.8.0.1<->10.8.0.2的PtP链接。
因而Open***为每个链接的客户端指定一个/30的子网,第一个可使用的/30的子网是:
10.8.0.4:网络地址;
10.8.0.5:在Open***中的“虚拟”IP地址;
10.8.0.6:指定给客户端的IP地址;
10.8.0.7:广播地址。
而后将路由推到客户端,这样便使全部IP地址为10.8.0.5的流量都必须经过“网关”10.8.0.5才能够出去或者进入。
因为10.8.0.5仅是Open***内部的一个虚拟IP地址,它被用做末端路由,对应这个地址,Open***不会接受ping,而10.8.0.6对于服务器的操做系统来讲倒是一个真正的IP地址,所以它能够接受ping,咱们让客户端链接查看一下。
以此类推,第二个客户端链接分配的IP地址对就是10.8.0.9<->10.8.0.10,从这个IP分配来看,对IP的使用形成的浪费。可是对于Open***服务器端仅使用一个配置来为全部类型的客户端分配地址来讲这是最好的一种方式。
二、subnet
subnet经过配置TUN接口的本地IP地址和子网掩码来使用一个子网,而不是点对点的拓扑结构,相似于使用--dev tap和以太网桥模式的拓扑结构。这种模式为每一个客户端分配单个IP地址。
三、p2p
p2p模式使用点对点拓扑,仅适用于Windows系统下,如今已经再也不同意使用。
附录
下载密钥制做工具easy_rsa 2:
wget https://github.com/Open***/easy-rsa/archive/release/2.x.zip
解压easy_rsa并拷贝到/etc/open***:
unzip 2.x.zip
mv easy-rsa-release-2.x/ /etc/open***/
编辑easy-rsa的vars文件,设定相关变量信息:
cd /etc/open***/easy-rsa-release-2.x/easy-rsa/2.0
vim vars
export KEY_COUNTRY="CN"
export KEY_PROVINCE="Shanghai"
export KEY_CITY="Shanghai"
export KEY_ORG="Comratings"
export KEY_EMAIL="ADMIN@Comratings.COM"
export KEY_OU="MyOpen***"
编辑完以后,保存退出。
将刚才编辑的vars文件,执行以下命令:
source vars
./clean-all
./build-ca
建立服务器的证书和密钥:
./build-key-server Open***_Server
[root@cloud 2.0]# ./build-key-server Open***_Server
Generating a 2048 bit RSA private key
.................................+++
............+++
writing new private key to 'Open***_Server.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) [BEIJING]:
Locality Name (eg, city) [BEIJING]:
Organization Name (eg, company) [XIAOCUI]:
Organizational Unit Name (eg, section) [MyOpen***]:
Common Name (eg, your name or your server's hostname) [Open***_Server]:
Name [EasyRSA]:
Email Address [ADMIN@ XIAOCUI.COM]:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /etc/open***/easy-rsa-release-2.x/easy-rsa/2.0/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'CN'
stateOrProvinceName :PRINTABLE:'BEIJING'
localityName :PRINTABLE:'BEIJING'
organizationName :PRINTABLE:' XIAOCUI '
organizationalUnitName:PRINTABLE:'MyOpen***'
commonName :T61STRING:'Open***_Server'
name :PRINTABLE:'EasyRSA'
emailAddress :IA5STRING:'ADMIN@ XIAOCUI.COM'
Certificate is to be certified until May 2 07:49:13 2025 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
建立客户端的证书和密钥:
./build-key client-user-test1
[root@cloud 2.0]# ./build-key client-user-test1
Generating a 2048 bit RSA private key
....................+++
...............................................................................+++
writing new private key to 'client-user-cuiyuanrong.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) [BEIJING]:
Locality Name (eg, city) [BEIJING]:
Organization Name (eg, company) [XIAOCUI]:
Organizational Unit Name (eg, section) [MyOpen***]:
Common Name (eg, your name or your server's hostname) [client-user-test1]:
Name [EasyRSA]:
Email Address [ADMIN@XIAOCUI.COM]:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /etc/open***/easy-rsa-release-2.x/easy-rsa/2.0/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'CN'
stateOrProvinceName :PRINTABLE:'BEIJING'
localityName :PRINTABLE:'BEIJING'
organizationName :PRINTABLE:'XIAOCUI'
organizationalUnitName:PRINTABLE:'MyOpen***'
commonName :PRINTABLE:'client-user-test1'
name :PRINTABLE:'EasyRSA'
emailAddress :IA5STRING:'ADMIN@XIAOCUI.COM'
Certificate is to be certified until May 2 07:53:17 2025 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
建立Diffie Hellman 参数:
./build-dh