Open0pn的技术核心是虚拟网卡,其次是SSL协议实现:
虚拟网卡是使用网络底层编程技术实现的一个驱动软件,安装后在主机上多出现一个网卡,能够像其它网卡同样进行配置。服务程序能够在应用层打开虚拟网卡,若是应用软件(如IE)向虚拟网卡发送数据,则服务程序能够读取到该数据,若是服务程序写合适的数据到虚拟网卡,应用软件也能够接收获得。虚拟网卡在不少的操做系统下都有相应的实现,这也是Open0pn可以跨平台一个很重要的理由。
在Open0pn中,若是用户访问一个远程的虚拟地址(属于虚拟网卡配用的地址系列,区别于真实地址),则操做系统会经过路由机制将数据包(TUN模式)或数据帧(TAP模式)发送到虚拟网卡上,服务程序接收该数据并进行相应的处理后,经过SOCKET从外网上发送出去,远程服务程序经过SOCKET从外网上接收数据,并进行相应的处理后,发送给虚拟网卡,则应用软件能够接收到,完成了一个单向传输的过程,反之亦然。html
优势:成本低,是一个廉价有效的构建私有网络的方式,用它能够替代昂贵的实体专线;灵活,比实体专线更灵活。例如,一个公司能够在0pn站点的数量调整,根据不断变化的需求。
缺点:搭建不容易,对技术要求很是高,须要对网络和安全问题有高水平的理解以及认真地规划和配置。因为在互联网上缺少质量服务(QoS)管理,可能会致使数据包丢失和其余性能问题。若公共网络条件发生问题,则私网的管理员不能控制。出于这个缘由,许多大公司通常购买使用可信0pn使用专用网络,以保证服务质量。linux
1.关闭selinuxc++
setenforce 0
2.安装编译环境算法
yum -y install gcc gcc-c++ make yum -y install pam-devel.x86_64
3.配置0pn时间同步服务器编程
yum -y install ntp ntpdate
ntpdate cn.pool.ntp.org
crontab -e 00 12 * * * /usr/sbin/ntpdate cn.pool.ntp.org #亲测因为时间问题致使链接失败
4.安装lzo压缩模块安全
#准备包 wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.10.tar.gz #解压安装 tar xf lzo-2.10.tar.gz cd lzo-2.10.tar.gz ./configure make && make install
5.安装open0pn 软件服务器
#安装ssl yum -y install openssl* #源码包 wget https://swupdate.open***.org/community/releases/open***-2.4.6.tar.gz #解压安装 tar xf open***-2.4.6.tar.gz cd open***-2.4.6 ./configure --prefix=/usr/local/open*** --with-lzo-headers=/usr/local/include --with-lzo-lib=/usr/local/lib make && make install
#把包里的脚本作软连接 ln -sv /home/open***-2.4.6/src/open***/open***/usr/bin/open*** open*** --version
7.配置CA证书网络
#下载easy-rsa wget http://build.open***.net/downloads/releases/easy-rsa-2.2.0_master.tar.gz tar xf easy-rsa-2.2.0_master.tar.gz cd easy-rsa-2.2.0_master ./configure make && make install #放置/etc/open0pn mkdir /etc/open*** cp -rf /home/easy-rsa /etc/open***/ #配置vars vi /etc/open***/easy-rsa/vars
cd /etc/open***/easy-rsa source vars //执行脚本生成证书时,须要设置一些环境变量 #生成根证书-CA证书,CA证书同时须要部署在服务器和客户端上 ./build-ca #一路回车 #查看ca [root@aliyun ~]# ll /etc/open***/keys/ca* -rw-r--r-- 1 root root 1643 Dec 12 11:05 /etc/open***/keys/ca.crt -rw------- 1 root root 1704 Dec 12 11:05 /etc/open***/keys/ca.key
[root@aliyun easy-rsa]# ll
build-ca #生成CA证书
build-dh #生成密码协议交换文件
build-key #生成免密码客户端密钥对
build-key-pass #生成带密码客户端密钥对
build-key-server #生成服务端密钥对
clean-all #初始化配置,清空全部keys
pkitool #各证书生成主要调用此命令执行
revoke-full #证书吊销
vars #预约义的证书基本信息并发
8.生成server证书和密钥key框架
./build-key-server jhrdc
[root@aliyun ~]# ll /etc/open***/easy-rsa/keys/jhrdc.* #查看证书 -rw-r--r-- 1 root root 5340 Dec 12 11:08 /etc/open***/easy-rsa/keys/jhrdc.crt #服务端证书 -rw-r--r-- 1 root root 1115 Dec 12 11:08 /etc/open***/easy-rsa/keys/jhrdc.csr #服务端证书请求文件 -rw------- 1 root root 1708 Dec 12 11:08 /etc/open***/easy-rsa/keys/jhrdc.key #服务端私钥
8.生成客户端证书和密钥,若要生成多个证书,重复步骤便可(一个证书仅限一人使用)
./build-key test#和以前server同样一路回车便可
9.生成须要密码验证的客户端密钥ett
./build-key-pass ett Generating a 2024 bit RSA private key .........................+++ ...........................................................+++ writing new private key to 'ett.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) [oldboy]: Organizational Unit Name (eg, section) [oldboy]: Common Name (eg, your name or your server's hostname) [ett]: Name [oldboy]: Email Address [mail@host.domain]: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:123456 An optional company name []:oldboy Using configuration from /etc/open***/easy-rsa/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:'BJ' localityName :PRINTABLE:'Beijing' organizationName :PRINTABLE:'oldboy' organizationalUnitName:PRINTABLE:'oldboy' commonName :PRINTABLE:'ett' name :PRINTABLE:'oldboy' emailAddress :IA5STRING:'mail@host.domain' Certificate is to be certified until Oct 23 08:45:44 2028 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 #查看证书 [root@aliyun ~]# ll /etc/open***/easy-rsa/keys/ett* -rw-r--r-- 1 root root 5217 Dec 12 11:12 /etc/open***/easy-rsa/keys/ett.crt -rw-r--r-- 1 root root 1110 Dec 12 11:12 /etc/open***/easy-rsa/keys/ett.csr -rw------- 1 root root 1834 Dec 12 11:12 /etc/open***/easy-rsa/keys/ett.key
10.生成密钥协议交换文件
./build-dh #视网络环境,等待便可
11.防止恶意链接(如DOS、UDP port flooding),生成一个“HMAC firewalls”
open*** --genkey --secret keys/ta.key [root@aliyun ~]# ll /etc/open***/easy-rsa/keys/ta* -rw------- 1 root root 636 Dec 12 11:20 /etc/open***/easy-rsa/keys/ta.key #复制证书 cp -ap keys /etc/open***/ 将服务端配置文件拷贝到/etc/open***/目录 [root@aliyun ~]# cp open***-2.4.6/sample/sample-config-files/{client,server}.conf /etc/open***/ [root@aliyun open***] ls client.conf easy-rsa keys server.conf
12.备份配置文件
cp client.conf client.conf.bak cp server.conf server.conf.bak #server配置 [root@aliyun ~]# grep -vE ";|#|^$" /etc/open***/server.conf port 52115 proto tcp #指定监听的协议,当并发访问多时,推荐tcp dev tun #*** server的模式采用路由模式。可选tap或tun ca /etc/open***/keys/ca.crt #写绝对路径 cert /etc/open***/keys/jhrdc.crt dh /etc/open***/keys/dh2048.pem server 10.8.0.0 255.255.255.0 ifconfig-pool-persist ipp.txt push "route 172.18.249.0 255.255.240.0" #加一条路由 client-to-client #容许拨号的多个client互相通讯 duplicate-cn #容许多个客户端使用一个帐号链接 keepalive 10 120 cipher AES-256-CBC persist-key # 当超时后,当从新启动后,保持上一次使用的私钥,而不从新读取私钥 persist-tun status open***-status.log log /var/log/open***.log verb 3 #
13.调试服务启动
#开启路由转发功能 sed -i 's#net.ipv4.ip_forward = 0#net.ipv4.ip_forward = 1#' /etc/sysctl.conf #开启服务 /usr/local/sbin/open*** --config /etc/open***/server.conf & #检查***服务端口: netstat -lntup | grep *** #加入开机启动 echo "#startup open***" >>/etc/rc.local echo "/usr/local/sbin/open*** --config /etc/open***/server.conf &" >>/etc/rc.local
14.window客户端配置
下载客户端 https://swupdate.open***.org/community/releases/open***-install-2.4.1-I601.exe
配置客户端证书
将ca.crt test.crt test.key 下载,
配置文件以下:
client dev tun proto tcp remote IP 52115 resolv-retry infinite nobind persist-key persist-tun ca D:\\Open***\\config\\test\\ca.crt #注意window的文件格式呵Linux不同 cert D:\\Open***\\config\\test\\test.crt key D:\\Open***\\config\\test\\test.key ns-cert-type server comp-lzo verb 3 log D:\\Open***\\config\\test\\open***.log
导入配置点击登陆,以下成功
参考https://idc.wanyunshuju.com/***/915.html