NO.A.0015——Open***2.4.9服务端/客户端部署/本地client配置/连接成功测试

一、***概述

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

  • Open***是一个用于创建虚拟专用网络加密通道的软件包,最早由James Yonan编写。Open***允许创建的***使用公开密钥、电子证书、或者用户名/密码来进行身份验证。
  • 它大量使用了OpenSSL加密库中的SSLv3/TLSv1协议函数库。
  • 目前Open***能在Solaris、Linux、OpenBSD、FreeBSD、NetBSD、Mac OS X与Microsoft Windows以及Android和iOS上运行,并包含了许多安全性的功能。它并不是一个基于Web的***软件,也不与IPsec及其他***软件包兼容。

在这里插入图片描述

1、open***可以解决什么问题

open***能让我们在环境隔离的场景中像在隔离环境的内网上远程登录集群中其他的服务器主机,比如我们在阿里云环境中创建基于VPC不同网络正式环境,测试环境,自动化工具平台环境等,我们就可以利用open***这样的基础服务打通测试环境和生产环境与自动化工具平台环境之间的通信,这样既隔离了测试与生产环境又能通过持续集成和持续部署完成业务的上下线。

2、open***实现原理:

Open***的技术核心是虚拟网卡,其次是SSL协议实现。
Open***中的虚拟网卡

虚拟网卡是使用网络底层编程技术实现的一个驱动软件。安装此类程序后主机上会增加一个非真实的网卡,并可以像其它网卡一样进行配置。服务程序可以在应用层打开虚拟网卡,如果应用软件(如网络浏览器)向虚拟网卡发送数据,则服务程序可以读取到该数据。如果服务程序写合适的数据到虚拟网卡,应用软件也可以接收得到。虚拟网卡在很多的操作系统中都有相应的实现,这也是Open***能够跨平台使用的一个重要原因。

在Open***中,如果用户访问一个远程的虚拟地址(属于虚拟网卡配用的地址系列,区别于真实地址),则操作系统会通过路由机制将数据包(TUN模式)或数据帧(TAP模式)发送到虚拟网卡上,服务程序接收该数据并进行相应的处理后,会通过SOCKET从外网上发送出去。这完成了一个单向传输的过程,反之亦然。当远程服务程序通过SOCKET从外网上接收到数据,并进行相应的处理后,又会发送回给虚拟网卡,则该应用软件就可以接收到。

3、如何保证open***负载高可用性

  • 通过客户端多配置文件实现负载:如果同一个办公室人员使用open***访问环境,我们可以通过使用多个open*** server来避免流量拥堵,此时我们可以在open*** server上将服务的配置文件拷贝到其他的服务器上,使用不同的IP地址启动另外一个open*** server,这样我们本地可以使用不同的配置文件来避免open***的访问慢流量拥堵的问题。

  • 通过使用remote-random实现负载:和多配置文件一样需要多个Open*** server端完成该方案,但是这个方案显得更智能,客户端不在需要手动的去选择使用哪个配置文件来连接哪个open***server,这些Open*** GUI自动的帮你实现,你只需要在客户端的配置文件中添加 remote-random和多个 remote配置段即可

4、加密和身份验证

  • 加密:Open***使用OpenSSL库来加密数据与控制信息。这意味着,它能够使用任何OpenSSL支持的算法。它提供了可选的数据包HMAC功能以提高连接的安全性。此外,OpenSSL的硬件加速也能提高它的性能。2.3.0以后版本引入PolarSSL。

  • 身份验证:Open***提供了多种身份验证方式,用以确认连接双方的身份,最常用的有以下三种:
    预享私钥
    第三方证书
    用户名/密码组合
  • 预享密钥最为简单,但同时它只能用于创建点对点的***;基于PKI的第三方证书提供了最完善的功能,但是需要额外维护一个PKI证书系统。Open***2.0后引入了用户名/口令组合的身份验证方式,它可以省略客户端证书,但是仍需要一份服务器证书用作加密。

二、open***部署流程及环境要求:
1、部署流程:

  • 安装lzo,用于压缩通讯数据加快传输速度, 编译安装的lzo,需要在编译安装open***时候指定lzo的位置
  • 安装open***和easy-rsa, esay-rsa是用来生成ca根证书和服务端客户端的证书以及通信key
  • 生成服务端证书
  • 生成客户端用户签署证书
  • 生成迪菲・赫尔曼密钥,会生成dh2048.pem文件
  • 生成防止ddos***key文件

2、环境要求:

  • 服务端:Centos7.6-1810
  • 客户端:Windows10
  • open***版本:Open*** 2.4.9 x86_64-redhat-linux-gnu
  • easy-rsa版本:easy-rsa-3.0.5

3、在GitHub上下载最新版本的easy-rsa:https://github.com/Open***/easy-rsa
在这里插入图片描述

三、open***部署配置:

1、部署open*** 和easy-rsa(该包用来制作ca证书)

// 1、安装epel仓库源
[root@localhost ~]# wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
[root@localhost ~]# rpm -Uvh epel-release-6-8.noarch.rpm             //安装epel 仓库源

//2、安装open***
[root@localhost ~]# yum install open***
Installed:
  open***.x86_64 0:2.4.9-1.el6                                                                   
Dependency Installed:
  pkcs11-helper.x86_64 0:1.11-3.el6                                                              
Complete!  

 //3、安装easy-rsa:将GitHub上下载的包上传到服务器:easy-rsa-3.0.5.zip
[root@localhost ~]# unzip easy-rsa-3.0.5.zip
[root@localhost ~]# mv easy-rsa-3.0.5 easy-rsa
[root@localhost ~]# ls
easy-rsa  easy-rsa-master.zip 

配置/etc/open***配置文件

//1、创建目录,并复制easy-rsa 目录到open***目录下
[root@localhost ~]#  mkdir -p /etc/open***/
[root@localhost ~]#  cp -a easy-rsa /etc/open***/

//2、配置,编辑vars文件,根据自己环境配置
[root@localhost ~]#  cd /etc/open***/easy-rsa/easyrsa3
[root@localhost easyrsa3]# cp vars.example vars
[root@localhost easyrsa3]# vim vars
set_var EASYRSA_REQ_COUNTRY     "CN"
set_var EASYRSA_REQ_PROVINCE    "Zhejiang"
set_var EASYRSA_REQ_CITY        "Hangzhou"
set_var EASYRSA_REQ_ORG         "Open***"
set_var EASYRSA_REQ_EMAIL       "[email protected]"
set_var EASYRSA_REQ_OU          "My Open***"

2、创建服务端证书及key:

//1、切换/etc/open***/easy-rsa/easyrsa3/目录并初始化
[root@localhost ~]# cd /etc/open***/easy-rsa/easyrsa3/
[root@localhost easyrsa3]# ./easyrsa init-pki
Note: using Easy-RSA configuration from: /etc/open***/easy-rsa/easyrsa3/vars
init-pki complete; you may now create a CA or requests.
Your newly created PKI dir is: /etc/open***/easy-rsa/easyrsa3/pki       //新创建的pki目录地址

//2、创建根证书
[root@localhost easyrsa3]# ./easyrsa build-ca
Enter New CA Key Passphrase:                                            //EPM密码:123456,
Re-Enter New CA Key Passphrase:                                         //后期为证书签名是会用到
Common Name (eg: your user, host, or server name) [Easy-RSA CA]:Open***-ca  //设置common name通用名:Open***-ca
Your new CA certificate file for publishing is at:
/etc/open***/easy-rsa/easyrsa3/pki/ca.crt                               //ca证书文件地址

//3、创建服务器端证书:
[root@localhost easyrsa3]# ./easyrsa gen-req server nopass
Common Name (eg: your user, host, or server name) [server]:Open***-server
Keypair and certificate request completed. Your files are:
req: /etc/open***/easy-rsa/easyrsa3/pki/reqs/server.req
key: /etc/open***/easy-rsa/easyrsa3/pki/private/server.key
//该过程中需要输入common name,随意但是不要跟之前的根证书的一样

2.1、签约服务端证书

[root@localhost easyrsa3]# ./easyrsa sign server server
Type the word 'yes' to continue, or any other input to abort.
     Confirm request details:     yes               //键入yes表示生成
Using configuration from /etc/open***/easy-rsa/easyrsa3/pki/easy-rsa-106473.G6htKP/tmp.PK2ZW1
Enter pass phrase for /etc/open***/easy-rsa/easyrsa3/pki/private/ca.key:    123456      //键入创建CA时的密码,如果忘记了,重头再来一次吧。
Certificate created at: /etc/open***/easy-rsa/easyrsa3/pki/issued/server.crt            //server.crt证书位置

3、创建Diffie-Hellman,

//创建Diffie-Hellman,确保key穿越不安全网络的命令
[root@localhost easyrsa3]# ./easyrsa gen-dh
Note: using Easy-RSA configuration from: /etc/open***/easy-rsa/easyrsa3/vars
Using SSL: openssl OpenSSL 1.0.2k-fips  26 Jan 2017
Generating DH parameters, 2048 bit long safe prime, generator 2
This is going to take a long time
...................+......+............................................++*++*
DH parameters of size 2048 created at /etc/open***/easy-rsa/easyrsa3/pki/dh.pem      //2048DH参数文件位置

4、创建客户端证书

//1、在root目录下新建client文件夹,cp之前解压的easy-ras目录到client文件夹
[root@localhost ~]#  mkdir client
[root@localhost ~]# cp -r /etc/open***/easy-rsa/ client/
[root@localhost ~]# cd client/easy-rsa/easyrsa3/

//2、初始化
[root@localhost easyrsa3]# ./easyrsa init-pki //需输入yes 确定
Type the word 'yes' to continue, or any other input to abort.
  Confirm removal: yes
init-pki complete; you may now create a CA or requests.
Your newly created PKI dir is: /root/client/easy-rsa/easyrsa3/pki           //pki文件地址

//3、创建客户端key及生成证书(记住生成是自己客户端登录输入的密码)
[root@localhost easyrsa3]# ./easyrsa gen-req open***-client //名字自己定义 
Enter PEM pass phrase:654321                                                //设置客户端登录时的密码
Verifying - Enter PEM pass phrase:654321                                    //此密码后期登录客户端时需用到
Common Name (eg: your user, host, or server name) [open***-client]:open***-client   //设置定义客户端的名字
Keypair and certificate request completed. Your files are:
req: /root/client/easy-rsa/easyrsa3/pki/reqs/open***-client.req
key: /root/client/easy-rsa/easyrsa3/pki/private/open***-client.key          //客户但key整数地址

//4、将得到的open***-client.req导入然后签约证书
[root@localhost easyrsa3]# cd /etc/open***/easy-rsa/easyrsa3/           //切换到/etc/open***/easy-rsa/easyrsa3/目录下
[root@localhost easyrsa3]# ./easyrsa import-req /root/client/easy-rsa/easyrsa3/pki/reqs/open***-client.req open***-client       //导入req
The request has been successfully imported with a short name of: open***-client
You may now use this name to perform signing operations on this request.
[root@localhost easyrsa3]# ./easyrsa sign client open***-client         //签约证书  //这里生成client所以必须为client,open***-client名字要与之前导入名字一致
Type the word 'yes' to continue, or any other input to abort.
  Confirm request details: yes      //yes同意执行
Using configuration from /etc/open***/easy-rsa/easyrsa3/pki/easy-rsa-106795.0lVxFk/tmp.ky2xRR
Enter pass phrase for /etc/open***/easy-rsa/easyrsa3/pki/private/ca.key:123456   //输入之前创建的CA的密码
Data Base Updated
Certificate created at: /etc/open***/easy-rsa/easyrsa3/pki/issued/open***-client.crt    //open***-client.crt文件地址

5、把服务器端必要文件放到etc/open***/ 目录下:ca的证书、服务端的证书、秘钥

[root@localhost ~]# cp /etc/open***/easy-rsa/easyrsa3/pki/ca.crt /etc/open***/
[root@localhost ~]# cp /etc/open***/easy-rsa/easyrsa3/pki/private/server.key /etc/open***/
[root@localhost ~]# cp /etc/open***/easy-rsa/easyrsa3/pki/issued/server.crt /etc/open***/
[root@localhost ~]# cp /etc/open***/easy-rsa/easyrsa3/pki/dh.pem /etc/open***/
[root@localhost ~]# ls /etc/open***/
ca.crt  dh.pem  server.crt  server.key

6、把客户端必要文件放到root/open***/ 目录下:客户端的证书、秘钥

[root@localhost ~]# cp /etc/open***/easy-rsa/easyrsa3/pki/ca.crt /root/client/
[root@localhost ~]# cp /etc/open***/easy-rsa/easyrsa3/pki/issued/open***-client.crt /root/client/
[root@localhost ~]# cp /root/client/easy-rsa/easyrsa3/pki/private/open***-client.key /root/client/
[root@localhost ~]# ls /root/client/
ca.crt    open***-client.crt  open***-client.key

7、配置服务端配置文件:


//1将server.conf配置文件cp到/etc/open***目录下
[root@localhost ~]# rpm -ql open*** |grep server.conf
/usr/share/doc/open***-2.4.9/sample/sample-config-files/server.conf
//当open***部署完成后,会给我们提供一个server配置的文件例子,
//在/usr/share/doc/open***-2.4.9/sample/sample-config-files/ 下有一个server.conf文件,
[root@localhost ~]# cp /usr/share/doc/open***-2.4.9/sample/sample-config-files/server.conf /etc/open***/

//2、编辑配置文件server.conf
[root@localhost ~]# vim /etc/open***/server.conf
[root@localhost ~]# grep '^[^#|;]' /etc/open***/server.conf         //修改后的版本如下
    local 0.0.0.0                       //监听地址
    port 1194                           //监听端口
    proto tcp                           //监听协议
    dev tun                             //采用路由隧道模式
    ca /etc/open***/ca.crt              //ca证书路径
    cert /etc/open***/server.crt        //服务器证书
    key /etc/open***/server.key         //服务器秘钥
    dh /etc/open***/dh.pem              //密钥交换协议文件
    server 10.10.0.0 255.255.255.0       //给客户端分配地址池,注意:不能和***服务器内网网段有相同
    ifconfig-pool-persist ipp.txt
    push "redirect-gateway def1 bypass-dhcp"        //给网关
    push "dhcp-option DNS 8.8.8.8"                  //dhcp分配dns
    client-to-client                                //客户端之间互相通信
    keepalive 10 120                    //存活时间,10秒ping一次,120 如未收到响应则视为断线
    # tls-auth ta.key 0                 //这个文件是设置保密秘钥的,暂时没有配置,客户端处应关闭
    comp-lzo                            //传输数据压缩
    max-clients 100                     //最多允许 100 客户端连接
    user open***                        //用户
    group open***                       //用户组
    persist-key
    persist-tun
    status /var/log/open***/open***-status.log          //连接状态文件地址
    log         /var/log/open***/open***.log            //日志文件地址
    verb 3

//3、配置文件创建完成后,创建open***.log文件地址及创建open***用户和组:
[root@localhost ~]# mkdir /var/log/open***
[root@localhost ~]# chown -R open***.open*** /var/log/open***/
[root@localhost ~]# chown -R open***.open*** /etc/open***/*

8、开启防火墙iptables 设置nat 规则和打开路由转发

[root@localhost ~]# iptables -t nat -A POSTROUTING -s 10.10.0.0/24 -j MASQUERADE
[root@localhost ~]# iptables -vnL -t nat
    0     0 MASQUERADE  all  --  *      *       10.10.0.0/24          0.0.0.0/0 
[root@localhost ~]# vim /etc/sysctl.conf                    //打开路由转发
net.ipv4.ip_forward = 1
[root@localhost ~]# sysctl -p
net.ipv4.ip_forward = 1

9、开启open*** 服务


[root@localhost ~]# systemctl start open***.service
[root@localhost ~]# systemctl enable open***.service
[root@localhost ~]# systemctl status open***.service
[root@localhost ~]# open*** /etc/open***/server.conf        //开启服务
[root@localhost sbin]# ss -tunlp |grep 1194
tcp     32       *:1194      *:* users:(("open***",pid=107194,fd=6))
//若是开启后没有打开1194端口,没说明开启服务失败,可能配置文件错误,也可能是权限不够,查询日志定位问题

三、在window下通过客户端连接open***

1、Windows下open***2.4.9客户端地址:http://www.npackd.org/p/open***64/2.4.9

2、配置客户端client配置文件
sample-config——>打开client.o***模板——>修改内容如下所示——>并复制知道config目录下——>END

// open***客户端client.o***配置说明:
client                           //定义是一个客户端
;dev tap                         //定义使用设备类型,与服务端一致
dev tun 
;dev-node(示例)                 //定义Windows下使用的网卡名称,linux不需要
proto tcp                       //定义使用的协议,与服务端一致
;proto udp
remote 192.168.1.59 1194        //指定服务端地址和端口,可以用多行指定多台服务器;实现负载均衡(从上往下尝试)
;remote my-server-2 1194        //open***服务器的外网ip地址和端口,ip或域名都可以
;remote-random                  //若上面配置了多台服务器,让客户端随机连接       
# Keep trying indefinitely to resolve the               //解析服务器域名
# host name of the Open*** server.  Very useful
# on machines which are not permanently connected
# to the internet such as laptops.
resolv-retry infinite       
# Most clients do not need to bind to                   //客户端不需要绑定端口
# a specific local port number.
nobind
;user nobody                    // nobody用户和组:是为了让Open***也nobody运行(安全)
;group nobody                   //注意:Windows不能设置       
# Try to preserve some state across restarts.
persist-key
persist-tun
;http-proxy-retry # retry on connection failures    //若客户端通过HTTP Proxy,在这里设置
;http-proxy [proxy server] [proxy port #]           //要使用Proxy,不能使用UDP为***的通讯协议
;mute-replay-warnings                               //无线网络有很多多余的头文件,设置忽略它

ca  "D:\\open***\\config\\ca.crt"                   //ca证书地址:重点,就是指定ca和客户端的证书
cert "D:\\open***\\config\\open***-client.crt"      //证书地址:注意,下面的两个号是连在一起的,之间没有空格
key  "D:\\open***\\config\\open***-client.key"      //秘钥地址:注意:因为配置文件\是脚本内容模式,使用\\代表单斜杠定义

;auth-user-pass                                     // 如果服务端打开了PAM认证模块,如mysql,LDAP数据库验证,客户端需要另其有效
# Verify server certificate by checking             //一些安全措施
# that the certicate has the nsCertType
# field set to “server”.  This is an
# important precaution to protect against
# a potential attack discussed here:
# http://open***.net/howto.html#mitm
# To use this feature, you will need to generate
# your server certificates with the nsCertType
# field set to “server”.  The build-key-server
# script in the easy-rsa folder will do this.
;ns-cert-type server
# then every client must also have the key.         //增强验证加密,如果你在服务器端生成了ta.key,那么这里就需要加上
;tls-auth ta.key 1                                  //重点:服务端配置文件没有开启ta.key验证,所以不用启用                      
# Select a cryptographic cipher.
# If the cipher option is used on the server
# then you must also specify it here.
;cipher x

comp-lzo        # 使用lzo压缩,与服务端一致                          
# Set log file verbosity.
verb 3                          
# Silence repeating messages
;mute 20
;auth-user-pass                 //采用用户名密码方式验证,若不用证书的话,可以考虑这种方式,可以结合LDAP或者mysql
route-method exe                //windows7上会报错,建议加上此行
route-delay 2                   //强行指定添加路由前的延时
auth-nocache                    //不存储验证缓存
ip-win32 dynamic 0 7200         //设置IP地址过期时间

3、把服务器端的证书文件ca.crt open***-client.crt open***-client.key复制到config 目录下
在这里插入图片描述

4、启动客户端并测试运行是否OK

启动客户端——>以root管理员权限运行——>输入当时设置Open***-client密码:654321——>连接成功(图标变为绿色)——>测试——>IE中输入ip测试IP地址是否为服务器所在地址

1、连接成功时显示日志:
Thu Nov 26 17:01:52 2020 Successful ARP Flush on interface [43] {F09886D2-EE14-4D64-A031-DD6F748763B8}
Thu Nov 26 17:01:52 2020 MANAGEMENT: >STATE:1606381312,ASSIGN_IP,,10.10.0.6,,,,

2、测试本地client端IP地址:在CMD窗口下
C:\Users\Administrator>ipconfig
以太网适配器 VMware Network Adapter VMnet1:
   IPv4 地址 . . . . . . . . . . . . : 10.10.0.6          //当时配置的是10.0.0网段的地址
   子网掩码  . . . . . . . . . . . . : 255.255.255.252

猜你喜欢

转载自blog.51cto.com/15005403/2556376