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