CENTOS6.5下的OpenVPN的配置

一、安裝準備
1、安裝openssl、gcc、libpam
#yum -y install openssl-devel openssl
#yum -y install gcc gcc-c++
#yum -y install pam-devel.x86_64

如遇Segmentation Fault,在/usr/local/lib下,刪除鏈接libz.so和libz.so.1
#rm -f libz.so
#rm -f libz.so.1
安裝完之後恢復這兩個鏈接即可
#ln -s libz.so.1.2.7 libz.so.1
#ln -s libz.so.1 libz.so

二、OpenVPN服務端安裝過程

下載lzo,下載鏈接爲http://www.oberhumer.com/opensource/lzo/#download,下載完之後複製到/var/tmp目錄下
1、lzo的安裝
#cd /var/tmp    //安裝目錄
#gunzip zxvf lzo-2.04.tar.gz    //解壓
#tar zxvf lzo-2.04.tar    //解壓
#cd lzo-2.04
#./configure
#make
#make install   #編譯與安裝

2、openvpn下載與安裝

下載openvpn,下載鏈接爲https://openvpn.net/index.php/open-source/downloads.html,下載完之後複製到/var/tmp目錄下
#cd /var/tmp
#gunzip xvf openvpn-2.3.10.tar.gz
#tar xvf openvpn-2.3.10.tar
#./configure
#make
#make install

安裝好了檢查一下openvpn版本
#openvpn --version

3、easy-sea安裝
下載openvpn,下載鏈接爲https://community.openvpn.net/openvpn/wiki/GettingEasyRsa,下載完之後複製到/var/tmp目錄下
#cd /var/tmp
#gunzip xvf easy-rsa-2.2.0_master.tar.gz
#tar xvf easy-rsa-2.2.0_master.tar
#./configure
#make
#make install

安裝路徑是/usr/local/share/easy-esa/

三、製作證書
複製源文件至目標路徑
#mkdir /etc/openvpn
#cp -rf /usr/local/share/easy-rsa /etc/openvpn/

0、配置vars
#vi /etc/openvpn/easy-rsa/vars
export KEY_SIZE=2048      //DH證書的長度設爲2048,缺省爲1024

export KEY_COUNTRY="CN"
export KEY_PROVINCE=“SH”
export KEY_CITY=“Shanghai”
export KEY_ORG=“jhrdc”
export KEY_EMAIL=“[email protected]
export KEY_OU=“jhrdc“
export KEY_NAME=“jhrdc”       //特別重要,“jhrdc”根據情況自己設定

#cd /etc/openvpn/easy-rsa
#source vars  //執行腳本生成證書時,需要設置一些環境變量
#./clean-all    //製作客戶端證書時,不需要執行該腳本

1、生成根證書-CA證書,CA證書同時需要部署在服務器和客戶端上
#./build-ca
#cp keys/ca.crt /etc/openvpn/

2、生成服務器端證書
#./build-key-server jhrdc
#./build-dh
#cp keys/jhrdc.crt keys/jhrdc.key keys/dh2048.pem /etc/openvpn/

3、Client端證書
#./build-key jhrdc    //使用服務器端的CN設定
Generating a 2048 bit RSA private key
................................................................................................+++
....+++
writing new private key to ‘jhrdc.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) [CN]:
State or Province Name (full name) [SH]:
Locality Name (eg, city) [Shanghai]:
Organization Name (eg, company) [JH]:
Organizational Unit Name (eg, section) [jhrdc]:
Common Name (eg, your name or your server's hostname) [jhrdc]:testchannel1    //給不同的客戶端創建證書和私鑰時,可以使用不同名字
Name [jhrdc]:testchannel1
Email Address [[email protected]]:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:


如遇“TXT_DB error number 2”錯誤,重新touch一個keys/index.txt

生成的客戶端證書位於/etc/openvpn/easy-rsa/keys,分別是jhrdc.crt、jhrdc.csr、jhrdc.key。這幾個證書和前面所生成的服務器端的證書有所不同,僅可爲客戶端所使用,請將這幾個證書文件和ca.crt打包,拷貝到客戶端電腦備用。

注意,同一個證書,缺省配置情況下同時只能從一個客戶端登陸

四、配置openvpn服務器
修改服務器配置文件
#cp /var/tmp/openvpn-2.3.10/sample/sample-config-files/server.conf /etc/openvpn/
#vi /etc/openvpn/server.conf
port 1194 //端口設爲1194
proto tcp //協議設爲tcp
ca ca.crt //ca.crt的路徑,建議和server.conf在一個目錄下
cert jhrdc.crt //jhrdc.crt的路徑,建議和server.conf在一個目錄下
key jhrdc.key //jhrdc.key的路徑,建議和server.conf在一個目錄下
server 10.8.0.0 255.255.255.0 //DHCP服務器的IP段,缺省是10.8.0.0
client-to-client //VPN客戶端之間允許互相訪問,如不需要客戶端之間互相訪問,則可註釋該配置
max-clients 10 //併發的客戶端鏈接,可設爲10個
user nobody //服務啓動時使用的系統用戶,建議使用nobody
group nobody //服務啓動時使用的系統用戶組,建議使用nobody

五、啓動openvpn的服務器端
#cd /etc/openvpn
#openvpn —config /etc/openvpn/server.conf —daemon

六、配置客戶端
下載Windows客戶端,下載鏈接爲https://openvpn.net/index.php/download/community-downloads.html,

安裝後,將第三步所生成的證書文件和配置文件放在一個目錄裏,並修改客戶端配置文件,然後啓動該配置文件即大功告成。配置文件簡要說明
client
proto tcp
remote 111.111.111.111 1194   //VPN服務器的IP地址和端口號
ca ca.crt //ca.crt的路徑,建議和server.conf在一個目錄下
cert testchannel1.crt //testchannel1.crt的路徑,建議和server.conf在一個目錄下

key testchannel1.key //testchannel1.key的路徑,建議和server.conf在一個目錄下


原文 http://bbs.csdn.net/topics/391948237

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章