open0pn的一次踩坑

open0pn的一些介紹

open0pn的原理

Open0pn的技術核心是虛擬網卡,其次是SSL協議實現:
  虛擬網卡是使用網絡底層編程技術實現的一個驅動軟件,安裝後在主機上多出現一個網卡,能夠像其它網卡同樣進行配置。服務程序能夠在應用層打開虛擬網卡,若是應用軟件(如IE)向虛擬網卡發送數據,則服務程序能夠讀取到該數據,若是服務程序寫合適的數據到虛擬網卡,應用軟件也能夠接收穫得。虛擬網卡在不少的操做系統下都有相應的實現,這也是Open0pn可以跨平臺一個很重要的理由。
  在Open0pn中,若是用戶訪問一個遠程的虛擬地址(屬於虛擬網卡配用的地址系列,區別於真實地址),則操做系統會經過路由機制將數據包(TUN模式)或數據幀(TAP模式)發送到虛擬網卡上,服務程序接收該數據並進行相應的處理後,經過SOCKET從外網上發送出去,遠程服務程序經過SOCKET從外網上接收數據,並進行相應的處理後,發送給虛擬網卡,則應用軟件能夠接收到,完成了一個單向傳輸的過程,反之亦然。html

open0pn的優缺點

  優勢:成本低,是一個廉價有效的構建私有網絡的方式,用它能夠替代昂貴的實體專線;靈活,比實體專線更靈活。例如,一個公司能夠在0pn站點的數量調整,根據不斷變化的需求。
  缺點:搭建不容易,對技術要求很是高,須要對網絡和安全問題有高水平的理解以及認真地規劃和配置。因爲在互聯網上缺少質量服務(QoS)管理,可能會致使數據包丟失和其餘性能問題。若公共網絡條件發生問題,則私網的管理員不能控制。出於這個緣由,許多大公司通常購買使用可信0pn使用專用網絡,以保證服務質量。linux

0pn的做用

  • 訪問外網
  • 提高網速(案例網遊加速)

0pn的分類

  • PPTP
      點對點隧道協議 (PPTP) 是由包括微軟和3Com等公司組成的PPTP論壇開發的一種點對點隧道協,基於撥號使用的PPP協議使用PAP或CHAP之類的加密算法,或者使用Microsoft的點對點加密算法MPPE。其經過跨越基於 TCP/IP 的數據網絡建立0pn實現了從遠程客戶端到專用企業服務器之間數據的安全傳輸。PPTP 支持經過公共網絡(例如 Internet)創建按需的、多協議的、虛擬專用網絡。PPTP 容許加密 IP 通信,而後在要跨越公司 IP 網絡或公共 IP 網絡(如 Internet)發送的 IP 頭中對其進行封裝。
  • L2TP
      第 2 層隧道協議 (L2TP) 是IETF基於L2F (Cisco的第二層轉發協議)開發的PPTP的後續版本。是一種工業標準 Internet 隧道協議,其能夠爲跨越面向數據包的媒體發送點到點協議 (PPP) 框架提供封裝。PPTP和L2TP都使用PPP協議對數據進行封裝,而後添加附加包頭用於數據在互聯網絡上的傳輸。PPTP只能在兩端點間創建單一隧道。 L2TP支持在兩端點間使用多隧道,用戶能夠針對不一樣的服務質量建立不一樣的隧道。L2TP能夠提供隧道驗證,而PPTP則不支持隧道驗證。可是當L2TP 或PPTP與IPSEC共同使用時,能夠由IPSEC提供隧道驗證,不須要在第2層協議上驗證隧道使用L2TP。 PPTP要求互聯網絡爲IP網絡。L2TP只要求隧道媒介提供面向數據包的點對點的鏈接,L2TP能夠在IP(使用UDP),楨中繼永久虛擬電路 (PVCs),X.25虛擬電路(VCs)或ATM VCs網絡上使用。
  • IPSec
      IPSec 的隧道是封裝、路由與解封裝的整個過程。隧道將原始數據包隱藏(或封裝)在新的數據包內部。該新的數據包可能會有新的尋址與路由信息,從而使其可以經過網絡傳輸。隧道與數據保密性結合使用時,在網絡上竊聽通信的人將沒法獲取原始數據包數據(以及原始的源和目標)。封裝的數據包到達目的地後,會刪除封裝,原始數據包頭用於將數據包路由到最終目的地。
  • SSL0pn
      SSL協議提供了數據私密性、端點驗證、信息完整性等特性。SSL協議由許多子協議組成,其中兩個主要的子協議是握手協議和記錄協議。握手協議容許服務器 和客戶端在應用協議傳輸第一個數據字節之前,彼此確認,協商一種加密算法和密碼鑰匙。在數據傳輸期間,記錄協議利用握手協議生成的密鑰加密和解密後來交換 的數據。

open0pn的部署

1.關閉selinuxc++

setenforce 0

2.安裝編譯環境算法

yum -y install gcc gcc-c++ make
yum -y install pam-devel.x86_64

3.配置0pn時間同步服務器編程

  • 安裝ntpdate
    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
  1. 檢查版本
    #把包裏的腳本作軟連接
    ln -sv /home/open***-2.4.6/src/open***/open***/usr/bin/open***
    open*** --version

    open0pn的一次踩坑
    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

    open0pn的一次踩坑

    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

    介紹一下easy-rsa的的工具功能

    [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

open0pn的一次踩坑

[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 #視網絡環境,等待便可

open0pn的一次踩坑
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
#

open0pn的一次踩坑

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
open0pn的一次踩坑
配置客戶端證書
將ca.crt test.crt test.key 下載,
open0pn的一次踩坑
配置文件以下:

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

open0pn的一次踩坑
導入配置點擊登陸,以下成功
open0pn的一次踩坑

參考https://idc.wanyunshuju.com/***/915.html

相關文章
相關標籤/搜索