歡迎您光臨本站 註冊首頁

RHEL5/CentOS5下OpenVPN安裝和Windows下OpenVPN GUI安裝筆記

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

RHEL5/CentOS5下OpenVPN安裝和Windows下OpenVPN GUI安裝筆記

RHEL5下OpenVPN 安裝和Windows OpenVPN GUI 安裝筆記

                                                                                                 ----------------- 撫琴煮酒

        網上少有RHEL5配置openVPN的資料,所以特將RHEL5下的配置過程寫下來,其過程與RHEL4發現居然是一樣的..以下實驗截圖是在RHEL5下.實驗在RHEL5下測試均通過.特將實驗步驟摘錄如下,希望能給大家帶來幫助,轉載請註明我的博客地址http://hi.baidu.com/yuhongchun027

一、 安裝伺服器
1、 到http://openvpn.net/上下載openvpn的最新版,時至今日是openvpn-2.0.9.tar.gz。
a) 網上都說還需要lzo這個壓縮庫。我沒有安裝,在編譯程序的時候只需要加上--disable-lzo就可以了。這樣所有要安裝的就是一個包openvpn-2.0.9.tar.gz。
2、 上傳到伺服器gait.buaa.edu.cn上,解開成為/root/openvpn-2.0.9。
3、 cd /root/openvpn-2.0.9
4、 ./configure --disable-lzo。

1)建立CA

在OpenVPN源代碼目錄下有一個\easy-rsa\2.0目錄,進入后修改vars文件最後部分的信息:

export KEY_COUNTRY="CN"
export KEY_PROVINCE="BJ"
export KEY_CITY="Beijing"
export KEY_ORG="PKU"
export KEY_EMAIL=" xxxxxx@pku.edu.cn"

保存退出,再運行:

source vars
./clean-all
./build-ca

然後就是一段提示,要求輸入信息,大部分信息默認就是上述vars文件里的信息,自己只需要填寫「Organizational Unit Name」一項,這個隨便寫一個就是了,也可以不寫,我就沒有寫。



2)為伺服器生成證書和密鑰

./build-key-server server

還是與上一步類似,自己只需要填寫「Organizational Unit Name」一項,也可以不寫,此步不寫的話建立windows VPN client要能正確解析VPN伺服器名,我更改的是c:\windows\system32/drivers/etc/hosts文件,將VPN伺服器的域名解析文件寫入此.

還會出現:「Sign the certificate? 」和「1 out of 1 certificate requests certified, commit? 」,都輸入y然後回車。

./build-key-server server
./build-key-server server

Generating a 1024 bit RSA private key
......++++++
....................++++++
writing new private key to 'server.key'
-----
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) :
State or Province Name (full name) :
Locality Name (eg, city) :
Organization Name (eg, company) :
Organizational Unit Name (eg, section) []:gait
Common Name (eg, your name or your server's hostname) []:server
Email Address [support@cooldvd.com]:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:abcd1234
An optional company name []:dvdmaster
Using configuration from /openvpn-2.0.5/easy-rsa/openssl.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'CN'
stateOrProvinceName :PRINTABLE:'GD'
localityName :PRINTABLE:'SZ'
organizationName :PRINTABLE:'dvdmaster'
organizationalUnitName:PRINTABLE:'dvdmaster'
commonName :PRINTABLE:'server'
emailAddress :IA5STRING:'support@cooldvd.com'
Certificate is to be certified until Mar 19 08:15:31 2016 GMT (3650 days)
Sign the certificate? :y

1 out of 1 certificate requests certified, commit? y
Write out database with 1 new entries
Data Base Updated


3)在openvpn中,這種配置方法是每一個登陸的VPN客戶端需要有一個證書,每個證書在同一時刻只能供一個客戶端連接(如果有兩個機器安裝相同證書,同時撥伺服器,都能撥上,但是只有第一個撥上的才能連通網路)。所以需要建立許多份證書。下面建立2份,名稱分別為client1和client2
./build-key client1
Generating a 1024 bit RSA private key
.....++++++
......++++++
writing new private key to 'client1.key'
-----
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) :
State or Province Name (full name) :
Locality Name (eg, city) :
Organization Name (eg, company) :
Organizational Unit Name (eg, section) []:gait
Common Name (eg, your name or your server's hostname) []:client1 #重要: 每個不同的 client 生成的證書, 名字必須不同.
Email Address [support@cooldvd.com]:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:abcd1234
An optional company name []:gait
Using configuration from /openvpn-2.0.5/easy-rsa/openssl.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'CN'
stateOrProvinceName :PRINTABLE:'GD'
localityName :PRINTABLE:'SZ'
organizationName :PRINTABLE:'dvdmaster'
organizationalUnitName:PRINTABLE:'dvdmaster'
commonName :PRINTABLE:'client1'
emailAddress :IA5STRING:'support@cooldvd.com'
Certificate is to be certified until Mar 19 08:22:00 2016 GMT (3650 days)
Sign the certificate? :y


1 out of 1 certificate requests certified, commit? y
Write out database with 1 new entries
Data Base Updated


依次類推生成其他客戶端證書/key:
./build-key client2

4)./build-dh

生成的證書文件均在/root/openvpn-2.0.9/easy-rsa/2.0/keys下

5)配置伺服器VPN文件
a) cp /root/openvpn-2.0.9/sample-config-files/server.conf /usr/local/etc/server.conf
b) vi /usr/local/etc/server.conf
i. proto udp改成proto tcp
ii. ca那四行改成
ca     /root/openvpn-2.0.9/easy-rsa/2.0/keys/ca.crt
cert   /root/openvpn-2.0.9/easy-rsa/2.0/keys/server.crt
key   /root/openvpn-2.0.9/easy-rsa/2.0/keys/server.key
dh    /root/openvpn-2.0.9/easy-rsa/2.0/keys/dh1024.pem
iii. server那行改成
server 10.0.0.0 255.255.255.0
iv. 註釋掉comp-lzo
v. 改成verb 5可以多查看一些調試信息


5) 啟動服務:
a) 關閉伺服器、防火牆上所有對SSH(22)、openvpn(1194)的攔截。
b) echo "1" > /proc/sys/net/ipv4/ip_forward
c) /usr/local/sbin/openvpn --config /usr/local/etc/server.conf

二.安裝WidnowsVPN客戶端

4. 安裝客戶端
1、 從http://openvpn.se/files/上下載與openvpn伺服器版本一致的Windows客戶端「OpenVPN GUI For Windows」
a) 例如, 伺服器裝的是 OpenVPN 2.09, 那麼下載的 OpenVPN GUI fow windows應該是: openvpn-2.0.9-gui-1.0.3-install.exe
2、 執行openvpn-2.0.9-gui-1.0.3-install.exe。一切採用默認設置。
3、 將ca.crt、client1.crt、client1.key複製到C:\Program Files\OpenVPN\config。(不同用戶使用不同的證書,每個證書包括.crt和.key兩個文件,如client2.crt和client2.key)
4、 在/root/openvpn-2.0.9/sample-config-files/client.conf 的基礎上建立客戶端配置文件,改名為C:\Program Files\OpenVPN\config\client.ovpn
a) proto udp改成proto tcp
b) remote那行改成
gait.buaa.edu.cn 1194            //感覺直接寫成VPN的IP地址好像也行
c) ca那3行改為
ca ca.crt
cert client1.crt
key client1.key
d) 註釋掉comp-lzo
5、 連接:在右下角的openvpn圖標上右擊,選擇「Connect」。正常情況下應該能夠連接成功,分配正常的IP。







     我在RHEL4將此實驗過程按以上步驟,也順利通過了,有興趣的同學和朋友可對照實驗(撫琴煮酒)



OPENVPN的特點:

加密

OpenVPN使用OpenSSL庫加密數據與控制信息:它使用了OpesSSL的加密以及驗證功能,意味著,它能夠使用任何OpenSSL支持的演算法。它提供了可選的數據包HMAC功能以提高連接的安全性。此外,OpenSSL的硬體加速也能提高它的性能。





驗證

OpenVPN提供了多種身份驗證方式,用以確認參與連接雙方的身份,包括:預享私鑰,第三方證書以及用戶名/密碼組合。預享密鑰最為簡單,但同時它只能用於建立點對點的VPN;基於PKI的第三方證書提供了最完善的功能,但是需要額外的精力去維護一個PKI證書體系。OpenVPN2.0后引入了用戶名/口令組合的身份驗證方式,它可以省略客戶端證書,但是仍有一份伺服器證書需要被用作加密。


網路
OpenVPN所有的通信都基於一個單一的IP埠,默認且推薦使用UDP協議通訊,同時TCP也被支持。OpenVPN連接能通過大多數的代理伺服器,並且能夠在NAT的環境中很好地工作。服務端具有向客戶端「推送」某些網路配置信息的功能,這些信息包括:IP地址、路由設置等。OpenVPN提供了兩種虛擬網路介面:通用Tun/Tap驅動,通過它們,可以建立三層IP隧道,或者虛擬二層乙太網,後者可以傳送任何類型的二層乙太網絡數據。傳送的數據可通過LZO演算法壓縮。IANA(Internet Assigned Numbers Authority)指定給OpenVPN的官方埠為1194。OpenVPN 2.0以後版本每個進程可以同時管理數個併發的隧道。
OpenVPN使用通用網路協議(TCP與UDP)的特點使它成為IPsec等協議的理想替代,尤其是在ISP(Internet service provider)過濾某些特定VPN協議的情況下。
在選擇協議時候,需要注意2個加密隧道之間的網路狀況,如有高延遲或者丟包較多的情況下,請選擇TCP協議作為底層協議,UDP協議由於存在無連接和重傳機制,導致要隧道上層的協議進行重傳,效率非常低下。


安全
OpenVPN與生俱來便具備了許多安全特性:它在用戶空間運行,無須對內核及網路協議棧作修改;初始完畢后以chroot方式運行,放棄root許可權;使用mlockall以防止敏感數據交換到磁碟。
OpenVPN通過PKCS#11支持硬體加密標識,如智能卡。


對比

[火星人 ] RHEL5/CentOS5下OpenVPN安裝和Windows下OpenVPN GUI安裝筆記已經有817次圍觀

http://coctec.com/docs/service/show-post-29522.html