Open×××-HOWTO中文版

Open××× HOWTO
介绍
此文档描述一个典型的Home到Office的通信中Open×××的配置。这份HOWTO举了一个完整的配置实例,在man page手册页中有一个更为简单的例子。
此HOWTO文档还有如下格式:

附加的文档
为不同环境下配置Open×××而作。
基本的隧道(Tunnel)类型
Open×××可以创建两种基本的隧道类型:
  • Routed IP tunnels -- 适用于不需广播的点对点IP(point-to-point)通信。比起桥接网络隧道来略显得更有效率些而且更易配置。此HOWTO文档涵盖了Routed IP tunnels。
  • Bridged Ethernet Tunnels(桥接网络隧道) -- 能用于IP协议或非IP协议的隧道。这种类型的隧道更适合于使用广播(broadcast)的应用,比如某些Windows网络游戏。配置起来稍微复杂些。
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包,安装
如果你使用Linux 2.2 或更早版本,下载
。对于Linux 2.4.7及以上版本的用户TUN/TAP 驱动已经捆绑到内核中。Linux 2.4.0 -> 2.4.6 的用户需要留意
文件末尾的注意信息。
现在下载 Open××× 的最新发布版:
使用 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 库需要额外下载并安装;; 其他的库在大多数的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,你需要获得
的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 的更多信息,参考
创建 RSA 证书和密钥
Open××× 有两种安全模式,一种基于使用 RSA 证书和密钥的 SSL/TLS,一种使用预先分享的静态密钥。SSL/TLS + RSA 密钥被证明是一种最安全的选择,静态密钥优势则在于简洁。如果你想使用 RSA 密钥,继续往下读。要使用静态密钥,向前跳到
一节.
我们将使用
openssl 命令创建 RSA 证书和密钥,该命令包含在 OpenSSL 库的发布程序中。
RSA 证书是一种公开密钥,在其中还含有其他安全域,比如说证书持有者的
Common Name
email 地址。Open××× 有能力在进行认证前对这些域进行测试。更多信息参考
中的
--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 密钥长度的很好的文章,参见
    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××× 时都需要输入口令。更多信息参考
中的
--askpass 选项。
如果你对手工管理 RSA 密钥觉得困惑,那要指出一点 Open××× 可以很好的同任何 X509 证书管理工具或服务包括商业化的 CAs 如
or
等协同工作。检索
项目可以查看有哪些同证书/密钥管理工具 配合良好的开源项目。
另外,Open××× 发布版中包含了一组脚本能够简化
在 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(将产生大量细节信息用于调试)。参考
获取更多错误处理信息。
如果测试通过,可以尝试经过隧道 ping 另一端子网中的机器(网关机器除外)来测试路由。基本上
10.0.1.0/24 子网中的任一机器可以访问
10.0.1.0/24 子网中的任意机器,反之亦然。
如果工作正常,恭喜你!如果不正常,你可以查看邮件列表
有没有相似问题。如果问题依旧,可以考虑贴到
open***-users 列表。
Make the ××× DHCP-aware
回想一下,在我们的网络配置中,Home是使用动态 IP,地址可以任意的变化。如果你的客户端(client daemon)使用
dhcpcd ,那写一个适应IP地址任意变化的脚本也是很容易的。这个脚本或许被命名为
/etc/dhcpc/dhcpcd-eth0.exe.
基本上你要作的就是将下面这一行加入脚本,其作用是向 Open*** daemon 发送一个
SIGUSR1
SIGHUP 信号:
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×××的 更多信息,可参考
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.sh
open***-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 . 此文档于
Version 1.2 协议下发布.