环境:
1. Open×××机器 (CentOS6.2 X64)
[root@localhost /]# ifconfig |grep 'inet addr'
          inet addr:192.168.1.89  Bcast:192.168.1.255  Mask:255.255.255.0
          inet addr:192.168.56.105  Bcast:192.168.56.255  Mask:255.255.255.0
          inet addr:127.0.0.1  Mask:255.0.0.0
2. Client机器 (windows)
192.168.56.101

目标:
Client通过***拨号到Open×××,获取IP,能访问内网192.168.1.X网段

安装配置过程:
1.启动并清空iptables规则
# iptables -t NAT -F
# iptables -F
# service iptables save
# service iptables restart
2.关闭SELINUX
# setenforce 0
# vi /etc/sysconfig/selinux
---------------
SELINUX=disabled
---------------
server端:
一.网络设置
1.开启服务器端路由转发功能
# vi /etc/sysctl.conf
---------------------
net.ipv4.ip_forward = 1
---------------------
# sysctl -p
2.设置nat转发:
注:保证×××地址池可路由出外网
# iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
3.设置open***端口通过:
# iptables -A INPUT -p TCP --dport 1194 -j ACCEPT
# iptables -A INPUT -p TCP --dport 7505 -j ACCEPT
# iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
3.时间同步(重要):
# ntpdate asia.pool.ntp.org
 
二.安装依赖库
# yum install -y openssl openssl-devel lzo lzo-devel pam pam-devel automake pkgconfig
 
三.安装open***:
# wget -c http://swupdate.open***.org/community/releases/open***-2.3.0.tar.gz
# tar zxvf open***-2.3.0.tar.gz
# cd open***-2.3.0
# ./configure --prefix=/usr/local/open***
# make && make install
# mkdir -p /etc/open***
复制模板到open***配置目录:
# cp -rf sample /etc/open***/
复制open***配置文件到主目录:
# cp /etc/open***/sample/sample-config-files/server.conf /etc/open***/
# cd ..
 
四.下载easy-rsa:
注:该包用来制作ca证书,服务端证书,客户端证书,open***2.3.0该版本源码不包含easy-rsa,所以需要单独下载安装用来配合open***实现证书生成。
# wget -c https://github.com/Open×××/easy-rsa/archive/master.zip
# wget -c https://github.com/Open×××/easy-rsa/archive/2.2.2.zip        用的是version 2  
# unzip master
# mv easy-rsa-master easy-rsa
# cp -rf easy-rsa /etc/open***
# cd /etc/open***/easy-rsa/easy-rsa/2.0
***变量
# vi vars
修改如下参数
注:在后面生成服务端ca证书时,这里的配置会作为缺省配置
---------------------
export KEY_COUNTRY="CN"
export KEY_PROVINCE="SH"
export KEY_CITY="SH"
export KEY_ORG="Renrui"
export KEY_EMAIL="yangwenhao@renruihr.com"
---------------------
做SSL配置文件软链:
# ln -s openssl-1.0.0.cnf openssl.cnf
修改vars文件可执行并调用
# chmod +x vars
# source ./vars
-----------------
NOTE: If you run ./clean-all, I will be doing a rm -rf on /etc/open***/easy-rsa/easy-rsa/2.0/keys
-----------------
注:也就是如果执行./clean-all,就会清空/etc/open***/easy-rsa/easy-rsa/2.0/keys下所有文件
 
开始配置证书:
1.清空原有证书:
# ./clean-all
注:下面这个命令在第一次安装时可以运行,以后在添加完客户端后慎用,因为这个命令会清除所有已经生成的证书密钥,和上面的提示对应
 
2.生成服务器端ca证书
./build-ca
注:由于之前做过缺省配置,这里一路回车即可
 
3.生成服务器端密钥证书, 后面这个open***.example.com就是服务器名,也可以自定义
./build-key-server ***.1tjob.cn
---------------------------
Generating a 2048 bit RSA private key
...................................................+++
..................................+++
writing new private key to 'open***.example.com.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) [SX]:
Locality Name (eg, city) [Xian]:
Organization Name (eg, company) [example]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname)
 
[open***.example.com]:
Name [EasyRSA]:
Email Address [user01@example.com]:
 
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:123456
An optional company name []:Renrui
Using configuration from /etc/open***/easy-rsa/easy-rsa/2.0/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'CN'
stateOrProvinceName :PRINTABLE:'SX'
localityName :PRINTABLE:'Xian'
organizationName :PRINTABLE:'example'
commonName :PRINTABLE:'open***.example.com'
name :PRINTABLE:'EasyRSA'
emailAddress :IA5STRING:'user01@example.com'
Certificate is to be certified until Jun 10 21:58:49 2023 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
---------------------------
 
4.生成所需客户端证书密钥文件:
# ./build-key client1
# ./build-key client2
注:这里与生成服务端证书配置类似,中间一步提示输入服务端密码,其他按照缺省提示一路回车即可。
 
5.再生成diffie hellman参数,用于增强open***安全性(生成需要漫长等待)
# ./build-dh
 
6.打包keys
# tar zcvf keys.tar.gz keys/
五.配置open*** server:
# vi /etc/open***/server.conf
注:可按照默认模板配置,本例为自定义配置文件:
--------------------------
# 设置监听IP,默认是监听所有IP
;local a.b.c.d
# 设置监听端口,必须要对应的在防火墙里面打开
port 1194
# 设置用TCP还是UDP协议?
;proto tcp
proto udp
# 设置创建tun的路由IP通道,还是创建tap的以太网通道
# 路由IP容易控制,所以推荐使用它;但如果如IPX等必须
# 使用第二层才能通过的通讯,则可以用tap方式,tap也
# 就是以太网桥接
;dev tap
dev tun
# Windows需要给网卡一个名称,这里设置,linux不需要
;dev-node MyTap
# 这里是重点,必须指定SSL/TLS root certificate (ca),
# certificate(cert), and private key (key)
# ca文件是服务端和客户端都必须使用的,但不需要ca.key
# 服务端和客户端指定各自的.crt和.key
# 请注意路径,可以使用以配置文件开始为根的相对路径,
# 也可以使用绝对路径
# 请小心存放.key密钥文件
ca /etc/open***/easy-rsa/easy-rsa/2.0/keys/ca.crt
cert /etc/open***/easy-rsa/easy-rsa/2.0/keys/open***.example.com.crt
key /etc/open***/easy-rsa/easy-rsa/2.0/keys/open***.example.com.key
# This file should be kept secret
 
# 指定Diffie hellman parameters.
dh /etc/open***/easy-rsa/easy-rsa/2.0/keys/dh2048.pem
 
# 配置×××使用的网段,Open×××会自动提供基于该网段的DHCP
# 服务,但不能和任何一方的局域网段重复,保证唯一
server 10.8.0.0 255.255.255.0
 
# 维持一个客户端和virtual IP的对应表,以方便客户端重新
# 连接可以获得同样的IP
ifconfig-pool-persist ipp.txt
 
# 配置为以太网桥模式,但需要使用系统的桥接功能
# 这里不需要使用
;server-bridge 10.8.0.4 255.255.255.0 10.8.0.50 10.8.0.100
 
# 为客户端创建对应的路由,以另其通达公司网内部服务器
# 但记住,公司网内部服务器也需要有可用路由返回到客户端
;push "route 192.168.20.0 255.255.255.0"
push "route 192.168.1.0 255.255.255.0"
 
# 为特定的客户端指定IP或指定路由,该路由通常是客户端后面的
# 内网网段,而不是服务端连接的网段
# ccd是/etc/open***下的目录,其中建有希望限制的客户端Common
# Name为文件名的文件,并通过下面的命令写入固定IP地址
# 例如Common Name为client1,则在/etc/open***/ccd/client1写有:
# ifconfig-push 10.9.0.1 10.9.0.2
;client-config-dir ccd
;route 192.168.40.128 255.255.255.248
 
# 为可以对不同的客户端设置防火墙等权限
# 可以让其自动运行对应脚本,可参考man
;learn-address ./script
 
# 若客户端希望所有的流量都通过×××传输,则可以使用该语句
# 其会自动改变客户端的网关为×××服务器,推荐关闭
# 一旦设置,请小心服务端的DHCP设置问题
;push "redirect-gateway"
 
# 用Open×××的DHCP功能为客户端提供指定的DNS、WINS等
;push "dhcp-option DNS 10.8.0.1"
;push "dhcp-option WINS 10.8.0.1"
 
# 默认客户端之间是不能直接通讯的,除非把下面的语句注释掉
client-to-client
 
# 如果您希望有相同Common Name的客户端都可以登陆
# 也可以注释下面的语句,推荐每个客户端都使用不用的Common Name
# 常用于测试
;duplicate-cn
 
# 设置服务端检测的间隔和超时时间
keepalive 10 120
 
# 下面是一些对安全性增强的措施
# For extra security beyond that provided
# by SSL/TLS, create an "HMAC firewall"
# to help block DoS attacks and UDP port flooding.
#
# Generate with:
# open*** --genkey --secret ta.key
#
# The server and each client must have
# a copy of this key.
# The second parameter should be 0
# on the server and 1 on the clients.
;tls-auth ta.key 0 # This file is secret
 
# Select a cryptographic cipher.
# This config item must be copied to
# the client config file as well.
;cipher BF-CBC # Blowfish (default)
;cipher AES-128-CBC # AES
;cipher DES-EDE3-CBC # Triple-DES
 
# 使用lzo压缩的通讯,服务端和客户端都必须配置
comp-lzo
 
# 设置最大用户数
;max-clients 100
 
# 让Open×××以nobody用户和组来运行(安全)
;user nobody
;group nobody
 
# The persist options will try to avoid
# accessing certain resources on restart
# that may no longer be accessible because
# of the privilege downgrade.
persist-key
persist-tun
 
# 输出短日志,每分钟刷新一次,以显示当前的客户端
status /var/log/open***/open***-status.log
 
# 缺省日志会记录在系统日志中,但也可以导向到其他地方
# 建议调试的使用先不要设置,调试完成后再定义
log /var/log/open***/open***.log
log-append /var/log/open***/open***.log
 
# 设置日志的级别
#
# 0 is silent, except for fatal errors
# 4 is reasonable for general usage
# 5 and 6 can help to debug connection problems
# 9 is extremely verbose
verb 3
 
# Silence repeating messages. At most 20
# sequential messages of the same message
# category will be output to the log.
;mute 20

# 设置客户端用账号密码登陆
#加入script-security消除以下警告,获取来自客户端的账号和密码
script-security 3 system      
# 开启用户密码脚本
auth-user-pass-verify /usr/local/open***/extend/checkpsw.sh via-env
# 取消客户端的证书认证
client-cert-not-required
username-as-common-name
--------------------------
创建日志目录:
# mkdir -p /var/log/open***/
启动open*** server
# /usr/local/open***/sbin/open*** --config /etc/open***/server.conf &
设置开机启动:
#

客户端用户验证登陆
cd  /usr/local/open***/extend
wget http://open***.se/files/other/checkpsw.sh
vi psw-file
client1 trinfo     #账户 密码
## checkpsw.sh
#!/bin/sh
###########################################################
# checkpsw.sh (C) 2004 Mathias Sundman <mathias@open***.se>
#
# This script will authenticate Open××× users against
# a plain text file. The passfile should simply contain
# one row per user with the username first followed by
# one or more space(s) or tab(s) and then the password.

PASSFILE="/usr/local/open***/extend/psw-file"
LOG_FILE="/var/log/open***/open***-password.log"
TIME_STAMP=`date "+%Y-%m-%d %T"`

###########################################################

if [ ! -r "${PASSFILE}" ]; then
  echo "${TIME_STAMP}: Could not open password file \"${PASSFILE}\" for reading." >> ${LOG_FILE}
  exit 1
fi

CORRECT_PASSWORD=`awk '!/^;/&&!/^#/&&$1=="'${username}'"{print $2;exit}' ${PASSFILE}`

if [ "${CORRECT_PASSWORD}" = "" ]; then
  echo "${TIME_STAMP}: User does not exist: username=\"${username}\", password=\"${password}\"." >> ${LOG_FILE}
  exit 1
fi

if [ "${password}" = "${CORRECT_PASSWORD}" ]; then
  echo "${TIME_STAMP}: Successful authentication: username=\"${username}\"." >> ${LOG_FILE}
  exit 0
fi

echo "${TIME_STAMP}: Incorrect password: username=\"${username}\", password=\"${password}\"." >> ${LOG_FILE}
exit 1
~                
##########################################

client端:
六.安装WINDOWS客户端(WIN7 64bit)
1.下载客户端,并默认安装:
http://***tech.googlecode.com/files/open***-2.1.1-gui-1.0.3-install-cn-64bit.zip
 
2.将服务端打包文件解压,并将包内ca.crt、client1.crt、client1.key复制到客户端C:\Program Files\Open×××\config下.
 
3.在C:\Program Files\Open×××\config下创建client.o***文件
内容如下:
-----------------------
# 定义是一个客户端
client
 
# 定义使用路由IP模式,与服务端一致
;dev tap
dev tun
 
# 定义Windows下使用的网卡名称,linux不需要
;dev-node MyTap
 
# 定义使用的协议,与服务端一致
;proto tcp
proto udp
 
# 指定服务端地址和端口,可以用多行指定多台服务器
# 实现负载均衡(从上往下尝试)
remote 192.168.56.105 1194
;remote my-server-2 1194
 
# 若上面配置了多台服务器,让客户端随机连接
;remote-random
 
# 解析服务器域名
# Keep trying indefinitely to resolve the
# host name of the Open××× server. Very useful
# on machines which are not permanently connected
# to the internet such as laptops.
resolv-retry infinite
 
# 客户端不需要绑定端口
# Most clients do not need to bind to
# a specific local port number.
nobind
 
# 也是为了让Open***也nobody运行(安全)
# 注意:Windows不能设置
;user nobody
;group nobody
 
# Try to preserve some state across restarts.
persist-key
persist-tun
# 若客户端通过HTTP Proxy,在这里设置
# 要使用Proxy,不能使用UDP为×××的通讯协议
;http-proxy-retry # retry on connection failures
;http-proxy [proxy server] [proxy port #]
# 无线网络有很多多余的头文件,设置忽略它
;mute-replay-warnings
# 重点,就是指定ca和客户端的证书
ca ca.crt
# cert client1.crt
# key client1.key
# 如果服务端打开了PAM认证模块,客户端需要另其有效
auth-user-pass
# 一些安全措施
# Verify server certificate by checking
# that the certicate has the nsCertType
# field set to "server". This is an
# important precaution to protect against
# a potential attack discussed here:
# http://open***.net/howto.html#mitm
#
# To use this feature, you will need to generate
# your server certificates with the nsCertType
# field set to "server". The build-key-server
# script in the easy-rsa folder will do this.
;ns-cert-type server
 
# If a tls-auth key is used on the server
# then every client must also have the key.
;tls-auth ta.key 1
 
# Select a cryptographic cipher.
# If the cipher option is used on the server
# then you must also specify it here.
;cipher x
 
# 使用lzo压缩,与服务端一致
comp-lzo
 
# Set log file verbosity.
verb 3
# Silence repeating messages
;mute 20
-----------------------
5.连接:
在右下角的open***图标上右击,选择“Connect”,若能正常分配IP,则连接成功。
6.最终测试:
C:\Documents and Settings\Administrator>route print
 wKiom1QbvQeTshGYAAKVeF87640347.jpg


更多文章:
基于用户名/密码认证和流量控制的Open×××系统的实现
http://liaowake.blog.163.com/blog/static/2507510201163163531396/
深入Open×××的配置
http://os.chinaunix.net/a2008/0102/963/000000963340.shtml


Open×××设置访问权限:
一般在iptables中设置。
第一步: #将iptables 的 INPUT 、OUTPUT、FORWORD链的默认规则由ACCEPT变为DROP,即关闭所有端口 #
iptables -P INPUT  DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP

第二步:  #打通了局域网通过此机的Forward的通道,也就是来自瑞聘228的消息转发,可以通过
iptables -A FORWARD -d 192.168.1.228 -j ACCEPT
iptables -A FORWARD -s 192.168.1.228 -j ACCEPT
# for ssh
iptables -A OUTPUT -d 192.168.1.88 -j ACCEPT
iptables -A OUTPUT -s 192.168.1.88 -j ACCEPT
# 放外网IP
iptables -A OUTPUT -d 192.168.56.101 -j ACCEPT
iptables -A OUTPUT -d 192.168.56.101 -j ACCEPT

查看iptables当前的规则:
iptables -L -n
查看iptables当前的nat规则:
iptables -t nat -L

另外一种方式,不管外网地址:
iptables -P INPUT  ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP
iptables -A FORWARD -d 192.168.1.228 -j ACCEPT
iptables -A FORWARD -s 192.168.1.228 -j ACCEPT