1. 安裝前先裝 rpmforge

官網:http://rpmrepo.org/RPMforge/Using

下載後用 rpm 安裝

2. yum install openvpn lzo lzo-devel openssl openssl-devel

3.建立Root CA certifacate及Server/Client keys:


CentOS 5.5的路徑

cd /usr/share/doc/openvpn-2.1.4/easy-rsa/2.0
chmod 755 *
 
  1. 設定 CA 環境

vim vars
按自己的需求更改:
export KEY_COUNTRY=TW
export KEY_PROVINCE=Taiwan
export KEY_CITY=Taipei
export KEY_ORG=”Test-Office”
export
KEY_EMAIL=”test@gmail.com

source ./vars

./clean-all

。 建置 root CA

./build-ca

會在 keys 資料夾內 產生ca.key,ca.crt

 

。 建置 Diffie Hellman 參數

./build-dh

會在 keys 資料夾內 產生dh1024.pem

 

。 建置 server key 及 crt
使用build-key-server 這支script 為 OpenVPN Server 建立憑證:

./build-key-server server(名稱可自訂)

會在 keys 資料夾內 產生server.key,server.crt

 

。 產生 tls-auth key:

防止Dos 及 UDP port flooding 攻擊。

openvpn --genkey --secret ta.key
會產生 ta.key,將ta.key移到keys/裡
mv ta.key keys/
 
 
將上面產生金鑰放入 /etc/openvpn/
。 cp –a ca.crt ta.key dh1024.pem server.* /etc/openvpn/
 
。 接著建立,建立User 的憑證。
build-key client1(名稱可自訂)

 

 
======================================================

將server.conf copy一份到/etc/openvpn內

cp server.conf /etc/openvpn/

修改 /etc/openvpn/server.conf
======================================================
port 1194 預設不變
proto tcp (預設使用udp,如果要使用HTTP proxy,必須採用tcp模式)
dev tap    
原文有提到

# "dev tun" will create a routed IP tunnel,
# "dev tap" will create an ethernet tunnel.

所以看你習慣用哪個 簡單來說 tun 類似點對點,tap 類似區網環境,適用Bridge

以效能來說 tun 會優於 tap

# Key File 路徑設定 (基本上都在/etc/openvpn/內)

ca ca.crt
cert server.crt
key server.key

dh dh1024.pem

server 192.168.10.0 255.255.255.0 (vpn使用網段,勿和原有網段相衝突)

ifconfig-pool-persist ipp.txt 
(client重新連線時會按照ipp.txt文件內容分配ip位址。 )
client-to-client(client之間可以互相連結 )

 

client-config-dir ccd

針對每個client 設置規則

在/etc/openvpn內建立一資料夾 ccd,

當一新client開始連接OpenVPN server的時候,程式會先搜尋符合正在連接的client端用戶 Common Name的文件,一旦找到相符的文件它會自動執行文件中的配置。

ex:在ccd目录中放入名為client1的文件,文件中包含以下内容:
push “route 192.168.4.0 255.255.255.0”

這樣設定後VPN Server 將會把192.168.4.0/24這網段路由加入到 client1 內

keepalive 10 120 (每10秒ping 一次,120秒後client端沒回應就斷線)

comp-lzo (對OpenVPN連接進行壓縮,client的配置檔client.ovpn必須同時使用)

status openvpn-status.log (記錄log)

verb 3 (log記錄等級)

 

push "redirect-gateway"
這個設定會將Client端的Default Gateway自動指到OpenVPN Server
不必擔心default gateway更改了以後會造成原來對OpenVPN Server連結中斷

push "dhcp-option DNS 10.8.0.1"
設定 Client 端所使用的 DNS
若 OpenVPN Server 本身有 DNS 則可直接使用內定的 IP
若無, 設定一台離 OpenVPN Server 最近的 DNS

 

==========================================

openvpn client

可在官網下載

http://openvpn.net/index.php/open-source/downloads.html

Windows Installer openvpn-2.2.0-install.exe

安裝完後可以看到如下圖

openvpn1.JPG

 

將 OpenVPN Sample Configuration Files中sample檔(範例檔)複製一份到

OpenVPN configuration file directory後 內容修改成與 VPN Server中的server.conf內容參數一樣存檔後(檔案名可自取,副檔名為ovpn ex:client1.opvn)

# The hostname/IP and port of the server.
# You can have multiple remote entries
# to load balance between the servers.

其中這段要填入VPNServer的ip和port
remote 10.10.50.51 1194

 

並且把ca.crt,client1.crt,client1.key,client1.csr,ta.key 以及client1.opvn放入到OpenVPN configuration file directory中

========================================================

NAT設定

iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -o eth0 -j MASQUERADE

 

  1. forward設定 (看個人需求)
  2. echo "1" > /proc/sys/net/ipv4/ip_forward
  3. 讓vpn的虛擬網卡在server開放input/output
    iptables -A INPUT -i tun+ -j ACCEPT
  4. iptables -A OUTPUT -o tun+ -j ACCEPT
  5. 開放server端的vpn與實體網路進出FORWARD
    iptables -A FORWARD -i eth* -o tun+ -j ACCEPT
    iptables -A FORWARD -i tun+ -o eth* -j ACCEPT

  6. 注意,eth*的星號,指的是你實體網卡的編號,建議指定一張就好
     

 

 

 

 

參考:http://blog.nuface.tw/?p=941

http://blog.roodo.com/shishimaru/archives/15579399.html

http://hi.baidu.com/farmerluo/blog/item/07aa5343908959069213c641.html

http://www.study-area.org/tips/openvpn.html

http://cheaster.blogspot.com/2009/11/openvpn-by-ssl.html

http://blog.77run.com/OpenVPN-client-ovpn/     參數詳解

http://openvpn.net/index.php/open-source/documentation/howto.html#examples

http://j796160836.pixnet.net/blog/post/25721059

arrow
arrow
    全站熱搜

    neo2124 發表在 痞客邦 留言(0) 人氣()