Open***-HOWTO中文版

Open***-HOWTO中文版


Open*** HOWTO
介紹
此文檔描述一個典型的Home到Office的通信中Open***的配置。這份HOWTO舉了一個完整的配置實例,在man page手冊頁中有一個更爲簡單的例子。
此HOWTO文檔還有如下格式:


附加的文檔
其他的一些很好的文檔及HOWTO
爲不同環境下配置Open***而作。
基本的隧道(Tunnel)類型
Open***可以創建兩種基本的隧道類型:
  • Routed IP tunnels -- 適用於不需廣播的點對點IP(point-to-point)通信。比起橋接網絡隧道來略顯得更有效率些而且更易配置。此HOWTO文檔涵蓋了Routed IP tunnels。
  • Bridged Ethernet Tunnels(橋接網絡隧道) -- 能用於IP協議或非IP協議的隧道。這種類型的隧道更適合於使用廣播(broadcast)的應用,比如某些Windows網絡遊戲。配置起來稍微複雜些。
    關於橋接網絡隧道的Mini-HOWTO。

Routed IP tunnel HOWTO
我們會嘗試描述一個完整的系統配置,期間涉及到防火牆,***,NAT以及他們彼此間的相互關聯,我們不會孤立的一部分一部分的探討***設置。
在我們的例子中,Home和Office機器所在的私有網絡都分別通過了一臺具有公網IP地址的網關機器接入互聯網。每臺網關機器都配有兩塊網卡(NIC),一塊聯入內網,另一塊聯入公網。網關機器爲內網機器提供NAT,防火牆,***服務。Home及Office機器的配置基本一樣,除了 Office的網關機器爲固定IP,Home機器的IP爲DHCP動態獲取。
在以下例子中所顯示的配置文件在Open***發佈版本中是有效的。
Home和Office的IP網絡參數
Home
Office
本地子網 (內網地址)
10.0.1.0/24
10.0.0.0/24
Tunnel Endpoint (內網地址)
10.1.0.2
10.1.0.1
Open*** Gateway (公網地址)
DHCP client, need not be explicitly specified
1.2.3.4  
安裝 Open***
如果你的系統沒有OpenSSL庫,你需要
下載和安裝它

如果你想使用***連接的壓縮特性,或者你想將Open***安裝爲一個RPM包,安裝
LZO Library

如果你使用Linux 2.2 或更早版本,下載
TUN/TAP driver
。對於Linux 2.4.7及以上版本的用戶TUN/TAP 驅動已經捆綁到內核中。Linux 2.4.0 -> 2.4.6 的用戶需要留意
INSTALL
文件末尾的注意信息。
現在下載 Open*** 的最新發布版:
http://prdownloads.sourceforge.net/open***/open***-1.6.0.tar.gz
使用 tarball 安裝
解開發布版的壓縮包:
gzip -dc open***-1.6.0.tar.gz | tar xvf -
創建 Open***:
cd open***-1.6.0
./configure
make
make install

如果你未下載 LZO Library ,將 --disable-lzo 加入到 configure 命令中。也可以啓用其他的選型,比如 pthread (./configure --enable-pthread) 用來提高 SSL/TLS 動態密鑰交換的響應速度。命令
./configure --help
將顯示所有的配置選型。
從 RPM 安裝
首先創建RPM文件。此操作需要 OpenSSl,pthread,和
LZO
庫。通常只會有 LZO 庫需要額外下載並安裝;; 其他的庫在大多數的Linux 發行版本中已經作爲缺省安裝。
rpmbuild -tb open***-1.6.0.tar.gz
RPM 創建過程會生成大量輸出信息。創建成功後,在輸出信息的末尾附記會有一個提示信息說明生成的二進制RPM文件名。用如下命令安裝該文件:
rpm -Uvh binary-RPM-file
配置 TUN/TAP 驅動
僅需一次的配置如果你使用 Linux 2.4.7 或更高版本,十分幸運 TUN/TAP 驅動已經捆綁到內核中。你可以通過如下命令確認:
locate if_tun.h
此命令產生類似這樣的信息 /usr/include/linux/if_tun.h
對於 Linux 2.4.7 或更高版本,如果你通過 tarball 安裝,輸入如下命令配置 TUN/TAP 設備節點(如果你通過 RPM 安裝可以忽略這一步,因爲RPM爲你自動創建該節點):
mknod /dev/net/tun c 10 200
如果你使用 Linux 2.2,你需要獲得
版本 1.1
的TUN/TAP kernel module 並按照安裝說明進行操作。
每次系統啓動後需要執行一次的配置
在 Linux 上使用 Open*** 或任何用到 TUN/TAP 設備的程序前需要載入 TUN/TAP kernel module:
modprobe tun
並且啓用 IP 轉發:
echo 1 > /proc/sys/net/ipv4/ip_forward
配置 Firewall 和 NAT
這一小節假定你使用 Linux 2.4 和 iptables 防火牆。這裏是一個防火牆配置的例子,它爲內網機器訪問互聯網提供了NAT服務,stateful outgoing connection tracking, 和 Open*** 支持:
sample-config-files/firewall.sh
#!/bin/bash
# Open***-aware 防火牆例子.
# eth0 連接到互聯網.
# eth1 連接到內部子網.
# 這裏改變你的子網地址
# Home   使用 10.0.1.0/24
# Office 使用 10.0.0.0/24
PRIVATE=10.0.0.0/24
# Loopback 地址
LOOP=127.0.0.1
# 刪除舊的 iptables 規則
# 並且臨時阻塞網絡通信
iptables -P OUTPUT DROP
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -F
# 設置缺省策略
iptables -P OUTPUT ACCEPT
iptables -P INPUT DROP
iptables -P FORWARD DROP
# 阻止外部數據包使用 loopback 地址
iptables -A INPUT -i eth0 -s $LOOP -j DROP
iptables -A FORWARD -i eth0 -s $LOOP -j DROP
iptables -A INPUT -i eth0 -d $LOOP -j DROP
iptables -A FORWARD -i eth0 -d $LOOP -j DROP
# 任何從互聯網流入的數據包都必須使用真實互聯網地址
iptables -A FORWARD -i eth0 -s 192.168.0.0/16 -j DROP
iptables -A FORWARD -i eth0 -s 172.16.0.0/12 -j DROP
iptables -A FORWARD -i eth0 -s 10.0.0.0/8 -j DROP
iptables -A INPUT -i eth0 -s 192.168.0.0/16 -j DROP
iptables -A INPUT -i eth0 -s 172.16.0.0/12 -j DROP
iptables -A INPUT -i eth0 -s 10.0.0.0/8 -j DROP
# 阻塞 NetBios 數據包流出(如果內網有 windows 機器)。
# 這不會影響 *** 隧道上的NetBios通信,
# 但它會阻止本地 windows 機器向互聯網廣播自己。
iptables -A FORWARD -p tcp --sport 137:139 -o eth0 -j DROP
iptables -A FORWARD -p udp --sport 137:139 -o eth0 -j DROP
iptables -A OUTPUT -p tcp --sport 137:139 -o eth0 -j DROP
iptables -A OUTPUT -p udp --sport 137:139 -o eth0 -j DROP
# 檢查流向互聯網的數據包中源地址的合法性
iptables -A FORWARD -s ! $PRIVATE -i eth1 -j DROP
# 允許本地 loopback
iptables -A INPUT -s $LOOP -j ACCEPT
iptables -A INPUT -d $LOOP -j ACCEPT
# 允許向內的(incoming) ping 操作(可以禁止)
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
# 允許 www 和 ssh 服務(可以禁止)
iptables -A INPUT -p tcp --dport http -j ACCEPT
iptables -A INPUT -p tcp --dport ssh -j ACCEPT
# 允許向內的(incoming) Open*** 數據包
# 對於每條 Open*** 隧道要將以下每行重複,
# 改變 --dport n 爲 Open*** UDP 實際端口。
#
# 在 Open***中,端口號由 --port n 選項控制。
# 如果你將這個選型寫入配置文件,
# 你可以去掉 '--'後這一串字符。
#
# If you taking the stateful firewall
# approach (參看 Open*** HOWTO),
# 那麼註釋掉下面這一行。
iptables -A INPUT -p udp --dport 5000 -j ACCEPT
# 允許來自 TUN/TAP 設備的數據包。
# 當 Open*** 運行於安全模式時,
# 他會對 tun 或 tap 接口上的數據包到達前進行驗證。
# 也就是說,這裏添加的任何過濾不是必需的,
# 除非你想對有可能溢出隧道的數據包類型進行嚴格約束。
iptables -A INPUT -i tun+ -j ACCEPT
iptables -A FORWARD -i tun+ -j ACCEPT
iptables -A INPUT -i tap+ -j ACCEPT
iptables -A FORWARD -i tap+ -j ACCEPT
# 允許來自內網的數據包
iptables -A INPUT -i eth1 -j ACCEPT
iptables -A FORWARD -i eth1 -j ACCEPT
# 保持來自本機和內網數據包的連接狀態
iptables -A OUTPUT -m state --state NEW -o eth0 -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -m state --state NEW -o eth0 -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
# 僞裝本地子網
iptables -t nat -A POSTROUTING -s $PRIVATE -o eth0 -j MASQUERADE

Open*** 在防火牆設置中提供少量的附加選項:
  • If both Open*** peers reference the other with an explicit --remote option, and stateful firewalls that provide UDP connection tracking (such as iptables) exist between the peers, it is possible to run Open*** without any explicit firewall rules, if both peers originate regular pings to each other to keep the connection alive. To do this, simply run Open*** with the --remote peer option, and specify --ping 15 to ensure that packets flow over the tunnel at least once every 15 seconds.
  • 上面的選項在隧道一端(peer)頻繁變更 IP 地址比如說DHCP或撥號時,顯得不夠方便。在這種情況下,以上簡單的防火牆配置將允許任何IP地址通過UDP端口5000(Open*** 的缺省UDP端口) 流入數據包。在 Open*** 的安全模式下,所有流入隧道的數據或者通過安全驗證或者被丟棄,所以它通常被認爲是安全的。
  • 如果你選擇完全開放 Open*** 的 incoming UDP 端口就像上面簡單防火牆中的配置一樣,你可能會想利用 --tls-auth 選項在 TLS 控制通道上作雙倍的驗證,同時使用 RSA 密鑰和預先分享的密碼短語(passphrase)來作爲防禦 DoS 或 active ***的第二道防線。關於--tls-auth 的更多信息,參考
    open*** man page。

創建 RSA 證書和密鑰
Open*** 有兩種安全模式,一種基於使用 RSA 證書和密鑰的 SSL/TLS,一種使用預先分享的靜態密鑰。SSL/TLS + RSA 密鑰被證明是一種最安全的選擇,靜態密鑰優勢則在於簡潔。如果你想使用 RSA 密鑰,繼續往下讀。要使用靜態密鑰,向前跳到
創建預分享靜態密鑰
一節.
我們將使用 openssl 命令創建 RSA 證書和密鑰,該命令包含在 OpenSSL 庫的發佈程序中。
RSA 證書是一種公開密鑰,在其中還含有其他安全域,比如說證書持有者的 Common Nameemail 地址。Open*** 有能力在進行認證前對這些域進行測試。更多信息參考
open*** man page
中的 --tls-verify 選項。
在我們的例子中遵從 apache 慣例使用 .crt 擴展名錶示證書文件,.key 擴展名錶示私鑰。私鑰文件必須安全保管。證書文件可以自由發佈共享。
選擇一臺機器比如 Office 作爲密鑰管理主機。
首先編輯文件 /usr/share/ssl/openssl.cnf (這個文件也許在其他地方,可以用 locate openssl.cnf 命令找到它)。
你或許會對它作一些修改:
  • 建立一個目錄作爲密鑰的工作目錄,將 dir 指向它。
  • 考慮增加有限期限 default_days 以免你的 *** 在工作整一年後莫名其妙的終止。
  • 設定 certificateprivate_key 指向你的根證書 (master certificate authority certificate)和私鑰文件(我們馬上要生成它)。在下面的例子中,我們假定你的證書文件名爲 my-ca.crt,你的私鑰文件名爲 my-ca.key
  • 注意文件 index.txtserial。將 index.txt 清空,serial 初始化爲包含一個數字序列比如 01.
  • 如果你狂熱的追求密鑰長度,那可以將 default_bits 增加到2048。 對於打開 pthread 支持(可以後臺處理 RSA 密鑰)的 Open*** 處理2048位的 RSA 密鑰是毫無問題的。甚至沒有打開pthread 支持時也可以使用更長的密鑰,但你會在隧道中作 SSL/TLS 密鑰協商時感覺到響應時間的延遲。這裏有一份選擇 RSA 密鑰長度的很好的文章,參見
    April 2002 issue
    of Bruce Schneier's Crypto-Gram Newsletter.

openssl.cnf 編輯完後,創建根證書/私鑰對(master certificate authority certificate/private-key pair):
openssl req -nodes -new -x509 -keyout my-ca.key -out my-ca.crt -days 3650
這將會創建一對有效期爲十年的根證書/私鑰對。
現在爲 Home 和 Office 創建 證書/私鑰對:
openssl req -nodes -new -keyout office.key -out office.csr
openssl ca -out office.crt -in office.csr
openssl req -nodes -new -keyout home.key -out home.csr
openssl ca -out home.crt -in home.csr

現在將 home.crt, home.key, 和 my-ca.crt 文件通過安全途徑拷貝到 Home 機器上,儘管實際上只有.key 才被認爲是應該保密的。
現在在 Office 機器上創建 Diffie Hellman 參數,使用下列命令:
openssl dhparam -out dh1024.pem 1024
如果在 openssl.cnf 中增大了密鑰位數,相應的這裏也要把 1024 改爲 2048。
對於偏執狂可以考慮去掉上面 openssl 命令中的-nodes 選項。其結果是對每一個私鑰進行口令加密,從而保證當有人攻入你的主機盜走你的私鑰時仍有一定的安全性。麻煩的是每次當你使用 Open*** 時都需要輸入口令。更多信息參考
open*** man page
中的 --askpass 選項。
如果你對手工管理 RSA 密鑰覺得困惑,那要指出一點 Open*** 可以很好的同任何 X509 證書管理工具或服務包括商業化的 CAs 如
Thawte
or
Verisign
等協同工作。檢索
OpenCA
項目可以查看有哪些同證書/密鑰管理工具 配合良好的開源項目。
另外,Open*** 發佈版中包含了一組腳本能夠簡化
RSA 證書和密鑰管理

在 Open*** 上使用商業證書(CAs)的重要提示
It should be noted that Open***'s security model in SSL/TLS mode is oriented toward users who will generate their own root certificate, and hence be their own CA. In SSL/TLS mode, Open*** authenticates its peer by checking that the peer-supplied certificate was signed by the CA certificate specified in the --ca option. Like the SSL-based secure web, the security of Open***'s SSL/TLS mode rests on the infeasibility of forging a root certificate signature.
This authentication procedure works perfectly well if you have generated your own root certificate, but presents a problem if you wish to use the root certificate of a commercial CA such as Thawte. If, for example, you specified Thawte's root certificate in the --ca option, any certificate signed by Thawte would now be able to authenticate with your Open*** peer -- certainly not what you would want.
Luckily there is a solution to this problem in the --tls-verify option. This option will allow you to execute a command to check the contents of a certificate, to fine-tune the selection of which certificate is allowed, and which is not. See the script verify-cn in the sample-scripts subdirectory for an example of how to do this, and also see the man page for the --tls-verify option.
使用 SSL/TLS 模式和 RSA 證書/密鑰的配置文件
在我們的例子中,我們使用 Open*** 配置文件。Open*** 允許由命令行或一個或多個配置文件指定參數。在命令行中由"--"引導的參數在配置文件中是可以忽略"--"的,命令行中則不行。
設置下列配置文件:
sample-config-files/tls-office.conf
#
# Sample Open*** configuration file for
# office using SSL/TLS mode and RSA certificates/keys.
#
# '#' 或 ';' 用於表明註釋.
# 使用 dynamic tun device.
# For Linux 2.2 or non-Linux OSes,
# 你可以使用顯式指明的設備號,比如"tun1"
# Open*** 也支持虛擬網絡 "tap" devices;
dev tun
# 10.1.0.1 is our local *** endpoint (office).
# 10.1.0.2 is our remote *** endpoint (home).
ifconfig 10.1.0.1 10.1.0.2
# up 腳本將在 *** 激活時建立路由
up ./office.up
# 在 SSL/TLS 密鑰交換時,Office 作爲 server,Home 作爲 client
tls-server
# Diffie-Hellman Parameters (tls-server only)
dh dh1024.pem
# Certificate Authority file
ca my-ca.crt
# Our certificate/public key
cert office.crt
# Our private key
key office.key
# Open*** 缺省使用 UDP 端口 5000 .
# 每一個 Open*** tunnel 必須使用一個不同的端口.
# lport 和 rport 被用於指明本地或遠程的不同端口
; port 5000
# 出於安全考慮,初始化後UID 和GID 權限將降爲 "nobody"
; user nobody
; group nobody
# 如果你的Open***支持LZO 壓縮,去掉這一行的註釋
; comp-lzo
#
# 每15秒向遠端主機發送一個 UDP ping
# stateful firewall connection
# alive.  Uncomment this
# out if you are using a stateful
# firewall.
; ping 15
# Uncomment this section for a more reliable detection when a system
# loses its connection.  For example, dial-ups or laptops that
# travel to other locations.
; ping 15
; ping-restart 45
; ping-timer-rem
; persist-tun
; persist-key
# 信息細節等級
# 0 -- 除非發生致命錯誤,否則保持安靜。
# 1 -- 非常安靜,但會顯示一些非致命網絡錯誤。
# 3 -- 中等輸出,通常情況下的很好選擇。
# 9 -- 非常詳細,用於診斷錯誤。
verb 3

sample-config-files/office.up
#!/bin/bash
route add -net 10.0.1.0 netmask 255.255.255.0 gw $5

sample-config-files/tls-home.conf
#
# Sample Open*** configuration file for
# home using SSL/TLS mode and RSA certificates/keys.
#
# '#' or ';' may be used to delimit comments.
# Use a dynamic tun device.
# For Linux 2.2 or non-Linux OSes,
# you may want to use an explicit
# unit number such as "tun1".
# Open*** also supports virtual
# ethernet "tap" devices.
dev tun
# Our Open*** peer is the office gateway.
remote 1.2.3.4
# 10.1.0.2 is our local *** endpoint (home).
# 10.1.0.1 is our remote *** endpoint (office).
ifconfig 10.1.0.2 10.1.0.1
# Our up script will establish routes
# once the *** is alive.
up ./home.up
# 在 SSL/TLS 密鑰交換時,Office 作爲 server,Home 作爲 client
tls-client
# Certificate Authority file
ca my-ca.crt
# Our certificate/public key
cert home.crt
# Our private key
key home.key
# Open*** 缺省使用 UDP 端口 5000 .
# 每一個 Open*** tunnel 必須使用一個不同的端口.
# lport 和 rport 被用於指明本地或遠程的不同端口
; port 5000
# 出於安全考慮,初始化後UID 和GID 權限將降爲 "nobody"
; user nobody
; group nobody
# 如果你的Open***支持LZO 壓縮,去掉這一行的註釋
; comp-lzo
# 每15秒向遠端主機發送一個 UDP ping
# stateful firewall connection
# alive.  Uncomment this
# out if you are using a stateful
# firewall.
; ping 15
# Uncomment this section for a more reliable detection when a system
# loses its connection.  For example, dial-ups or laptops that
# travel to other locations.
; ping 15
; ping-restart 45
; ping-timer-rem
; persist-tun
; persist-key
# 信息細節等級
# 0 -- 除非發生致命錯誤,否則保持安靜。
# 1 -- 非常安靜,但會顯示一些非致命網絡錯誤。
# 3 -- 中等輸出,通常情況下的很好選擇。
# 9 -- 非常詳細,用於診斷錯誤。
verb 3

sample-config-files/home.up
#!/bin/bash
route add -net 10.0.0.0 netmask 255.255.255.0 gw $5

創建一個預分享靜態密鑰(Pre-Shared Static Key)
同 RSA 密鑰管理極爲不同的是,使用預分享靜態密鑰是十分簡單。The major downside of using static keys is that you give up the notion of perfect forward secrecy, meaning that if an attacker steals your static key, everything that was ever encrypted with it is compromised.
使用如下命令生成靜態密鑰:
open*** --genkey --secret static.key
靜態密鑰文件由ascii組成,就像下面這樣:
-----BEGIN Open*** Static key V1-----
e5e4d6af39289d53
171ecc237a8f996a
97743d146661405e
c724d5913c550a0c
30a48e52dfbeceb6
e2e7bd4a8357df78
4609fe35bbe99c32
bdf974952ade8fb9
71c204aaf4f256ba
eeda7aed4822ff98
fd66da2efa9bf8c5
e70996353e0f96a9
c94c9f9afb17637b
283da25cc99b37bf
6f7e15b38aedc3e8
e6adb40fca5c5463
-----END Open*** Static key V1-----

一個 Open*** 靜態密鑰包含有足夠的熵值,其中512位作爲加密鍵,512位作爲身份驗證的 HMAC。(An Open*** static key file contains enough entropy to key both a 512 bit cipher key and a 512 bit HMAC key for authentication.)
通過安全的媒介將 static.key 拷貝到另一端(peer),比如使用scp ssh 中的拷貝、粘貼。
使用預共享靜態密鑰(Pre-Shared Static Key)的配置文件
在我們的例子中,我們使用 Open*** 配置文件。Open*** 允許由命令行或一個或多個配置文件指定參數。在命令行中由"--"引導的參數在配置文件中是可以忽略"--"的,命令行中則不行。
Set up the following configuration files:
sample-config-files/static-office.conf
#
# Sample Open*** configuration file for
# office using a pre-shared static key.
#
# '#' or ';' may be used to delimit comments.
# Use a dynamic tun device.
# For Linux 2.2 or non-Linux OSes,
# you may want to use an explicit
# unit number such as "tun1".
# Open*** also supports virtual
# ethernet "tap" devices.
dev tun
# 10.1.0.1 is our local *** endpoint (office).
# 10.1.0.2 is our remote *** endpoint (home).
ifconfig 10.1.0.1 10.1.0.2
# Our up script will establish routes
# once the *** is alive.
up ./office.up
# Our pre-shared static key
secret static.key
# Open*** uses UDP port 5000 by default.
# Each Open*** tunnel must use
# a different port number.
# lport or rport can be used
# to denote different ports
# for local and remote.
; port 5000
# Downgrade UID and GID to
# "nobody" after initialization
# for extra security.
; user nobody
; group nobody
# If you built Open*** with
# LZO compression, uncomment
# out the following line.
; comp-lzo
# Send a UDP ping to remote once
# every 15 seconds to keep
# stateful firewall connection
# alive.  Uncomment this
# out if you are using a stateful
# firewall.
; ping 15
# Uncomment this section for a more reliable detection when a system
# loses its connection.  For example, dial-ups or laptops that
# travel to other locations.
; ping 15
; ping-restart 45
; ping-timer-rem
; persist-tun
; persist-key
# 信息細節等級
# 0 -- 除非發生致命錯誤,否則保持安靜。
# 1 -- 非常安靜,但會顯示一些非致命網絡錯誤。
# 3 -- 中等輸出,通常情況下的很好選擇。
# 9 -- 非常詳細,用於診斷錯誤。
verb 3

sample-config-files/office.up
#!/bin/bash
route add -net 10.0.1.0 netmask 255.255.255.0 gw $5

sample-config-files/static-home.conf
#
# Sample Open*** configuration file for
# home using a pre-shared static key.
#
# '#' or ';' may be used to delimit comments.
# Use a dynamic tun device.
# For Linux 2.2 or non-Linux OSes,
# you may want to use an explicit
# unit number such as "tun1".
# Open*** also supports virtual
# ethernet "tap" devices.
dev tun
# Our Open*** peer is the office gateway.
remote 1.2.3.4
# 10.1.0.2 is our local *** endpoint (home).
# 10.1.0.1 is our remote *** endpoint (office).
ifconfig 10.1.0.2 10.1.0.1
# Our up script will establish routes
# once the *** is alive.
up ./home.up
# Our pre-shared static key
secret static.key
# Open*** uses UDP port 5000 by default.
# Each Open*** tunnel must use
# a different port number.
# lport or rport can be used
# to denote different ports
# for local and remote.
; port 5000
# Downgrade UID and GID to
# "nobody" after initialization
# for extra security.
; user nobody
; group nobody
# If you built Open*** with
# LZO compression, uncomment
# out the following line.
; comp-lzo
# Send a UDP ping to remote once
# every 15 seconds to keep
# stateful firewall connection
# alive.  Uncomment this
# out if you are using a stateful
# firewall.
; ping 15
# Uncomment this section for a more reliable detection when a system
# loses its connection.  For example, dial-ups or laptops that
# travel to other locations.
; ping 15
; ping-restart 45
; ping-timer-rem
; persist-tun
; persist-key
# 信息細節等級
# 0 -- 除非發生致命錯誤,否則保持安靜。
# 1 -- 非常安靜,但會顯示一些非致命網絡錯誤。
# 3 -- 中等輸出,通常情況下的很好選擇。
# 9 -- 非常詳細,用於診斷錯誤。
verb 3

sample-config-files/home.up
#!/bin/bash
route add -net 10.0.0.0 netmask 255.255.255.0 gw $5

在 SSL/TLS mode 下啓動 ***
Home 機器端,用如下命令啓動 *** :
open*** --config tls-home.conf
Office 端,用如下命令啓動 *** :
open*** --config tls-office.conf
在靜態密鑰模式(Static Key mode)下啓動 ***
Home 機器端,用如下命令啓動 *** :
open*** --config static-home.conf
Office 端,用如下命令啓動 *** :
open*** --config static-office.conf
測試 ***
在 Home 機器上,可以通過 ping Office 主機(經過隧道)來測試 ***:
ping 10.1.0.1
在 Office 機器上,可以通過 ping Home 主機(經過隧道)來測試 ***:
ping 10.1.0.2
如果測試失敗但無輸出信息,可以編輯配置文件將 信息細節等級 調爲8(將產生大量細節信息用於調試)。參考
FAQ
獲取更多錯誤處理信息。
如果測試通過,可以嘗試經過隧道 ping 另一端子網中的機器(網關機器除外)來測試路由。基本上10.0.1.0/24 子網中的任一機器可以訪問 10.0.1.0/24 子網中的任意機器,反之亦然。
如果工作正常,恭喜你!如果不正常,你可以查看郵件列表
Open*** Mailing List
有沒有相似問題。如果問題依舊,可以考慮貼到 open***-users 列表。
Make the *** DHCP-aware
回想一下,在我們的網絡配置中,Home是使用動態 IP,地址可以任意的變化。如果你的客戶端(client daemon)使用 dhcpcd ,那寫一個適應IP地址任意變化的腳本也是很容易的。這個腳本或許被命名爲/etc/dhcpc/dhcpcd-eth0.exe.
基本上你要作的就是將下面這一行加入腳本,其作用是向 Open*** daemon 發送一個SIGUSR1SIGHUP 信號:
killall -HUP open***
當 Open*** 收到這個信號後會關閉連接隨後再使用DHCP獲取的新的IP重新與對端連接。
如果你連接的對端由於 DHCP 重置而改變IP地址,你也許會考慮使用 --float 選項。
DHCP 重置時也有可能是 SIGUSR1 起作用,相比SIGHUP 它會在Open***子系統重置時提供更多的進程回收控制。--ping--ping-restart 也會內在的產生SIGUSR1信號。
--persist-tun 選項實現重置時不需關閉重新打開 TUN 設備(這就爲在DHCP上的隧道提供了一種無縫連接)。
--persist-remote-ip 選項實現在DHCP重置時會保留遠端 IP 地址。這樣就允許 Open*** 隧道的兩端都可以爲DHCP client。
--persist-key 選項實現在重啓時不用重新讀取密鑰文件(這樣就允許 Open*** daemon 在權限降爲 --user--group 時也能實現重啓)。
在 動態IP 環境下使用 Open***的 更多信息,可參考
FAQ

Open*** 也能在如下環境使用:
連接兩端都爲動態地址

系統重啓時自動啓動 ***
首先建立一個目錄存放Open***密鑰和配置文件,如: /etc/open***.
選擇使用TLS模式或靜態密鑰模式 ,將適當的 .conf, .up, .key, .pem, 和 .crt 文件拷入 目錄/etc/open***.
保護你的 .key 文件:
chmod go-rwx /etc/open***/*.key
如果使用 Linux iptables,編輯防火牆配置文件 firewall.sh,將相應的變動拷入目錄/etc/open***.
創建類似如下的 startup 腳本:
sample-config-files/open***-startup.sh
#!/bin/bash
# A sample Open*** startup script
# for Linux.
# open*** config file directory
dir=/etc/open***
# 載入防火牆
$dir/firewall.sh
# 載入 TUN/TAP kernel module
modprobe tun
# 開啓IP轉發
echo 1 > /proc/sys/net/ipv4/ip_forward
# 爲每一個***隧道喚醒一個守護(daemon)模式的open***
# Invoke open*** for each *** tunnel
# in daemon mode.  Alternatively,
# you could remove "--daemon" from
# the command line and add "daemon"
# to the config file.
#
# Each tunnel should run on a separate
# UDP port.  Use the "port" option
# to control this.  Like all of
# Open***'s options, you can
# specify "--port 8000" on the command
# line or "port 8000" in the config
# file.
open*** --cd $dir --daemon --config ***1.conf
open*** --cd $dir --daemon --config ***2.conf
open*** --cd $dir --daemon --config ***2.conf

創建類似如下的 shutdown 腳本:
sample-config-files/open***-shutdown.sh
#!/bin/bash
# stop all open*** processes
killall -TERM open***

最後將 open***-startup.shopen***-shutdown.sh 腳本添加到系統的 startup 和shutdown 腳本中 或拷貝到 /etc/init.d 目錄.
管理多條 Open*** 隧道的 startup 和 shutdown
這裏是一個/etc/init.d 下的腳本例子,它自動爲 /etc/open*** 下的每一個.conf 文件創建一條 Open*** 隧道。
該腳本在通過 RPM 安裝 Open*** 時會缺省安裝到機器上。
sample-scripts/open***.init
#!/bin/sh
#
# open***       This shell script takes care of starting and stopping
#               open*** on RedHat or other chkconfig-based system.
#
# chkconfig: 345 80 30
#
# 描述:         Open*** is a robust and highly flexible tunneling application that
#              uses all of the encryption, authentication, and certification features
#              of the OpenSSL library to securely tunnel IP networks over a single
#              UDP port.
#
# Contributed to the Open*** project by
# Douglas Keller
# 2002.05.15
# 安裝此腳本:
#   將這個文件拷貝到 /etc/rc.d/init.d/open***
#   shell> chkconfig --add open***
#   shell> mkdir /etc/open***
#   make .conf or .sh files in /etc/open*** (see below)
# 刪除此腳本:
#   運行: chkconfig --del open***
# 作者提示:
#
# 我已經寫了一個 /etc/init.d 初始化腳本並修改了 open***.spec 可以自動註冊該腳本。
# RPM 包裝好後你可以直接使用 "service open*** start" 和 "service open*** stop".
# 命令啓動和終止 Open***.
#
# 初始化腳本工作如下:
#
# - 爲它在/etc/open***下找到的每一個 .conf 文件啓動一個 open*** 進程
#
# - 如果存在對應於 xxx.conf 的 /etc/open***/xxx.sh 文件,
#   那麼在它啓動 open*** 前執行它(作 open*** --mktun... 時很有用)。
#
# - 除 start/stop 外還可以執行:
#
#   service open*** reload - SIGHUP
#   service open*** reopen - SIGUSR1
#   service open*** status - SIGUSR2
# Modifications 2003.05.02
#   * Changed == to = for sh compliance (Bishop Clark).
#   * If condrestart|reload|reopen|status, check that we were
#     actually started (James Yonan).
#   * Added lock, piddir, and work variables (James Yonan).
#   * If start is attempted twice, without an intervening stop, or
#     if start is attempted when previous start was not properly
#     shut down, then kill any previously started processes, before
#     commencing new start operation (James Yonan).
#   * Do a better job of flagging errors on start, and properly
#     returning success or failure status to caller (James Yonan).
# Location of open*** binary
open***="/usr/sbin/open***"
# Lockfile
lock="/var/lock/subsys/open***"
# PID directory
piddir="/var/run/open***"
# Our working directory
work=/etc/open***
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -f  $open*** ] || exit 0
# See how we were called.
case "$1" in
  start)
        echo -n $"Starting open***: "
        /sbin/modprobe tun >/dev/null 2>&1
        # From a security perspective, I think it makes
        # sense to remove this, and have users who need
        # it explictly enable in their --up scripts or
        # firewall setups.
        #echo 1 > /proc/sys/net/ipv4/ip_forward
        if [ ! -d  $piddir ]; then
            mkdir $piddir
        fi
        if [ -f $lock ]; then
            # we were not shut down correctly
            for pidf in `/bin/ls $piddir/*.pid 2>/dev/null`; do
              if [ -s $pidf ]; then
                kill `cat $pidf` >/dev/null 2>&1
              fi
              rm -f $pidf
            done
            rm -f $lock
            sleep 2
        fi
        rm -f $piddir/*.pid
        cd $work
        # Start every .conf in $work and run .sh if exists
        errors=0
        successes=0
        for c in `/bin/ls *.conf 2>/dev/null`; do
            bn=${c%%.conf}
            if [ -f "$bn.sh" ]; then
                . $bn.sh
            fi
            rm -f $piddir/$bn.pid
            $open*** --daemon --writepid $piddir/$bn.pid --config $c --cd $work
            if [ $? = 0 ]; then
                successes=1
            else
                errors=1
            fi
        done
        if [ $errors = 1 ]; then
            failure; echo
        else
            success; echo
        fi
        if [ $successes = 1 ]; then
            touch $lock
        fi
        ;;
  stop)
        echo -n $"Shutting down open***: "
        for pidf in `/bin/ls $piddir/*.pid 2>/dev/null`; do
          if [ -s $pidf ]; then
            kill `cat $pidf` >/dev/null 2>&1
          fi
          rm -f $pidf
        done
        success; echo
        rm -f $lock
        ;;
  restart)
        $0 stop
        sleep 2
        $0 start
        ;;
  reload)
        if [ -f $lock ]; then
            for pidf in `/bin/ls $piddir/*.pid 2>/dev/null`; do
                if [ -s $pidf ]; then
                    kill -HUP `cat $pidf` >/dev/null 2>&1
                fi
            done
        else
            echo "open***: service not started"
            exit 1
        fi
        ;;
  reopen)
        if [ -f $lock ]; then
            for pidf in `/bin/ls $piddir/*.pid 2>/dev/null`; do
                if [ -s $pidf ]; then
                    kill -USR1 `cat $pidf` >/dev/null 2>&1
                fi
            done
        else
            echo "open***: service not started"
            exit 1
        fi
        ;;
  condrestart)
        if [ -f $lock ]; then
            $0 stop
            # avoid race
            sleep 2
            $0 start
        fi
        ;;
  status)
        if [ -f $lock ]; then
            for pidf in `/bin/ls $piddir/*.pid 2>/dev/null`; do
                if [ -s $pidf ]; then
                    kill -USR2 `cat $pidf` >/dev/null 2>&1
                fi
            done
            echo "Status written to /var/log/messages"
        else
            echo "open***: service not started"
            exit 1
        fi
        ;;
  *)
        echo "Usage: open*** {start|stop|restart|condrestart|reload|reopen|status}"
        exit 1
esac
exit 0

用inetd或xinetd衍生(instantiate)一個 Open*** daemon
通用服務進程 xinetd 能夠響應遠端節點發送的初始數據報,自動衍生一個 Open*** daemon 。
此 xinetd 配置會使 xinetd 進程監聽 UDP 端口 5000,當流入一個 Open*** session (使用 pre-shared key)的數據報時,xinetd 自動衍生一個 Open*** daemon來處理此 session。注意使用 --inactive 參數會使 Open*** daemon 在發呆10分鐘後超時退出。無論何種原因一旦Open*** daemon 退出,xinetd 服務會重新監聽端口等待新的連接。另外要注意 xinetd 使用 root 權限衍生 Open*** daemon,但隨後(讀取受保護的密鑰文件後) Open*** 會將權限降爲 nobody
可用如下命令生成密鑰(key)文件:
open*** --genkey --secret key
注意每一條新的 Open*** 隧道都有它獨自的端口,同時也有它自己的 xinetd 配置文件。這是因爲Open*** 對每一個潛在的接入者需要特定的信息,包括key文件,TUN/TAP 設備,隧道節點(endpoints),和路由配置。基於這種觀點在 Open*** 的發展中,它從不使用單個配置文件來處理一大批類似的潛在接入者,即它沒有描述接入的模板文件。從Open*** 作爲一個UDP server 實現以來,它不具有TCP server可監聽一個固定端口同時可 fork 一個新的 daemon 來動態處理客戶連接的優點。儘管如此,接入模板的實現已進入預期計劃,只要得到開發者和最終用戶社區的足夠注意和支持,它一定會實現的。
sample-config-files/xinetd-server-config
# An xinetd configuration file for Open***.
#
# This file should be renamed to open*** or something suitably
# descriptive and copied to the /etc/xinetd.d directory.
# xinetd can then be made aware of this file by restarting
# it or sending it a SIGHUP signal.
#
# For each potential incoming client, create a separate version
# of this configuration file on a unique port number.  Also note
# that the key file and ifconfig endpoints should be unique for
# each client.  This configuration assumes that the Open***
# executable and key live in /root/open***.  Change this to fit
# your environment.
service open***_1
{
        type            = UNLISTED
        port            = 5000
        socket_type     = dgram
        protocol        = udp
        wait            = yes
        user            = root
        server          = /root/open***/open***
        server_args     = --inetd --dev tun --ifconfig 10.4.0.2 10.4.0.1 --secret /root/open***/key --inactive 600 --user nobody
}

sample-config-files/xinetd-client-config
# This Open*** config file
# is the client side counterpart
# of xinetd-server-config
dev tun
ifconfig 10.4.0.1 10.4.0.2
remote my-server
port 5000
user nobody
secret /root/open***/key
inactive 600

Copyright (C) 2002-2004 by James Yonan . 此文檔於
GNU Free Documentation License
Version 1.2 協議下發布.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章