溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

open0pn的一次踩坑

發(fā)布時間:2020-06-24 10:32:39 來源:網(wǎng)絡 閱讀:245 作者:緣檸 欄目:系統(tǒng)運維

open0pn的一些介紹

open0pn的原理

Open0pn的技術核心是虛擬網(wǎng)卡,其次是SSL協(xié)議實現(xiàn):
  虛擬網(wǎng)卡是使用網(wǎng)絡底層編程技術實現(xiàn)的一個驅動軟件,安裝后在主機上多出現(xiàn)一個網(wǎng)卡,可以像其它網(wǎng)卡一樣進行配置。服務程序可以在應用層打開虛擬網(wǎng)卡,如果應用軟件(如IE)向虛擬網(wǎng)卡發(fā)送數(shù)據(jù),則服務程序可以讀取到該數(shù)據(jù),如果服務程序寫合適的數(shù)據(jù)到虛擬網(wǎng)卡,應用軟件也可以接收得到。虛擬網(wǎng)卡在很多的操作系統(tǒng)下都有相應的實現(xiàn),這也是Open0pn能夠跨平臺一個很重要的理由。
  在Open0pn中,如果用戶訪問一個遠程的虛擬地址(屬于虛擬網(wǎng)卡配用的地址系列,區(qū)別于真實地址),則操作系統(tǒng)會通過路由機制將數(shù)據(jù)包(TUN模式)或數(shù)據(jù)幀(TAP模式)發(fā)送到虛擬網(wǎng)卡上,服務程序接收該數(shù)據(jù)并進行相應的處理后,通過SOCKET從外網(wǎng)上發(fā)送出去,遠程服務程序通過SOCKET從外網(wǎng)上接收數(shù)據(jù),并進行相應的處理后,發(fā)送給虛擬網(wǎng)卡,則應用軟件可以接收到,完成了一個單向傳輸?shù)倪^程,反之亦然。

open0pn的優(yōu)缺點

  優(yōu)點:成本低,是一個廉價有效的構建私有網(wǎng)絡的方式,用它可以替代昂貴的實體專線;靈活,比實體專線更靈活。例如,一個公司可以在0pn站點的數(shù)量調整,根據(jù)不斷變化的需求。
  缺點:搭建不容易,對技術要求非常高,需要對網(wǎng)絡和安全問題有高水平的理解以及認真地規(guī)劃和配置。由于在互聯(lián)網(wǎng)上缺乏質量服務(QoS)管理,可能會導致數(shù)據(jù)包丟失和其他性能問題。若公共網(wǎng)絡條件發(fā)生問題,則私網(wǎng)的管理員不能控制。出于這個原因,許多大公司一般購買使用可信0pn使用專用網(wǎng)絡,以保證服務質量。

0pn的作用

  • 訪問外網(wǎng)
  • 提升網(wǎng)速(案例網(wǎng)游加速)

0pn的分類

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

open0pn的部署

1.關閉selinux

 setenforce 0

2.安裝編譯環(huán)境

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  //執(zhí)行腳本生成證書時,需要設置一些環(huán)境變量 
    #生成根證書-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 #生成密碼協(xié)議交換文件
    build-key  #生成免密碼客戶端密鑰對
    build-key-pass #生成帶密碼客戶端密鑰對
    build-key-server #生成服務端密鑰對
    clean-all #初始化配置,清空所有keys
    pkitool #各證書生成主要調用此命令執(zhí)行
    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.生成密鑰協(xié)議交換文件

./build-dh #視網(wǎng)絡環(huán)境,等待即可

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 #指定監(jiān)聽的協(xié)議,當并發(fā)訪問多時,推薦tcp
dev tun #*** server的模式采用路由模式??蛇xtap或tun
ca /etc/open***/keys/ca.crt #寫絕對路徑
cert /etc/open***/keys/jhrdc.crt
dh /etc/open***/keys/dh3048.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.調試服務啟動

#開啟路由轉發(fā)功能
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

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI