CentOS下利用openvpn 搭建ssl-vpn
一、OpenVPN是靠虛擬的TUN/TAP裝置實現SSL VPN的,因此核心必須支援TUN/TAP裝置模組,這個配置選項在2.6.x核心中,位於Device Drivers ->Network device support 選單中,全稱是Universal TUN/TAP device driver support ,通常在標準核心 中,會以模組方式提供,在Open VPN啟動時,它會自動載入此模組,因此不需要手工載入此模組。
[[email protected] 2.6.18-238.12.1.el5-i686]# pwd
/usr/src/kernels/2.6.18-238.12.1.el5-i686
[
Device Drivers --->
Network device support --->
<M> Universal TUN/TAP device driver support #<M>即表示以模組化載入到核心中
二、在安裝OpenVPN之前,還需要安裝一些支援包,包括OpenSSL開發庫和LZO壓縮開發庫
1、可使用yum安裝OpenSSL開發庫,但需要手工下載並安裝LZO開發包。
[[email protected] /]#yum install openssl-devel
2、可到 http://www.oberhumer.com/opensource/lzo/ 下載LZO
[[email protected] src]#tar zxvf lzo-2.03.tar.gz
[[email protected] src]#cd lzo-2.03
[[email protected] lzo-2.03]#./configure
[[email protected]
[[email protected] lzo-2.03]#make install
三、配置SSL VPN服務
1、到 http://openvpn.net/release/ 下載openvpn-2.0.9.tar.gz並安裝
[[email protected] src]# tar zxvf openvpn-2.0.9.tar.gz
[[email protected] src]# cd openvpn-2.0.9/
[[email protected] openvpn-2.0.9]# ./configure
[[email protected] openvpn-2.0.9]# make
[[email protected] openvpn-2.0.9]# make install
[[email protected] openvpn-2.0.9]# cp -p sample-scripts/openvpn.init /etc/init.d/openvpn
[[email protected] openvpn-2.0.9]# chkconfig --add openvpn
[[email protected] openvpn-2.0.9]# service openvpn status #檢視服務狀態
openvpn: service not started
[[email protected] openvpn-2.0.9]# chkconfig --level 235 openvpn on
[[email protected] openvpn-2.0.9]# chkconfig --list openvpn
openvpn 0:off 1:off 2:on 3:on 4:on 5:on 6:off
2、開啟IP轉發功能
[[email protected] openvpn-2.0.9]# vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
[[email protected] openvpn-2.0.9]# sysctl -p
3、定義OpenVPN的配置目錄為/etc/openvpn,把伺服器配置檔案定義為/etc/openvpn/server.conf
OpenVPN是一個SSL VPN實現,因此,認證中最重要的是伺服器和客戶端的SSL證書管理,如果管理員之前沒有SSL證書釋出機制,那麼可以使用OpenVPN附帶的一組工具來完成所有的工作。
在/usr/src/openvpn-2.0.9/中,有一個easy-rsa目錄,這下面就是一些一成和管理SSL證書的工具,以下為生成證書操作。
[[email protected] openvpn-2.0.9]# mkdir -p /etc/openvpn
[[email protected] openvpn-2.0.9]# cp -p sample-config-files/server.conf /etc/openvpn/#將樣本配置檔案複製到/etc/openvpn/,後面再做修改
4、修改vars檔案變數,設定國家程式碼、省份、地市、機構名單、單位名稱郵件等
[[email protected] openvpn-2.0.9]# cd easy-rsa/
[[email protected] easy-rsa]# grep -v "#" vars
export D=`pwd`
export KEY_CONFIG=$D/openssl.cnf
export KEY_DIR=$D/keys
echo NOTE: when you run ./clean-all, I will be doing a rm -rf on $KEY_DIR
export KEY_SIZE=1024
export KEY_COUNTRY=CN
export KEY_PROVINCE=GD
export KEY_CITY=SZ
export KEY_ORG="DIC"
export KEY_EMAIL="[email protected]"
[[email protected] easy-rsa]# source vars
NOTE: when you run ./clean-all, I will be doing a rm -rf on /usr/src/openvpn-2.0.9/easy-rsa/keys#提示可使用./clean-all清除所有包括CA在內的所有證書
5、使用clean-all指令碼清除包括CA在內的所有證書,再建立CA證書。
[[email protected] easy-rsa]# ./clean-all #先清除證書,再建立證書
[[email protected] easy-rsa]# ./build-ca #建立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) [CN]:
State or Province Name (full name) [GD]:
Locality Name (eg, city) [SZ]:
Organization Name (eg, company) [DIC]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:dic172#伺服器主機名
Email Address [[email protected]]:
6、建立伺服器金鑰。
[[email protected] easy-rsa]# ./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) [CN]:
State or Province Name (full name) [GD]:
Locality Name (eg, city) [SZ]:
Organization Name (eg, company) [DIC]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:dic172#伺服器主機名
Email Address [[email protected]]:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:dic172
An optional company name []:dic172
Using configuration from /usr/src/openvpn-2.0.9/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:'DIC'
commonName :PRINTABLE:'dic172'
emailAddress :IA5STRING:'[email protected]'
Certificate is to be certified until Jul 16 05:51:08 2021 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
7、建立客戶端金鑰,客戶端金鑰名可隨意命名。
[[email protected] easy-rsa]# ./build-key client
Generating a 1024 bit RSA private key
.....++++++
.......................++++++
writing new private key to 'client.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) [GD]:
Locality Name (eg, city) [SZ]:
Organization Name (eg, company) [DIC]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:tgh #不同客戶端,命名絕不能一樣
Email Address [[email protected]]:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:dic172
An optional company name []:dic172
Using configuration from /usr/src/openvpn-2.0.9/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:'DIC'
commonName :PRINTABLE:'tgh'
emailAddress :IA5STRING:'[email protected]'
Certificate is to be certified until Jul 16 05:52:27 2021 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
8、建立dhDiffie-Hellman )金鑰演算法檔案
[[email protected] easy-rsa]# ./build-dh
Generating DH parameters, 1024 bit long safe prime, generator 2
This is going to take a long time
...+.......+.....+........................+......................+.....+...........................+..........+.......+.................................................+.....................+............+..............................................+..........................................................+..............................+...........................+..+.....+......++*++*++*
9、生成 tls-auth 金鑰 ,tls-auth金鑰可以為點對點的VPN連線提供了進一步的安全驗證,如果選擇使用這一方式,伺服器端和客戶端都必須擁有該金鑰檔案。
[[email protected] easy-rsa]# openvpn --genkey --secret keys/ta.key
[[email protected] easy-rsa]# cp -rp keys/ /etc/openvpn/ #將證書檔案複製到/etc/openvpn/
10、修改server.conf配置檔案
[[email protected] openvpn]# grep -v "#" server.conf
local 192.168.161.172 #伺服器所使用的IP
port 1194 #使用1194埠 埠需要修改
proto udp #使用UDP協議 可同時使用TCP UDP 搭建多程序ssl-VPN服務
dev tun #使用tun裝置
ca /etc/openvpn/keys/ca.crt #指定CA證書檔案路徑
cert /etc/openvpn/keys/server.crt
dh /etc/openvpn/keys/dh1024.pem
tls-auth /etc/openvpn/keys/ta.key 0
server 172.16.10.0 255.255.255.0 #VPN客戶端撥入後,所獲得的IP地址池
ifconfig-pool-persist ipp.txt
push "dhcp-option DNS 202.96.134.133" #客戶端所獲得的DNS
client-to-client
keepalive 10 120
comp-lzo
persist-key
persist-tun
status openvpn-status.log
verb 3
mute 20
[[email protected] openvpn-2.0.9]# service openvpn start
Starting openvpn: [ OK ]
[[email protected] openvpn-2.0.9]# netstat -anp |grep :1194
udp 0 0 192.168.161.172:1194 0.0.0.0:* 25162/openvpn
四、在XP客戶端配置SSL VPN(客戶端IP 192.168.163.96)
1、到http://openvpn.se/files/install_packages/下載openvpn-2.0.9-gui-1.0.3-install.exe
2、安裝openvpn-2.0.9-gui-1.0.3-install.exe,一路next。由於只是做客戶端使用,不必安裝OpenVPN Service
安裝完成後,在工作列會新增加一個OpenVPN GUI和本地連線圖示。
3、配置客戶端,把伺服器上/etc/openvpn/keys/ca.*,client.*,ta.* 複製客戶端C:\Program Files\OpenVPN\config下;再從C:\Program Files\OpenVPN\sample-config複製一個客戶端配置樣本檔案client.ovpn到C:\Program Files\OpenVPN\config下。
4、修改client.ovpn檔案如下並儲存。
client
dev tun
proto udp #proto tcp
remote 192.168.161.172 1194
resolv-retry infinite
nobind
ca ca.crt
cert client.crt
key client.key
tls-auth ta.key 1
comp-lzo
verb 3
mute 20
5、啟動連線。右擊右下角的OpenVPN GUI圖示,連線
6、連線成功後,圖示如下。到此,SSL VPN服務就配置好了。
相關推薦
CentOS下利用openvpn 搭建ssl-vpn
一、OpenVPN是靠虛擬的TUN/TAP裝置實現SSL VPN的,因此核心必須支援TUN/TAP裝置模組,這個配置選項在2.6.x核心中,位於Device Drivers ->Network device support 選單中,全稱是Universal TUN/TAP device dr
windows下利用OpenVPN搭建VPN伺服器
一、OpenVPN是一款功能強大,可跨平臺(支援Win 2000/XP/2003, Linux, Mac OS X, Solaris, FreeBSD, NetBSD, 和 OpenBSD)使用的SSL VPN伺服器軟體(具體說明見官方主頁官方主頁http://openvp
CentOS 下 Hadoop 環境搭建--Hadoop
mkdir left res 修改文件 wordcount cat 創建 work tar ---恢復內容開始--- ①解壓Hadoop到自定目錄下面(這裏解壓到/opt/hadoop目錄下) tar -zxvf hadoop-2.5.0.tar.gz -C /opt/
CentOS下SAMBA的搭建
centos samba搭建一、Samba的由來:早起網絡中,檔案數據傳輸大多使用FTP這個軟件進行傳送,FTP的弊端是無法直接修改服務器上面的數據,更新數據,只能靠來回拷貝,時間久了,容易混淆。於是就有了NFS(NetworkFile System),通過共享目錄的掛載實現對Server上的檔案數據讀寫更新
win7下利用IIS搭建FTP服務器
div 第一步 brief bsp 就是 用戶和組 bce ssl ice 配置一個完整的FTP服務器比較復雜,可以使用Windows系統自帶的FTP服務(默認情況下Windows自帶的Web和FTP服務是關閉的)。前段時間,為了與他人共享文件,為創建一個FTP服務
Spring Boot開發系列(Cassandra)(一)--CentOS下Cassandra環境搭建
Spring Boot開發系列(Cassandra)(一)–CentOS下Cassandra環境搭建 【1】安裝JAVA 1.8 檢視CentOS中已安裝的JAVA版本 rpm -qa|grep jdk 解除安裝CentOS中系統預裝的JAVA yum -y
Spring Boot開發系列(Redis)(二)--CentOS下Redis環境搭建
Spring Boot開發系列(Redis)(二)–CentOS下Redis環境搭建 【1】安裝redis 下載最新版的redis yum install -y http://rpms.famillecollet.com/enterprise/remi-rele
centos下PHP環境搭建
usermod -g web -G admin web mkdir -p /home/soft mkdir -p /home/webadm/wwwroot chmod -R 777 /home/webadm/wwwroot cd /home/soft 1、nginx
CentOS7下一鍵搭建PPTP VPN指令碼
此指令碼轉載自:隨想日誌,感謝原作者 指令碼已親測可用,環境是centos7.4 #!/bin/bash [ $(id -u) != "0" ] && { echo "Error: You must be root to run this sc
centos下hadoop叢集搭建詳細過程
Hadoop叢集搭建全過程 參考操作:課本劉鵬《雲端計算》,劉鵬《實戰hadoop》,上網google 需要軟體:VMware-workstation-9.0.exe;CentOS-6.4-i386-bin-DVD1.iso(3.51G,裡面的外掛比較全,VMtools都
Centos下Caffe環境搭建
網上各路大神的配置很繁瑣 其實官網 http://caffe.berkeleyvision.org/installation.html的配置和安裝步驟很簡單 而且針對了不同環境 所以我建議大家不要按照xx的blog來,做個參考可以(包括我的) 。遇到錯誤的時候再Googl
eclipse下利用maven搭建ssm環境
<!-- 統一定義jar包版本號 --> <properties> <aspectj.version>1.6.8</aspectj.version> <commons-fileupload.version>1.3.1</com
centos下Docker環境搭建(一)
Docker是一個能夠把開發的應用程式自動部署到容器的開源引擎,基於客戶端-伺服器架構c/s,讓開發者可以打包他們的應用以及依賴包到一個可移植的容器中,然後釋出到任何流行的Linux 機器上,也可以實現虛擬化。容器是完全使用沙箱機制,相互之間不會有任何介面。 Docker
Linux(centos)下用vim搭建php開發環境IDE
讓vi以vim來執行 輸入alias命令: alias檢視當前所有命令 下面是加入命令 ? 1 alias vi='vim' 這表示當你使用vi 這個命令時,其實執行的是vim。如果沒有這一行,那麼你必須使用vim filename來啟動vim。 al
CentOS下Git伺服器搭建與客戶端(windows和centos)搭建
一.伺服器端 1.yum安裝Git伺服器 yum install -y git 2.建立一個git使用者,用來執行git服務 useradd git 3.建立客戶端登入證書 注,收集所有需要登入的使用者的公鑰,就是他們自己生成的id_rsa.pub檔案,把所有公鑰複製到/
win7下利用IIS搭建FTP伺服器
1、再回到“Internet資訊服務(IIS)管理器”視窗,雙擊剛才選中的“FTP授權規則”,在FTP站點中對View和Admin授權。如下所示: 2、點選右側的“新增允許規則”,在彈出的視窗中,勾選“指定的使用者”,輸入View,在下方的“許可權”中,勾選“讀取”。如下所示:
windows下利用IIS搭建web和ftp服務以及防火牆配置
第一步:找到程式與功能裡面的啟動或關閉windows功能。選擇如下圖:第二步:點選計算機管理,選擇IIS。將底下預設的Default web site網站關閉。然後右擊網站,新建一個網站,填寫如下資訊。網站名稱隨便自己起,網站根目錄自己選擇一個資料夾。協議如何你的網站網站得到
centos下python環境搭建
一、安裝 pyenv 1、理想情況下 輸入 curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash 開始下載pyenv並安裝,安裝完成輸
centos下https詳細配置-SSL
1、 安裝mod_ssl 2、 Ssl.conf: 上面pem,下面key 通過yum來線上安裝mod_ssl [[email protected] ~]# yum -y install mod_ssl ← 線上安裝mod_ssl Lo
centos下go環境搭建及hello world
Go語言是谷歌2009釋出的第二款開源程式語言。 Go語言專門針對多處理器系統應用程式的程式設計進行了優化,使用Go編譯的程式可以媲美C或C++程式碼的速度,而且更加安全、支援並行程序。 Go適合用來做什麼 伺服器程式設計,以前你如果使用C或者C++做的那些事情,用Go來做