歡迎您光臨本站 註冊首頁

(轉)Redhat Linux企業版4的openvpn安裝

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

(轉)Redhat Linux企業版4的openvpn安裝

http://www.chinaunix.net 作者:jgj   發表於:2008-05-05 15:57:52


一、 需求
1、 安裝方便,平台兼容性高,不用編譯內核。(我比較反感動不動就要重新編譯內核的軟體);
2、 能夠沒有限制的穿透NAT內網;(這個非常關鍵,因為現在我的伺服器是在學校拖管,我們實驗室內部都是一層一層NAT出去的,)
由於以上兩點限制,在現有許多種方案中,我試用了兩種:pptpd和opensvn。pptpd是網上比較推薦使用的,因為配置非常方便,就改兩個小文件就可以配置成功。但是有一個致命的弱點是起了兩個埠,大多數情況下穿透NAT是個障礙,所以我最終放棄了。改用opensvn后解決了NAT的問題,在內網和公網上測試沒有任何問題。
openvpn的唯一缺限是不能夠使用Windows內置的vpn客戶端,需要另外安裝軟體,所幸安裝過程很簡單。

二、 安裝環境
1. 伺服器:Dell 6850伺服器,Redhat Linux 企業版4 Update 2,內核2.6.9-22.ELsmp。
2. 客戶端:Windows xp SP2
3. 網路結構:



a) 我們是北航校園網裡面的一個實驗室區域網,在學校網路中心託管了一台伺服器gait.buaa.edu.cn。
b) 從我們實驗室到校園網是一層NAT出去的。實驗室裡面是192.168.48.xxx的內網地址。
c) 伺服器有對外的獨立地址(屬於教育網內的獨立地址),目前由於網管中心的疏忽,對內、對外都沒有做任何埠限制(由此可見北航網管的整體水平),因此開通VPN服務是有可能的。
d) 經過我的配置,gait.buaa.edu.cn上面起了VPN服務,默認的子網地址是10.0.0.1。這樣在公網上的機器就可以撥入,而且可以連通到任何已經撥入這台伺服器的校園網主機。形成一個虛擬的10.0.0.x子網。從這個意義上,VPN服務也像是一個「虛擬HUB」,使得學校內、外的計算機可以互通,使得經過層層NAT和防火牆攔截的計算機連到了一個局域上。

三、 安裝伺服器
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。
a) 這個過程很可能需要Redhat的一些開發包,我安裝的時候又打上了openssl-devel-0.9.7a-43.2.i386.rpm、zlib-devel-1.2.1.2-1.2.i386.rpm、e2fsprogs-devel-1.35-12.2.EL4.i386.rpm,當然如果是完全安裝的伺服器就不用了。
5、 make ; make install
a) 我在很多機器上都做了編譯,不應該出現任何問題。這個軟體做的還是不錯的。
6、 生成證書
a) cd /root/openvpn-2.0.9/easy-rsa
i. export D=`pwd`
ii. export KEY_CONFIG=$D/openssl.cnf
iii. export KEY_DIR=$D/keys
iv. export KEY_SIZE=1024
v. export KEY_COUNTRY=CN
vi. export KEY_PROVINCE=BJ
vii. export KEY_CITY=BJ
viii. export KEY_ORG="buaa"
ix. export KEY_EMAIL=guojie.jin@hotmail.com
b) ./clean-all
c) ./build-ca
./clean-all
./build-ca

Generating a 1024 bit RSA private key
................++++++
........++++++
writing new private key to 'ca.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) : buaa
Organizational Unit Name (eg, section) []:gait
Common Name (eg, your name or your server's hostname) []:server
Email Address [guojie.jin@hotmail.com]:



d) ./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



e) 客戶端證書
在openvpn中,這種配置方法是每一個登陸的VPN客戶端需要有一個證書,每個證書在同一時刻只能供一個客戶端連接(如果有兩個機器安裝相同證書,同時撥伺服器,都能撥上,但是只有第一個撥上的才能連通網路)。所以需要建立許多份證書。下面建立三份,名稱分別為client1 – client3。
./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


f) 依次類推生成其他客戶端證書/key:
./build-key client2
./build-key client3
注意在進入 Common Name (eg, your name or your server's hostname) []: 的輸入時, 每個證書輸入的名字必須不同.
g) 執行./build-dh
h) 生成的所有證書在/root/openvpn-2.0.9/easy-rsa/keys下。
i. 其中伺服器需要的是ca.crt、server.crt、server.key、dh1024.pem,每個客戶端需要的是ca.crt、client1-3.crt、client1-3.key。
7、 配置文件
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/keys/ca.crt
cert /root/openvpn-2.0.9/easy-rsa/keys/server.crt
key /root/openvpn-2.0.9/easy-rsa/keys/server.key
dh /root/openvpn-2.0.9/easy-rsa/keys/dh1024.pem
iii. server那行改成
server 10.0.0.0 255.255.255.0
iv. 註釋掉comp-lzo
v. 改成verb 5可以多查看一些調試信息
8、 啟動服務:
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
d) 為了實現開機啟動,在/etc/rc.local後面添加
/usr/local/sbin/openvpn --config /usr/local/etc/server.conf > /dev/null 2>&1 &
4. 安裝客戶端
1、 從http://openvpn.se/上下載與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
c) ca那3行改為
ca ca.crt
cert client1.crt
key client1.key
d) 註釋掉comp-lzo
5、 連接:在右下角的openvpn圖標上右擊,選擇「Connect」。正常情況下應該能夠連接成功,分配正常的IP。
a) 在使用中發現,openvpn不是連續分IP,而是10.0.0.6、10.0.0.10、10.0.0.14、……這樣分下去,不知是何用意。

這貼是轉載的,圖片支持得不是很好http://hi.baidu.com/yuhongchun027
《解決方案》

本人操作系統為RHEL5, 在此基礎上配置成功了OPENVPN,因限於篇幅,這裡就不貼出來了,有興趣的朋友可去我博客http://hi.baidu.com/yuhongchun027

[火星人 ] (轉)Redhat Linux企業版4的openvpn安裝已經有641次圍觀

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