Open××× 服务器搭建详解
环境简介:
服务器:CentOS 5.2 客户端:XP sp2
其他软件: open***-2.0.9.tar.gz
open***-2.0.9-gui-1.0.3-install.exe
lzo-2.03.tar.gz
openssl 为CentOS 5.2 自带
NTRadPing.exe radius 测试软件
pam_mysql-0.7RC1.tar.gz
radiusplugin_v2.0c.tar.gz
libgcrypt-1.2.4.tar.gz
libgpg-error-1.5.tar.bz2
所有测试都是在 VMware Workstation 5.5.1 上完成
(一) 搭建Open××× Server 路由模式
目的:搭建一台 Open××× Server 使出差的员工也可以方便的访问到公司局域网中的共享资料。
网络环境:
Open××× Server 基本设定:连接方式采用路由方式,认证方式采用证书认证,虚拟设备使用tun(比tap更高效)
1. 安装 CentOS
这一步我就不详写了
注意:关闭SELinux ,iptables
2. 安装 Open×××
a) 检测openssl 是否已安装。(一般系统已自带)
[root@localhost ~]# Whereis openssl
如果你的系统没有OpenSSL库,你需要下载和安装它。
b) 安装 lzo
如果你想使用×××连接的压缩特性,或者你想将Open×××安装为一个RPM包,安装LZO Library。
下载: http://www.oberhumer.com/opensource/lzo/download/lzo-2.03.tar.gz
解压到/root/Scripts 目录中,后面所有的软件到存放到这个目录
gzip –cd lzo-2.03.tar.gz | tar –xvf -
make
make install
如果你使用Linux 2.2 或更早版本,下载TUN/TAP driver。对于Linux 2.4.7及以上版本的用户TUN/TAP 驱动已经捆绑到内核中。Linux 2.4.0 -> 2.4.6 的用户需要留意INSTALL文件末尾的注意信息。
c) tarball 安装Open×××
现在下载 Open××× 的最新发布版: http://open***.net/release/open***-2.0.9.tar.gz
解压gzip -dc open***-2.0.9.tar.gz | tar xvf -
cd open***-2.0.9
./configure
make
make install
如果你未下载 LZO Library ,将--disable-lzo 加入到 configure 命令中。也可以启用其他的选型,比如pthread (./configure --enable-pthread) 用来提高 SSL/TLS 动态密钥交换的响应速度。命令
./configure --help
将显示所有的配置选型。
d) 配置 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
3. 配置 Open×××
a)生成证书 Key
设置环境变量
[root@open*** ~]# vi /root/.bash_profile 追加如下内容(依据情况改变相应值)
D=/root/Scripts/open***-2.0.9/easy-rsa
KEY_CONFIG=$D/openssl.cnf
KEY_DIR=$D/keys
KEY_SIZE=1024
KEY_COUNTRY=CN
KEY_PROVINCE=GD
KEY_CITY=DG
KEY_ORG="ld"
KEY_EMAIL=" colin_xia@luckydragongroup.com"
export KEY_CONFIG KEY_DIR KEY_SIZE KEY_COUNTRY KEY_PROVINCE KEY_CITY KEY_ORG KEY_EMAIL D
同时把以上内容直接粘贴到控制台。
[root@open*** ~]# echo $D 可以看到变量已生效
[root@localhost local]# cd /root/Scripts/open***-2.0.9/easy-rsa/
初始化 PKI
Build:
代码:
./clean-all
./build-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) [DG]:
Organization Name (eg, company) [ld]:
Organizational Unit Name (eg, section) []:it
Common Name (eg, your name or your server's hostname) []:colin
Email Address [colin_xia@luckydragongroup.com]:
# 建立 server key 代码: 代码:
./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) [DG]:
Organization Name (eg, company) [ld]:
Organizational Unit Name (eg, section) []:it
Common Name (eg, your name or your server's hostname) []:server
Email Address [colin_xia@luckydragongroup.com]:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /root/Scripts/open***-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:'DG'
organizationName :PRINTABLE:'ld'
organizationalUnitName:PRINTABLE:'it'
commonName :PRINTABLE:'server'
emailAddress :IA5STRING:'colin_xia@luckydragongroup.com'
Certificate is to be certified until Nov 6 18:18:13 2018 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
#生成客户端 key
代码:
Generating a 1024 bit RSA private key
......++++++
...........................................................++++++
writing new private key to 'client1.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) [DG]:
Organization Name (eg, company) [ld]:
Organizational Unit Name (eg, section) []:it
Common Name (eg, your name or your server's hostname) []:client1 #重要: 每个不同的 client 生成的证书, 名字必须不同.
Email Address [colin_xia@luckydragongroup.com]:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /root/Scripts/open***-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:'DG'
organizationName :PRINTABLE:'ld'
organizationalUnitName:PRINTABLE:'it'
commonName :PRINTABLE:'client1'
emailAddress :IA5STRING:'colin_xia@luckydragongroup.com'
Certificate is to be certified until Nov 6 18:18:36 2018 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
依次类推生成其他客户端证书/key
代码:
./build-key client2
./build-key client3
注意在进入 Common Name (eg, your name or your server's hostname) []: 的输入时, 每个证书输入的名字必须不同.
build:  代码:
创建Diffie Hellman 参数。Diffie Hellman 用于增强安全性,在Open×××是必须的:
./build-dh
生成 ta.key
open*** --genkey --secret ta.key
将 keys 下的所有文件打包下载到本地(除ca 的key,这个文件要单独保存)
b)创建Open××× 服务器配置文件
vi /usr/local/etc/server.conf
port 2194
proto udp
dev tun
server 10.9.0.0 255.255.255.0
push "route 172.18.2.0 255.255.255.0"
push "dhcp-option DNS 172.18.2.23"
push "dhcp-option DNS 202.96.128.86"
ifconfig-pool-persist /usr/local/etc/ipp.txt
ca /usr/local/etc/keys/ca.crt
cert /usr/local/etc/keys/server.crt
key /usr/local/etc/keys/server.key
dh /usr/local/etc/keys/dh1024.pem
tls-auth /usr/local/etc/keys/ta.key 0
keepalive 10 120
comp-lzo
status /var/log/open***-status.log
verb 4
persist-key
persist-tun
按照配置文件所设置的, copy 相应的.key .pem .crt文件至 /usr/local/etc/keys
c)启动Open×××
/usr/local/sbin/open*** --config /usr/local/etc/server.conf
检查服务是否启动
lsof -i :2194
等调试结束后以后台进程的方式启动open***
/usr/local/sbin/open*** --daemon --config /usr/local/etc/server.conf
并把这一句加入到 /etc/rc.local 中
4. 配置Open××× Server防火墙
配置的关键是允许 tun tap 连入,对从 Open××× 客户端来到公司局域网的流量做NAT
如下(参考配置,实际配置要对应实际情况更改如测试时可先对 tun tap 全部允许,成功后再做限制。还有注意NAT的配置)
Vi /etc/sysconfig/iptables
# Generated by iptables-save v1.3.5 on Tue Sep 30 21:34:16 2008
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [42:4060]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
#设备tap(交换)和tun(路由) ,tap是二层设备,支持链路层协议。#tun是ip层的点对点协议,限制稍微多一些,一般是使用tun
从 tun+虚拟网卡入,目标ip为 172.18.2.32 协议 tpc 端口 80 或 83 动作允许
-A RH-Firewall-1-INPUT -d 172.18.2.32 -i tun+ -p tcp -m tcp --dport 80:83 -j ACCEPT
-A RH-Firewall-1-INPUT -d 172.18.2.32 -i tap+ -p tcp -m tcp --dport 80:83 -j ACCEPT
-A RH-Firewall-1-INPUT -d 172.18.2.23 -i tun+ -p udp -m udp --dport 53 -j ACCEPT
-A RH-Firewall-1-INPUT -d 172.18.2.23 -i tap+ -p udp -m udp --dport 53 -j ACCEPT
-A RH-Firewall-1-INPUT -d 172.18.2.23 -i tun+ -p tcp -m tcp --dport 53 -j ACCEPT
-A RH-Firewall-1-INPUT -d 172.18.2.23 -i tap+ -p tcp -m tcp --dport 53 -j ACCEPT
-A RH-Firewall-1-INPUT -s 10.9.0.132 -d 172.18.2.24 -j ACCEPT
-A RH-Firewall-1-INPUT -s 10.9.0.131 -j REJECT --reject-with icmp-port-unreachable
源ip 为 10.0.0.131 拒绝
#-A RH-Firewall-1-INPUT -s 10.9.0.130 -d 172.18.2.0/255.255.0.0 -j ACCEPT
-A RH-Firewall-1-INPUT -s 10.9.0.130 -d 172.18.2.41 -j ACCEPT
-A RH-Firewall-1-INPUT -s 10.9.0.130 -d 172.18.2.40 -j ACCEPT
-A RH-Firewall-1-INPUT -i eth1 -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
允许从 eth1 网卡访问 ssh 服务
-A RH-Firewall-1-INPUT -p udp -m udp --dport 2194 -j ACCEPT
允许 *** 客户端连接服务器的 *** 服务端口
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Tue Sep 30 21:34:16 2008
# Generated by iptables-save v1.3.5 on Tue Sep 30 21:34:16 2008
*nat
:PREROUTING ACCEPT [3:518]
:POSTROUTING ACCEPT [1:92]
:OUTPUT ACCEPT [1:92]
-A POSTROUTING -s 10.9.0.0/255.255.255.0 -o eth1 -j SNAT --to-source 172.18.2.30
源地址为 10.9.0.0/255.255.255.0 从 eth1 出口的数据报都 snat 为 172.18.2.30
COMMIT
# Completed on Tue Sep 30 21:34:16 2008
配置iptables 配置文件后,启用配置:
iptables-restore < /etc/sysconfig/iptables
ok 至此 Open××× 服务器配置完毕。
5. 配置 Open××× windows 客户端
a)安装 open***-2.0.9-gui-1.0.3-install.exe
编辑安装目录config 文件中的 client.o*** 文件
内容如下:
client
dev tun
proto udp
remote 192.168.80.129 2194
persist-key
persist-tun
ca ca.crt
cert client1.crt
key client1.key
ns-cert-type server
comp-lzo
verb 3
;redirect-gateway def1
tls-auth ta.key 1
安照配置文件 cp 相应的 .key .crt .pem 文件到 config 文件夹
运行open*** 客户端,并从windows客户机ping 公司局域网pc 172.18.2.202
再 tracert 和 pathping 一下,确认数据流向
OK 实验成功
6. 再做一个小测试 吊销客户端证书
root@localhost ~]# cd Scripts/open***-2.0.9/easy-rsa/
[root@localhost easy-rsa]# ./revoke-full client1 吊销client1的证书
这条命令执行完成之后, 会在 keys 目录下面, 生成一个 crl.pem 文件,这个文件中包含了吊销证书的名单。成功注销某个证书之后,可以打开 keys/index.txt 文件,可以看到被注销的证书前面,已标记为R.
a. 复制easy-rsa 目录下keys目录中的 crl.pem 到/usr/local/etc/keys 目录中
b. 确保 server.conf 中包含这样一句
crl-verify /usr/local/etc/keys/crl.pem
c. 重新启动open*** 。并测试
Client 连接失败测试成功
7.使用 tap 设备的路由模式
把服务器和客户端配置文件中 dev tun 改为 dev tap 即可
关于使用tap 和 tun 设备的区别,见附录 tun 和 tap 区别。
(二) 搭建Open××× Server 桥接模式
还是(一)的网络环境
目的:客户端还是连接到公司局域网中,但出于一些目的必须使用桥接模式。
如客户端要获得公司局域网ip,某些应用只能使用桥接模式,节省ip。
不管什么原因,反正就是必须使用桥接模式
Open××× Server 基本设定:连接方式采用桥接,认证方式采用证书认证,虚拟设备使用tap
1. 将Open××× 服务器的LAN 网卡和虚拟网卡桥接
关闭Open××× 服务 killall open***
a) 确认你已经安装了bridge-utils软件包。
可以 vi /root/install.log 或rpm –qa ,没有安装可以去安装光盘找或者直接yum安装
b) 编辑下面的bridge-start脚本。依照你要桥接的物理以太网接口设置br, tap, eth, eth_ip,eth_netmask和eth_broadcast参数。确保使用的接口是私有的且它连接的局域网由防火墙保护其到internet的连接。可以使用ifconfig命令获得要填入bridege-start参数的网络接口的信息
c) 这个脚本可以从
d) http://open***.net/index.php/documentation/miscellaneous/ethernet-bridging.html#linuxscript获得,或者 open*** 的模版文件目录中也有
e) 运行bridge-start脚本。它将创建一个永久( 服务器重起前 )的tap0接口并将它和活跃的以太网接口桥接。
f) 把这个脚本也加入到 /etc/rc.local
2. 编辑服务器配置文件
a) 在 “(一)”步骤地服务器配置文件基础上
i. 更改 dev tun 为 dev tap0
ii. 注释 server 开头的行
iii. 添加如下行
iv. 网桥ip 分给*** 客户端的ip范围server-bridge 172.18.2.30 255.255.255.0 172.18.2.128 172.18.2.254
v. push "route 172.18.2.0 255.255.255.0" 这句也可以注释掉,当然只要知道这句是push 一条路由给 *** client 就可以灵活掌握。
vi.
3. 设置防火墙使数据包在新建的tap0 和 br0 借口上自由传送
vi /etc/sysconfig/iptables
添加如下几条
-A RH-Firewall-1-INPUT -i tap0 -j ACCEPT
-A RH-Firewall-1-INPUT -i br0 -j ACCEPT
那条 NAT 的规则也可以去掉。
开启open***
/usr/local/sbin/open*** --daemon --config /usr/local/etc/server.conf
从 winxp client 连接到服务器
测试 ok ipconfig /all tracert pathping
Open××× 服务器启动和停止
运行 bridge-start 运行 open*** 停止 open*** 运行 bridge-stop
Ok Open××× 桥接设置完毕
(三) 搭建Open××× Server 路由模式 + 口令认证+ MYSQL
还是(一)的网络环境
目的:客户端还是连接到公司局域网中,但为了用户管理方便,认证数据从mysql 数据库中提取。
Open××× Server 基本设定:连接方式采用路由,认证方式采用mysql认证,虚拟设备使用tun
1. 首先检查pam-devel包是否安装,否则从系统盘安装改软件包
a) rpm –qa | grep pam
2.检查Mysql是否安装,确认mysql-devel包已经安装,否则从系统盘安装改软件包
rpm –qa | grep msql
mysql-5.0.45-7.el5
mysql-devel-5.0.45-7.el5
mysql-server-5.0.45-7.el5
注:从系统盘安装改软件包时有一系列的依赖问题,我晕
可以把系统盘设置为yum源,使用yum安装这样依赖问题就会自动解决
3.我们安装pam_mysql使用MySQL数据库存储用户数据,其它数据库可以找相应的PAM验证模块(我是在cu下载的 pam_mysql-0.7RC1.tar.gz)
[root@localhost ~]# gzip -cd pam_mysql-0.7RC1.tar.gz | tar xvf –
[root@localhost ~]# cd pam_mysql-0.7RC1
[root@localhost pam_mysql-0.7RC1]# ./configure
[root@localhost pam_mysql-0.7RC1]# make
[root@localhost pam_mysql-0.7RC1]# cp .libs/pam_mysql.so /lib/security/
4. 配置 mysql 数据库和 pam
Server mysqld start
使用 chkconfig 命令让 mysql 数据库,开机自启动
配置数据库
以管理员身份登录数据库:
mysql>; create database ***;
mysql>; GRANT ALL ON ***.* TO ***@localhost IDENTIFIED BY '***123';
mysql>; flush privileges;
mysql>; use ***;
mysql>; CREATE TABLE ***user (
->; name char(20) NOT NULL,
->; password char(128) default NULL,
->; active int(10) NOT NULL DEFAULT 1,
->; PRIMARY KEY (name)
->; );
mysql>; insert into ***user (name,password) values('elm',‘elm’);
#创建***用户,对***这个database有所有操作权限,密码为***123
#active不为1,无权使用×××
#增加用户用户名:elm 密码:elm
配置pam_mysql模块
创建/etc/pam.d/open***文件,文件内容如下:
===================CUT Here================
auth sufficient pam_mysql.so user=*** passwd=***123 host=localhost db=*** \
table=***user usercolumn=name passwdcolumn=password \
where=active=1 sqllog=0 crypt=0
account required pam_mysql.so user=*** passwd=***123 host=localhost db=*** \
table=***user usercolumn=name passwdcolumn=password \
where=active=1 sqllog=0 crypt=0
==================Cut Here=================
crypt(0) -- Used to decide to use MySQL's PASSWORD() function or crypt()
0 = No encryption. Passwords in database in plaintext. NOT recommended!
1 = Use crypt
2 = Use MySQL PASSWORD() function
下面可以测试pam_mysql是否工作正常,先检查saslauthd是否安装:
[root@localhost pam_mysql-0.7RC1]# rpm -qa | grep sasl
cyrus-sasl-plain-2.1.22-4
cyrus-sasl-devel-2.1.22-4
cyrus-sasl-2.1.22-4
cyrus-sasl-lib-2.1.22-4
有cyrus-sasl-2.1.22-4应该就可以了,如果没有请安装相应的软件包,不安装也行,可以通过其它方法测试
[root@*** ~]# saslauthd -a pam
把这句加入到 /etc/rc.local 记得写全路径用 whereis 或 locate 找
[root@*** ~]# testsaslauthd -u elm -p elm -s open***
0: OK "Success."
恭喜,pam_mysql工作正常了,下面可以开始配置Open×××服务器了。
这里我第一次测试时失败了
编辑 /etc/pam.d/open***
两句最后都加上
verbose=1 详细日志
[root@localhost pam_mysql-0.7RC1]# ls -ltr /var/log
看哪个日志文件被更新了
再开两个窗口监视这两个文件
[root@localhost pam_mysql-0.7RC1]# tail –f /var/log/messages
[root@localhost pam_mysql-0.7RC1]# tail -f /var/log/secure
重新做一次 saslauthd 的启动和 testsaslauthd
日志也没有看到明显错误
最后才记起来
Mysql 的 password 函数因为mysql 的加密函数和pam_mysql-0.7RC1 的加密函数不相同。
crypt (plain)
The method to encrypt the user's password:
0 (or "plain") = No encryption. Passwords stored in plaintext.
HIGHLY DISCOURAGED.
1 (or "Y") = Use crypt(3) function.
2 (or "mysql") = Use MySQL PASSWORD() function. It is possible
that the encryption function used by PAM-MySQL
is different from that of the MySQL server, as
PAM-MySQL uses the function defined in MySQL's
C-client API instead of using PASSWORD() SQL function
in the query.
3 (or "md5") = Use plain hex MD5.
4 (or "sha1") = Use plain hex SHA1.
于是把crypt 设置为0 ,新建一个密码不加密的帐户。再测试就通过了
5. 生成 open***-auth-pam.so
[root@localhost etc]# cd /root/Scripts/open***-2.0.9/plugin/auth-pam/
[root@localhost auth-pam]# make
[root@localhost auth-pam]# cp open***-auth-pam.so /usr/local/etc/lib/
6.配置服务器配置文件, 在(一)的基础上
添加如下几行:
#说明使用的插件,open***为插件的参数,使用pam的servicesname
plugin /usr/local/etc/lib/open***-auth-pam.so open***
#不请求客户的CA证书,使用User/Pass验证
client-cert-not-required
#使用客户提供的UserName作为Common Name
username-as-common-name
7.配置客户端配置文件
注释掉
;cert client1.crt
;key client1.key
增加
#询问用户名和密码
auth-user-pass
使用客户端连接服务器 测试 ok
(四) 搭建Open××× Server 路由模式 + 口令认证+TEXT/POP3
还是(一)的网络环境
目的:客户端还是连接到公司局域网中,但为了用户管理方便,认证数据从TEXT 数据库中提取。
Open××× Server 基本设定:连接方式采用路由,认证方式采用TEXT/POP3认证,虚拟设备使用tun
1. 下载TEXT认证脚本 checkpsw.sh ,并且复制到 /usr/local/etc/ 目录中同时chmod u+x 。
http://open***.se/files/other/
注意: 1.脚本保存到 windows 中再上传导 linux 有问题,最好在那个目录新建一个同名文件再从控制台粘贴进去。
2.脚本的开始不是 #! 要改正。
2.配置服务器配置文件, 在(一)的基础上
添加如下几行:
# auth-user-pass-verify cmd method: Query client for username/password and
# run script cmd to verify. If method='via-env', pass
# user/pass via environment, if method='via-file', pass
# user/pass via temporary file.
auth-user-pass-verify /usr/local/etc/checkpsw.sh via-env
#不请求客户的CA证书,使用User/Pass验证
client-cert-not-required
#使用客户提供的UserName作为Common Name
username-as-common-name
3..配置客户端配置文件
注释掉
;cert client1.crt
;key client1.key
增加
#询问用户名和密码
auth-user-pass
4.更改 checkpsw.sh 中的PASSFILE 变量为。
PASSFILE="/usr/local/etc/psw-file"
5. 创建 /usr/local/etc/psw-file 内容如下:
格式:用户名Tab密码
User1 pass
User2 pass
注:实验成功后我自己仿照 checkpsw.sh 用 perl 重写了一遍(目录中的checkpsw.pl),也可以使用。
6.同样的原理我们还可以使用POP3 认证(^_^ 其他的当然也可以)
脚本见目录中的 popauth.pl
(五) 搭建Open××× Server 路由模式 + 口令认证+RADIUS
网络环境:在(一)的基础上添加一台 win2003 服务器 ip 为 192.168.80.130
^_^ 不好意思,我把服务器给放到了公网上了。不过还好是测试。
目的:客户端还是连接到公司局域网中,但为了用户管理方便,认证数据从radius 数据库中提取。
Open××× Server 基本设定:连接方式采用路由,认证方式采用radius认证,虚拟设备使用tun
1. 搭建 Radius 服务器
见附录 搭建 win2003 下的IAS 服务
2. 配置 radiusplugin
1.radiusplugin_v2.0.tar.gz: 可以编译得到radiusplugin.so
http://www.nongnu.org/radiusplugin/下载
2.libgcrypt 支持库: 可以编译得到/usr/lib/libgcrypt.so.11
ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-1.2.4.tar.gz 下载
3.libgpg-error 支持库: 可以编译得到/usr/local/lib/libgpg-error.so.0
ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-1.5.tar.gz 下载
简单的编译以上3 个支持库,configure;make;make install。
我们要用到radiusplugin.so,其他是radiusplugin.so 的支持库。
好了如果能够得到radiusplugin.so,已经成功了80%,其他的就是配置了。
把radiusplugin.so 拷贝到/usr/local/etc/lib 下,并配置其配置文件radiusplugin.conf
内容如下:
# The NAS identifier which is sent to the RADIUS server
NAS-Identifier=Open***
# The service type which is sent to the RADIUS server
Service-Type=5
# The framed protocol which is sent to the RADIUS server
Framed-Protocol=1
# The NAS port type which is sent to the RADIUS server
NAS-Port-Type=5
# 这是运行open*** 服务器的ip,作为radius 客户端
NAS-IP-Address=192.168.80.129
#这里指明open*** 的配置位置
Open×××Config=/usr/local/etc/server.conf
# 这里定义 radius server 参数可以超过1 个作为备份
server
{
# The UDP port for radius accounting.
acctport=1813
# The UDP port for radius authentication.
authport=1812
# 这是我radius 服务器的ip,并添加了用户。
name=192.168.80.130
# How many times should the plugin send the if there is no response?
retry=1
# How long should the plugin wait for a response?
wait=1
# The shared secret.共享密钥,在winradius 里配置,设置-系统-NAS 密钥
sharedsecret=123456
}
3.配置服务器配置文件, 在(一)的基础上
添加如下几行:
#说明使用的插件
plugin /usr/local/etc/lib/radiusplugin.so /usr/local/etc/radius.conf
#不请求客户的CA证书,使用User/Pass验证
client-cert-not-required
#使用客户提供的UserName作为Common Name
username-as-common-name
4.配置客户端配置文件
注释掉
;cert client1.crt
;key client1.key
增加
#询问用户名和密码
auth-user-pass
使用客户端连接服务器 测试 ok
(六) 搭建Open××× Site to Site
目的:公司局域网 LAN B 和在其它城市公司分部网络 LAN A 要互相连通,共享彼此的资源。
Open××× Server 基本设定:连接方式采用路由,认证方式采用证书认证,虚拟设备使用tun
网络环境:
1. *** client 和 *** server两台设备都将作为各自网络的GW,系统为 CentOS 5.2 上面安装 Open××× 软件。并开启 ip 转发,防火墙已设置妥当。
2. 配置open*** server 在(一) 的基础上:
添加:
route 192.168.90.0 255.255.255.0
client-config-dir /usr/local/etc/ccd
配置要点:
使用 tun 点对点的虚拟连接(路由)
dev tun
在本机添加一条到 192.168.90.0 255.255.255.0 via 就是对端(10.9.0.2)
route 192.168.90.0 255.255.255.0
push一条路由到客户端,告诉客户机 172.18.2.0 255.255.255.0 在它的对端(10.9.0.5)
push "route 172.18.2.0 255.255.255.0"
为*** clien 设置单独配置文件,内容是:iroute 192.168.90.0 255.255.255.0
client-config-dir /usr/local/etc/ccd
3. 配置 ××× Client
同(一)
4.使用 ping pathping tracert 等命令测试, LAN A 和 LAN B 两个网络连通 ok
至此 Open××× Site to Site 配置完成。
(七) Open ××× 其它配置选项
1. 服务器选项
a) #定义最大连接数;max-clients 100
b) #记录日志,每次重新启动open***后删除原有的log信息log /var/log/open***.log #和log一致,每次重新启动open***后保留原有的log信息,新信息追加到文件最后;log-append open***.log
c) #如果可以让××× Client之间相互访问直接通过open***程序转发, #不用发送到tun或者tap设备后重新转发,优化Client to Client的访问效率client-to-client
d) #使Client的默认网关指向×××,让Client的所有Traffic都通过×××走;push "redirect-gateway"
e) 在*** client 连接或退出时,执行脚本。可以用于生成用户访问日志。
client-connect /usr/local/etc/connect client-disconnect /usr/local/etc/disconnect
脚本 见附录
f)#定义运行open***的用户user nobody group nobody
2. 客户端选项
a)可以有多个*** 服务器做负载均衡,然后客户端配置这样写
remote 61.1.1.2 1194
remote 22.1.1.2 1194
# 随机选择一个Server连接,否则按照顺序从上到下依次连接
;remote-random
b)如果 remote 后接的是域名
# 始终重新解析Server的IP地址(如果remote后面跟的是域名), # 保证Server IP地址是动态的使用DDNS动态更新DNS后,Client在自动重新连接时重新解析Server的IP地址# 这样无需人为重新启动,即可重新接入××× resolv-retry infinite
C)# 如果你使用HTTP代理连接××× Server,把Proxy的IP地址和端口写到下面# 如果代理需要验证,使用http-proxy server port [authfile] [auth-method] # 其中authfile是一个2行的文本文件,用户名和密码各占一行,auth-method可以省略,详细信息查看Manual ;http-proxy-retry # retry on connection failures ;http-proxy [proxy server] [proxy port #]
(八) Open××× 配置参数详解
# #号和;号开头的都是注释
# 设置监听IP,默认是监听所有IP
#local 116.6.45.23
#Open*** 服务器监听端口
port 2194
# 设置用TCP还是UDP协议?
;proto tcp
proto udp
# 设置创建tun的路由IP通道,还是创建tap的以太网通道
# 路由IP容易控制,所以推荐使用它;但如果如IPX等必须
# 使用第二层才能通过的通讯,则可以用tap方式,tap也
# 就是以太网桥接
dev tun
# 配置×××使用的网段,Open×××会自动提供基于该网段的DHCP
# 服务,但不能和任何一方的局域网段重复,保证唯一
# server端ip默认会设为.1的地址。
server 10.9.0.0 255.255.255.0
# 为客户端创建对应的路由,以另其通达公司网内部服务器
# 但记住,公司网内部服务器也需要有可用路由返回到客户端
push "route 172.18.2.0 255.255.255.0"
# 维持一个客户端和virtual IP的对应表,以方便客户端重新
# 连接可以获得同样的IP
ifconfig-pool-persist /usr/local/etc/ipp.txt
# 用Open×××的DHCP功能为客户端提供指定的DNS、WINS等
push "dhcp-option DNS 172.18.2.23"
push "dhcp-option DNS 202.96.128.86"
# 这里是重点,必须指定SSL/TLS root certificate (ca),
# certificate(cert), and private key (key)
# ca文件是服务端和客户端都必须使用的,但不需要ca.key
# 服务端和客户端指定各自的.crt和.key
# 请注意路径,可以使用以配置文件开始为根的相对路径,
# 也可以使用绝对路径
# 请小心存放.key密钥文件
ca /usr/local/etc/keys/ca.crt
cert /usr/local/etc/keys/server.crt
key /usr/local/etc/keys/server.key
# 指定Diffie hellman parameters.
dh /usr/local/etc/keys/dh1024.pem
#用于吊销客户证书
crl-verify /usr/local/etc/keys/***crl.pem
#增强安全性
# 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 /usr/local/etc/keys/ta.key 0
# 设置服务端检测的间隔和超时时间每10秒ping一次,如果120秒没有回应则认为对方已经down
keepalive 10 120
# 使用lzo压缩的通讯,服务端和客户端都必须配置
comp-lzo
# 输出短日志,每分钟刷新一次,以显示当前的客户端
status /var/log/open***-status.log
#设置日志要记录的级别。
#0只记录错误信息。
#4能记录普通的信息。
#5和6在连接出现问题时能帮助调试
#9是极端的,所有信息都会显示,甚至连包头等信息都显示(像tcpdump)
verb 4
#相同信息的数量,如果连续出现20条相同的信息,将不记录到日志中。
mute 20
# 让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
################### 其他参数 ######################################
# 为特定的客户端指定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 /usr/local/etc/ccd
# 若客户端希望所有的流量都通过×××传输,则可以使用该语句
# 其会自动改变客户端的网关为×××服务器,推荐关闭
# 一旦设置,请小心服务端的DHCP设置问题
;push "redirect-gateway"
# 如果您希望有相同Common Name的客户端都可以登陆
# 也可以注释下面的语句,推荐每个客户端都使用不用的Common Name
# 常用于测试
;duplicate-cn
# 设置最大用户数
#max-clients 3
# 打开管理界面,可以定义监控的IP和端口
management localhost 7505
# 缺省日志会记录在系统日志中,但也可以导向到其他地方
# 建议调试的使用先不要设置,调试完成后再定义
;log /var/log/open***/open***.log
;log-append /var/log/open***/open***.log
# 配置为以太网桥模式,但需要使用系统的桥接功能
# 这里不需要使用
;server-bridge 10.8.0.4 255.255.255.0 10.8.0.50 10.8.0.100
#记录日志,每次重新启动open***后删除原有的log信息log /var/log/open***.log #和log一致,每次重新启动open***后保留原有的log信息,新信息追加到文件最后;log-append open***.log
#定义运行open***的用户user nobody group nobody
#Run script or shell command cmd to validate client #virtual addresses or routes. 具体查看manual ;learn-address ./script #其它的一些需要PUSH给Client
#用于记录某个Client获得的IP地址,类似于dhcpd.lease文件, #防止open***重新启动后“忘记”Client曾经使用过的IP地址ifconfig-pool-persist ipp.txt #Bridge状态下类似DHCPD的配置,为客户分配地址,由于这里工作在路由模式,所以不使用;server-bridge 10.8.0.4 255.255.255.0 10.8.0.50 10.8.0.100
# 随机选择一个Server连接,否则按照顺序从上到下依次连接;remote-random # 始终重新解析Server的IP地址(如果remote后面跟的是域名), # 保证Server IP地址是动态的使用DDNS动态更新DNS后,Client在自动重新连接时重新解析Server的IP地址# 这样无需人为重新启动,即可重新接入××× resolv-retry infinite
# 在本机不邦定任何端口监听incoming数据,Client无需此操作,除非一对一的×××有必要nobind
# 如果你使用HTTP代理连接××× Server,把Proxy的IP地址和端口写到下面# 如果代理需要验证,使用http-proxy server port [authfile] [auth-method] # 其中authfile是一个2行的文本文件,用户名和密码各占一行,auth-method可以省略,详细信息查看Manual ;http-proxy-retry # retry on connection failures ;http-proxy [proxy server] [proxy port #]
# Server使用build-key-server脚本什成的,在x509 v3扩展中加入了ns-cert-type选项# 防止××× client使用他们的keys + DNS hack欺骗*** client连接他们假冒的××× Server # 因为他们的CA里没有这个扩展ns-cert-type server
a.定义tun为使用路由方式的×××
b.小心处理证书的路径,.key文件要保存好,特别是ca.key。
(ca.key不需要在Open×××中用到,可以另外保存)
注意,每个虚拟tun网卡都是成对的,只有inet addr标识的才是用于×××通讯。并且必须在/30网段
bridge-start
#!/bin/bash ################################# # Set up Ethernet bridge on Linux # Requires: bridge-utils #################################
更改蓝色字体部分即可,桥接后的ip为内网卡ip # Define Bridge Interface br="br0" # Define list of TAP interfaces to be bridged, # for example tap="tap0 tap1 tap2". tap="tap0" # Define physical ethernet interface to be bridged # with TAP interface(s) above. eth="eth1" eth_ip="172.18.2.30" eth_netmask="255.255.255.0" eth_broadcast="172.18.2.255" for t in $tap; do open*** --mktun --dev $t done brctl addbr $br brctl addif $br $eth for t in $tap; do brctl addif $br $t done for t in $tap; do ifconfig $t 0.0.0.0 promisc up done ifconfig $eth 0.0.0.0 promisc up ifconfig $br $eth_ip netmask $eth_netmask broadcast $eth_broadcast
bridge-stop
Bridge stop 脚本(其中内容也是要根据情况更改)
#!/bin/bash #################################### # Tear Down Ethernet bridge on Linux #################################### # Define Bridge Interface br="br0" # Define list of TAP interfaces to be bridged together tap="tap0" ifconfig $br down brctl delbr $br for t in $tap; do open*** --rmtun --dev $t done
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="/etc/open***/psw-file"
LOG_FILE="/var/log/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
#${TIME_STAMP} 是一个参数替换相当于 $TIME_STAMP 的值,也就是 `date "+%Y-%m-%d %T"`
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
checkpsw.pl
#!/usr/bin/perl -w use strict; my $PASSFILE = "/usr/local/etc/psw-file"; my $LOG_FILE = "/var/log/open***-password.log"; my $TIME_STAMP = `date "+%Y-%m-%d %T"`; my $username; my $password; open ("LOG",">>","$LOG_FILE") or die "can't open $LOG_FILE: $!"; open ("PASS","<","$PASSFILE") or die "can't open $PASSFILE"; sub get_***pass{ while(<PASS>){ next if m/^;/; next if m/^#/; ($username,$password) = split(/\s+/,$_); return $password if $username eq $ENV{username}; } } ###############################################################
my $CORRECT_PASSWORD = get_***pass(); unless ( -r $PASSFILE){ print LOG "$TIME_STAMP: Could not open password file \"$PASSFILE\" for reading."; exit 1; } if ( $CORRECT_PASSWORD eq ""){ print LOG "$TIME_STAMP: USER does not exist: username=\"$ENV{username}\",password=\"$ENV{password}\"."; exit 1; } if ( $CORRECT_PASSWORD eq $ENV{password}){ print LOG "$TIME_STAMP: Successful authentication:username=\"$ENV{username}\"."; exit 0; } print LOG "$TIME_STAMP: Incorrect password: username=\"$ENV{username}\",password=\"$ENV{password}\"."; exit 1;
connect
#!/bin/bash
day=`date +%F`
if [ -f /var/log/open***/$day ];then
echo "`date '+%F %H:%M:%S'` User $common_name is logged in" >>/var/log/open***/$day
else
touch /var/log/open***/$day
echo "`date '+%F %H:%M:%S'` User $common_name is logged in" >>/var/log/open***/$day
fi
disconnect
#!/bin/bash
day=`date +%F`
if [ -f /var/log/open***/$day ];then
echo "`date '+%F %H:%M:%S'` User $common_name is logged off" >>/var/log/open***/$day
else
touch /var/log/open***/$day
echo "`date '+%F %H:%M:%S'` User $common_name is logged off" >>/var/log/open***/$day
fi
(一) 搭建Radius 服务器这里使用的是 windows 2003 的IAS
1. 安装 IAS
2. 配置 IAS
A.新建 RADOUS 客户端
名称随便填,客户端的地址就是open***服务器地址
B 新建远程访问策略
授予 TelnetClients 组远程访问权限
重要:点击-〉编辑配置文件
身份验证选项卡 如下配置
Ok 确定之后 radius server 配置完成
接下来测试 radius 服务器
1.在服务器上新建一个用户
用户名:*** 密码:test 加入 TelnetClients 组确保它的“属性”中“拨入”选项卡的“远程访问权限”设置为“通过远程访问策略控制访问”
2.查看服务端口是否开启
Radius 的常用端口
2.Windows pc 上使用软件ntradping 进行测试
提示:你需要为你的pc 在radius 服务器上也新建一个 RADIUS 客户端
在软件左上方中输入认证信息 –〉接着点击下方的 send 按钮
A radius 服务器正常但认证失败(用户没有权限/密码错误等)
B radius 认证成功
至此 raidus 服务器搭建完成
Popauth.pl
#!/usr/bin/perl # Write by ELM # wzk [A|T] wenzk [D|O|T] net # http://www.wenzk.net ## POP3 Auth script for Open××× # Usage: # save this file to /etc/open***/ as popauth.pl # run£º chmod +x /etc/open***/popauth.pl # add the next line to you Open××× config file # auth-user-pass-verify /etc/open***/popauth.pl via-env # restart your Open××× Server use Net::POP3; # POP Server Address $POPHOST = "localhost"; $USERNAME = $ENV{username}; $PASSWORD = $ENV{password}; # Constructors $pop = Net::POP3->new($POPHOST); $pop = Net::POP3->new($POPHOST, Timeout => 60); if ( defined $pop->login($USERNAME, $PASSWORD) ) { $result = 0; } else { $result = 1; } $pop->quit; exit $result;
centos yum 光盘源
2008-09-04 18:42
CentOS 4下Yum安装本地光盘软件 首先 要先挂载光盘,把光盘挂载到media/CentOS/,media/cdrom/,或者media/cdrecorder/这样就不用修改配置文件了。
命令: mount /dev/cdrom /media/cdrom
如果想挂载到其他目录,只要修改下baseurl=file:///自己挂载的目录,就可以了。配置文件在/etc/yum.repos.d/CentOS-Media.repo。
接着 把/etc/yum.repos.d/CentOS-Base.repo改下名,命令如下: QUOTE: #mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
检查下配置文件的有没设置正确,命令如下: QUOTE: # CentOS-Media.repo # # This repo is used to mount the default locations for a CDROM / DVD on# CentOS-4. You can use this repo and yum to install items directly off the # DVD ISO that we release. # # To use this repo, put in your DVD and use it with the other repos too:# yum --enablerepo=c4-media [command] # # or for ONLY the media repo, do this: # # yum --disablerepo=\* --enablerepo=c4-media [command] [c4-media] name=CentOS-$releasever - Media baseurl=file:///media/cdrom/ file:///media/cdrecorder/ gpgcheck=1 enabled=0 gpgkey=file:///usr/share/doc/centos-release-4/RPM-GPG-KEY-centos4
其实配置文件中已经有教怎么做的了,我好像是多此一举了。
最后 就是要安装软件咯,命令如下: yum --disablerepo=\* --enablerepo=c4-media install mysql-server
yum --disablerepo=\* --enablerepo=c4-media install mysql-devel
yum --disablerepo=\* --enablerepo=c4-media install curl
yum --disablerepo=\* --enablerepo=c4-media install php-mysql
yum --disablerepo=\* --enablerepo=c4-media install compat-libstdc++-33
yum --disablerepo=\* --enablerepo=c4-media install libtool
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
yum --disablerepo=\* --enablerepo=c4-media install mysql-server mysql-devel curl php-mysql compat-libstdc++-33 libtool net-snmp php-gd php-snmp perl-DateManip perl-MD5 net-snmp-utils freetype sudo mod_ssl
freeradius+open***+mysql实现 2009-01-15 16:17
分类:技术归档
字号: 大 中 小
一、前言
具体的调用流程是:
win的open***客户端通过 auth-user-pass认证模式(即通过ca.crt ta.key server.crt)到open***服务器,调用插件radiusplugin (/usr/local/open***/radiusplugin.so , /usr/local/open***/radiusplugin.cnf),radiusplugin调用 radiusd(name=127.0.0.1、sharedsecret= testing123和radius的服务端口),通过radiusd的clients.conf实现服务器的本身127.0.0.1密匙模式调用 radiusd,再通过radiusd.conf配置sql方式的认证,再到radiusd的sql.conf(通过rlm_sql_mysql调用)到 mysql数据库
具体的安装是上述调用的逆向过程
二、安装freeradius以及rlm_sql_mysql.so
1、 编译安装
(1)、编译安装freeradius
wget ftp://ftp.freeradius.org:/pub/radius/freeradius-1.1.7.tar.gz
tar zxvf freeradius-1.1.7.tar.gz
cd freeradius-1.1.7
./configure
cp libltdl/ltdl.h src/include/
make
make install
注释:如果没有cp libltdl/ltdl.h src/include/ 在make的时候会有2个错误,应该是路径的问题
(2)、安装rlm_sql_mysql相关
由于我的mysql是编译好的二进制包安装的,所以系统没有rlm_sql_mysql.so这个东西
所以要重新编译出rlm_sql_mysql.so这个东西来。
ln -s /usr/local/mysql/bin/mysql_config /sbin/mysql_config
cd /usr/local/src/freeradius-1.1.7/src/modules/rlm_sql/drivers/rlm_sql_mysql
./configure --with-mysql-dir=/usr/local/mysql --with-mysql-lib-dir=/usr/local/mysql/lib \
--with-mysql-include-dir=/usr/local/mysq/include
make
make install
这里的编译参数是根据每个人的实际情况设定的,这一步的编译要在freeradius编译安装后再做。
vi /etc/ld.so.conf
/usr/local/lib
ldconfig
2、构建radius数据库(建立相关用户和密码)
/usr/local/mysql/bin/mysql –uroot –pXXXX
mysql>create database radius;
mysql>GRANT ALL PRIVILEGES ON radius.* TO radius@localhost IDENTIFIED BY 'AAAA';
mysql>\q
cd /usr/local/src/freeradius-1.1.7
/usr/local/mysql/bin/mysql -uroot -pXXXX radius < ./doc/examples/mysql.sql
3、配置radiusd.conf以及sql.conf
(1)、radiusd.conf配置
vi /usr/local/etc/raddb/radiusd.conf
proxy_requests = no
authorize {
preprocess
chap
mschap
suffix
eap
sql
# pap
# files
}
注释:使用sql,authorize中的file必须被注释掉。
preacct {
preprocess
acct_unique
suffix
# files
}
accounting {
detail
unix
radutmp
sql
}
(2)、sql.conf配置
vi /usr/local/etc/raddb/sql.conf
driver = "rlm_sql_mysql"
server = "localhost"
login = "radius"
password = "AAAA"
radius_db = "radius"
配置NAS信息:
vi /usr/local/etc/raddb/clients.conf
#本地帐号,用于测试
client 127.0.0.1 {
secret = testing123
shortname = localhost
nastype = other
}
注释:
secret 这里是针对client 127.0.0.1通讯密匙
#mysql -u root -p
mysql> use radius;
建立组信息:
mysql> insert into radgroupreply (groupname,attribute,op,value) values ('user','Auth-Type',':=','Local');
mysql> insert into radgroupreply (groupname,attribute,op,value) values ('user','Service-Type',':=','Framed-User');
mysql> insert into radgroupreply (groupname,attribute,op,value) values ('user','Framed-IP-Address',':=','255.255.255.255');
mysql> insert into radgroupreply (groupname,attribute,op,value) values ('user','Framed-IP-Netmask',':=','255.255.255.0');
建立用户信息:
mysql> insert into radcheck (username,attribute,op,value) values ('test','User-Password',':=','test');
mysql> insert into radcheck (username,attribute,op,value) values ('sense','User-Password',':=','123456');
将用户加入组中:
mysql> insert into usergroup (username,groupname) values ('test','user');
注释:
对于 radcheck 这个表attribute的项有好几种设置的,我们设置的是认证的密码模式明码User-Password,也可以设置成加密Crypt-Password,如果是加密模式需要libgcrypt支持。
同时对于表radgroupreply中项attribute,的含义不是太明白:Auth-Type 、 Service-Type 、 Framed-IP-Address、 Framed-IP-Netmask、Acct-Interim-Interval
测试:
radiusd –x &
这个时候控制台会被占用
另开一个控制台进行测试
ln -s /usr/local/bin/radtest /sbin/radtest
/sbin/radtest test test localhost 0 testing123
Sending Access-Request of id 204 to 127.0.0.1 port 1812
User-Name = "test"
User-Password = "test"
NAS-IP-Address = 255.255.255.255
NAS-Port = 0
rad_recv: Access-Accept packet from host 127.0.0.1:1812, id=204, length=38
Service-Type = Framed-User
Framed-IP-Address = 255.255.255.255
Framed-IP-Netmask = 255.255.255.0
/sbin/radtest sense 123456 localhost 0 testing123
Sending Access-Request of id 212 to 127.0.0.1 port 1812
User-Name = "sense"
User-Password = "123456"
NAS-IP-Address = 255.255.255.255
NAS-Port = 0
rad_recv: Access-Accept packet from host 127.0.0.1:1812, id=212, length=20
由于test加入了组所以信息量多一点
以上测试说明freeradius-mysql工作正常!
说明(freeradius\rlm_sql_mysql.so\mysql\)正常!
三、 装Open×××
1、其中我的openssl我是系统自带的,所以不要再次安装
rpm -aq|grep openssl
openssl-devel-0.9.8b-8.3.el5
openssl-0.9.8b-8.3.el5
2、安装open***2.09
cd /usr/local/src
wget http://open***.net/release/open***-2.0.9.tar.gz
tar zxvf open***-2.0.9.tar.gz
cd open***-2.0.9
首先是看一下open***.spec里面对于liblzo1和openssl的版本要求,对照自己的版本看符合要求吗
检查pam-devel包是否安装,否则从系统盘安装改软件包,一般系统安装时都已经安装了
这一部分的pam不一定要安装,因为open***不是直接调用mysql的,如果是open***直接调用mysql需要安装pam。(open***直接通过mysql,跟通过radius调用mysql主要是在计费统计上有很大区别,认证什么的差不多)
rpm -qa | grep pam
pam_passwdqc-1.0.2-1.2.2
pam-0.99.6.2-3.14.el5
pam_pkcs11-0.5.3-23
pam_krb5-2.2.11-1
pam-devel-0.99.6.2-3.14.el5
pam_smb-1.1.7-7.2.1
pam_ccreds-3-5
(1)、lzo
wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.02.tar.gz
tar zxvf lzo-2.02.tar.gz
cd lzo-2.02
./configure
make
make install
这一部分是支持open***的压缩功能
(2)、安装open***
cd open***-2.0.9
./configure --prefix=/usr/local/open*** --with-lzo-headers=/usr/local/include/lzo \
--with-lzo-lib=/usr/local/lib --with-ssl-headers=/usr/include/openssl \
--with-ssl-lib=/usr/lib
make
make install
注释:以上路径请根据自己系统的配置调整
(3)、生成密匙
cd /usr/local/src/open***-2.0.9
cp -rf ./easy-rsa/ /usr/local/open***/
cd /usr/local/open***/easy-rsa/2.0
source ./vars
./clean-all
./build-ca
./build-key-server server
./build-dh
./build-key cl1
cd keys
/usr/local/open***/sbin/open*** --genkey --secret ta.key
cd /usr/local/open***
mkdir ssl
cp -a ./easy-rsa/keys/2.0/ca.crt ./ssl/
cp -a ./easy-rsa/keys/2.0/dh1024.pem ./ssl/
cp -a ./easy-rsa/keys/2.0/ta.key ./ssl/
cp -a ./easy-rsa/keys/2.0/server.crt ./ssl/
cp -a ./easy-rsa/keys/2.0/server.key ./ssl/
3、安装 RadiusPlugin
(1)、安装
cd /usr/local/src/
wget wget http://www.nongnu.org/radiusplugin/radiusplugin_v2.0b_beta2.tar.gz
tar zxvf radiusplugin_v2.0b_beta2.tar.gz
cd radiusplugin_v2.0b_beta2
make
cp /usr/local/src/radiusplugin_v2.0b_beta2/radiusplugin.so /usr/local/open***/
cp /usr/local/src/radiusplugin_v2.0b_beta2/radiusplugin.cnf /usr/local/open***/
vi /usr/local/open***/radiusplugin.cnf
这里2个文件的位置,是自己定义的,根据这个定义的位置,后面相关配置要设定这里路径的
(2)、配置radiusplusin插件的配置文件radiusplugin.cnf
# The NAS identifier which is sent to the RADIUS server
NAS-Identifier=Open***
# The service type which is sent to the RADIUS server
Service-Type=5
# The framed protocol which is sent to the RADIUS server
Framed-Protocol=1
# The NAS port type which is sent to the RADIUS server
NAS-Port-Type=5
# The NAS IP address which is sent to the RADIUS server
NAS-IP-Address=127.0.0.1
# Path to the Open××× configfile. The plugin searches there for
# client-config-dir PATH (searches for the path)
# status FILE (searches for the file, version must be 1)
# client-cert-not-required (if the option is used or not)
# username-as-common-name (if the option is used or not)
Open×××Config=/usr/local/open***/server.conf
# Support for topology option in Open××× 2.1
# If you don't specify anything, option "net30" (default in Open×××) is used.
# You can only use one of the options at the same time.
# If you use topology option "subnet", fill in the right netmask, e.g. from Open××× option "--server NETWORK NETMASK"
#subnet=255.255.255.0
# If you use topology option "p2p", fill in the right network, e.g. from Open××× option "--server NETWORK NETMASK"
#p2p=10.10.0.1
####################### Ich benutze die Default Option
# Allows the plugin to overwrite the client config in client config file directory,
# default is true
overwriteccfiles=true
# Path to a script for vendor specific attributes.
# Leave it out if you don't use an own script.
# vsascript=/root/workspace/radiusplugin_v2.0.5_beta/vsascript.pl
# Path to the pipe for communication with the vsascript.
# Leave it out if you don't use an own script.
# vsanamedpipe=/tmp/vsapipe
# A radius server definition, there could be more than one.
# The priority of the server depends on the order in this file. The first one has the highest priority.
server
{
# The UDP port for radius accounting.
acctport=1813
# The UDP port for radius authentication.
authport=1812
# The name or ip address of the radius server.
name=127.0.0.1
# How many times should the plugin send the if there is no response?
retry=1
# How long should the plugin wait for a response?
wait=1
# The shared secret.
sharedsecret= testing123
}
注释:这里的sharedsecret= testing123跟radiusd的设置相关,注意/usr/local/etc/raddb/clients.conf中的client 127.0.0.1 的设置,(这个clients.conf是调用radius的客户端配置)
client 127.0.0.1 {
secret = testing123
shortname = localhost
nastype = other
}
同时重要的是要在正式应用的时候 同时修改这2个地方的testing123,这个就是radius的密匙
4、配置open***的服务器设置文件server.conf
cp /usr/local/src/open***-2.0.9/sample-config-files/server.conf /usr/local/open***/server.conf
vi /usr/local/open***/server.conf
注释:注意这里的server.conf要与/usr/local/open***/radiusplugin.cnf中Open×××Config的设置一致
这里的open***服务器端可以有多个配置文件,每一个配置等于开启了一个单独的***服 务,但是要单独设置每个服务器端配置文件./build-key-server ser*** 同时不同的客户端./build-key cl1*** 对应于相应 ser****的unit name,同时客户端要拷贝不同的ser***.crt
port 1194
proto udp
# Which device
dev tun
;fast-io
user nobody
group nogroup
persist-tun
persist-key
server 10.14.0.0 255.255.0.0
management 127.0.0.1 7505
float
username-as-common-name
;client-config-dir ccd
client-cert-not-required
client-to-client
#push "redirect-gateway def1"
push "dhcp-option DNS 172.21.41.15"
ping-timer-rem
keepalive 10 120
# Use compression
comp-lzo
# Strong encryption
tls-server
tls-auth ssl/ta.key 0
dh ssl/dh1024.pem
ca ssl/ca.crt
cert ssl/server.crt
key ssl/server.key
max-clients 200
plugin /usr/local/open***/radiusplugin.so /usr/local/open***/radiusplugin.cnf
verb 3
mute 10
status /var/log/open***/status.log 1
log /var/log/open***/open***.log
mkdir /usr/local/open***/ccd
mkdir /var/log/open***
这里我定义10.14段主要是不想跟别人定义的冲突:
#让客户端发起的所有IP请求都通过OPEN×××服务器
#这一句还是不用的好,没必要全部从***走,一般通过dns把内网的通过这里就可以了
#除非对方本地上网是被限制的,那么可以考虑开放这个配置,所有的通过***上网
push "redirect-gateway def1"
#定义客户端的dns服务器地址,设置本地的服务器内网地址就可以了
push "dhcp-option DNS 172.21.41.15"
注释:(这一部分暂时用不到,就是端到端的服务配置)
关于服务器端内网可以访问客户端内网的设置
# 使服务器子网内机器可以访问客户端子网内机器
# 仅用于路由模式
# 假设:客户端子网网段192.168.1.0
# 首先,在服务器配置文件中添加下面这两行
# client-config-dir ccd
# 和route 192.168.1.0 255.255.255.0
# 然后在服务器端ccd目录下创建一个文件,文件名是客户端的公共名,这里的公共名是客户证书的公共名
# 文件内容是:
# iroute 192.168.1.0 255.255.255.0
;client-config-dir ccd
;route 192.168.1.0 255.255.255.0
ccd目录通常在配置文件目录下面建立,公共名(common name)在生成证书,回答问题时填上的,跟证书的文件名一至.
route 192.168.1.0 255.255.255.0表示在服务器端增加访问客户端的路由(192.168.1.0/24指的是客户端网段)
我现在的配置还暂时用不到这个设置项,以上只是参考,感觉有些特殊的地方还是用的到的!
client-to-client 如果让Client之间可以相互看见,去掉本行的注释掉,否则Client之间无法相互访问
duplicate-cn 是否允许一个User同时登录多次,去掉本行注释后可以使用同一个用户名登录多次
plugin /usr/local/open***/radiusplugin.so /usr/local/open***/radiusplugin.cnf 说明使用的插件,
client-cert-not-required #不请求客户的CA证书
username-as-common-name #使用客户提供的UserName作为Common Name
四、开启radius和open***服务
1、建立open***的shell执行脚本
cp /usr/local/src/open***-2.0.9/sample-scripts/open***.init /etc/init.d/
ln -s /usr/local/open***/sbin/open*** /usr/sbin/open***
vi /etc/init.d/open***.init
work=/usr/local/open***
2、开启 open***服务器进程
/etc/init.d/open***.init start
这个时候要看一下 ifconfig 有没有 tun0设备,如果有就基本ok了!
如果有错误,请看/var/log/messages 和 /var/log/open***/open***.log的信息
如果关闭open***使用 :/etc/init.d/open***.init stop
在测试的时候,由于配置出错,会碰到/etc/init.d/open***.init stop关闭不了,使用killall open***来关闭
3、开启radius服务
这个做到这里容易忘记,我就忘了,还查了一阵子错误
radiusd &
五、windows下client.opvn客户端配置文件:
# Which device
dev tun
persist-key
persist-tun
# Our remote peer
nobind
remote *.*.*.* 1194
#出现用户、密码的认证
auth-user-pass
ns-cert-type server
tls-auth ta.key 1
#对于客户端建立了***连接后,通过***远程走的route设定(这里172.16.0.0 255.248.0.0是所有的内网包括从内部路由走出去的其他公司的内网,可以添加多个网段。)
route 172.16.0.0 255.240.0.0
# Use compression
comp-lzo
# Strong encryption
verb 3
mute 10
六、服务器端的路由和防火墙的调整
把以下的iptables命令放在靠前的规则中
#我这里定义$IPT 是 /sbin/iptables
#对于udp 1813和udp 1812 端口,因为radius是127.0.0.1本地的调用,所以不要另外再开许可
#打开open***连接端口udp 1194
$IPT -A INPUT -p udp -m udp --dport 1194 -j ACCEPT
#许可tun设备的,如果你开的是tap设备进行相应的更改
$IPT -A INPUT -i tun0 -j ACCEPT
$IPT -A OUTPUT -o tun0 -j ACCEPT
$IPT -A FORWARD -i tun0 -j ACCEPT
$IPT -t nat -A POSTROUTING -s 10.14.0.0/24 -o $LOCAL_IFACE -j SNAT --to-source $LOCAL_IP
七、自安装客户端的生成步骤
1、下载客户端制作程序
http://www.open***.se/files/nsis/nsis205.exe
http://www.open***.se/files/install_packages_source/open***_install_source-2.0.9-gui-1.0.3.zip
2、安装nsis205.exe
(1)、生成正确的配置源
在windows下解压缩open***_install_source-2.0.9-gui-1.0.3.zip
进入open***_install_source-2.0.9-gui-1.0.3/open***/目录下,建立config,
将正确的客户端的配置文件和密匙放到这个目录下(一个配置文件、3个跟密匙有关的文件):
client.o***、 ta.key 、ca.crt、server.crt
注释:
clint.o***就是client.conf!
(2)、编辑生成正确的配置文件
编辑open***_install_source-2.0.9-gui-1.0.3目录下open***-gui.nsi文件
查找 ;File "${HOME}\config\Office.o***"
替换成
File "${HOME}\config\client.o***"
File "${HOME}\config\ca.crt"
File "${HOME}\config\server.crt"
File "${HOME}\config\ta.key"
(3)、生成自动安装程序
运行NSIS Menu 的
compiler -- star MakNsiSW
菜单files--load script
导入open***_install_source-2.0.9-gui-1.0.3/目录下的open***-gui.nsi
导入这个open***-gui.nsi就会在目录open***_install_source-2.0.9-gui-1.0.3下自动生成open***_install_source-2.0.9-gui-1.0.3-install.exe
在客户端运行这个程序就能得到正确配置的客户端!
参考:
http://www.roessner-net.com/×××_RADIUS_MYSQL.howto.txt
http://www.linuxfly.org/read.php?86
http://www.xiaohui.com/dev/server/20070514-install-open***.htm
http://www.xxlinux.com/linux/article/development/database/20060707/2522_2.html
http://blog.chinaunix.net/u/2389/
Ethernet Bridging
译者:温占考(Email: wzk<AT>wenzk<DOT>net),来源:Open×××.net,转载请注明译者和出处及版权信息,并且不能用于商业用途,违者必究。由于英语水平有限,如有错误,还望指正! 时间: 2006-06-19 22:00 于沈阳
桥接概述
查看FAQ了解路由对比桥接的概述。
以太网桥接实质上是把一个以太网络接口和一个或多个虚拟TAP接口桥接在一个网桥接口上。以太网桥表现为使用软件模拟一个真实的以太网交换机。以太网桥可以理解为一种能够用来连接一个机器上的多个以太网接口(无论是物理的还是虚拟的)使它们共享一个IP子网的软件交换机。
把分布在两个独立网络的一个物理的以太网NIC和一个Open×××所使用的TAP接口桥接起来,这样就可以逻辑上合并两个以太网络,就像它们在一个以太网子网内。
配置桥接
这个例子将指导你配置一个Open×××服务器端的桥接。多个客户将会连接到这个网桥上,并且每个客户机的TAP接口将会分配到一个服务器端LAN网段的IP地址。
下面是两个实现客户IP地址分配的方法:
• 让Open×××使用server-bridge指示来管理其客户的IP地址池,或者
• 在LAN内配置DHCP服务器让其为×××客户分配IP地址。
在这个例子中,我们将使用第一个方法即Open×××服务器管理其客户在LAN子网内的IP地址池,和DHCP服务器使用的地址池分开(如果存在的话)。两种方法在FAQ item都有详细描述。
在我们的例子中,我们将使用下面的网桥配置:
设置
网桥启动 参数
取值
以太网络接口
eth
eth0
本地IP地址
ip
192.168.8.4
本地子网掩码
eth_netmask
255.255.255.0
本地广播地址
eth_broadcast
192.168.8.255
×××客户地址池
192.168.8.128 to 192.168.8.254
虚拟网桥接口
br
br0
虚拟TAP接口
tap
tap0
第一步是按照HOWTO中的“开始使用×××并且测试其连通性(Starting up the ××× and testing for initial connectivity)”章节。然后,根据你是在Linux或Windows下配置桥接继续配置。
在Linux上配置桥接服务器
首先,确认你已经安装了bridge-utils软件包。
编辑下面的bridge-start(启动网桥)脚本。根据你要桥接的物理网络接口设置br, tap, eth, eth_ip, eth_netmask, 和eth_broadcast 参数。确认使用一个内部网络接口并且是连接在一个受防火墙保护的LAN内。你可以使用Linux的ifconfig命令获得网络接口的一些必要的信息来完成bridge-start(启动网桥)参数。
现在就运行bridge-start脚本。脚本将会创建一个永久[译者注:永久意为系统重新启动前永久,默认虚拟接口在Open×××退出后就消失]的tap0网络接口并且已经和以太网接口桥接成功了。
下一步,我们将要编辑Open××× server configuration file(Open×××服务器端配置文件)来使能桥接配置。
注释掉dev tun这行行并且替换成:
dev tap0
注释掉以server开始的行并且替换成:
server-bridge 192.168.8.4 255.255.255.0 192.168.8.128 192.168.8.254
现在设置Linux防火墙使之允许数据包通过新建的tap0 和 br0接口:
iptables -A INPUT -i tap0 -j ACCEPT
iptables -A INPUT -i br0 -j ACCEPT
iptables -A FORWARD -i br0 -j ACCEPT
Open×××桥接现在能够通过下面顺序来启动和停止:
• 运行 bridge-start
• 运行 open***
• 停止 open***
• 运行 bridge-stop
到目前为止,桥接的配置就完成了,你可以continue where you left off in the HOWTO(根据HOWTO继续完成剩下部分)。
在Windows XP中配置桥接服务器
这个配置在桥接端需要Windows XP或更高版本系统。据我所知,Windows 2000不支持桥接,然而Windows 2000系统可以是一个桥接网络的客户,而Open×××另一端的桥接是在Linux或Windows XP系统上实现的。
在Windows上安装Open×××时,安装程序将自动创建一个名为“本地连接2”的TAP-Win32适配器。转到控制面版中的网络连接下并且改名为“tap-bridge”。
接下来使用鼠标选择tap-bridge和以太网适配器,点击鼠标右键,并且选择桥接(Bridge Connections)。这样就在控制面板中创建了一个新的桥适配器图标。
在桥适配器的TCP/IP属性里配置IP地址192.168.8.4子网掩码255.255.255.0。
接下来,编辑Open××× server configuration file(Open×××服务端配置文件) 使能桥接配置。
注释dev tun这行且替换成:
dev tap
dev-node tap-bridge
注释以server开始的行并且替换成:
server-bridge 192.168.8.4 255.255.255.0 192.168.8.128 192.168.8.254
如果你的系统时XP SP2,进入防火墙配置控制面板,并且禁用桥适配器和TAP适配器上的包过滤功能。
到目前为止,桥接的配置就完成了,你可以continue where you left off in the HOWTO(根据HOWTO继续完成剩下部分)。
配置桥接客户端
在sample Open××× client configuration(Open×××客户配置)基础上进行配置。注释dev tun的行且替换成:
dev tap
最后,确认客户端的配置文件和服务器端的配置文件是否一致。需要着重注意的是proto (udp or tcp)选项是否一致。同样如果使用了comp-lzo 和 fragment确认客户端和服务器端是否一致。
以太网桥接说明
使用以太网桥接配置时,第一步是构造以太网桥--一种虚拟网络接口是其他网络接口的一个容器,可以是物理的NIC也可以是虚拟的TAP接口。以太网桥接口必须在Open×××启动之前创建。
没有通用的网桥配置方法--每个OS有自己的配置方法(见下面例子)。
网桥接口一旦被创建,并且以太网接口加入到网桥中,Open×××就可以启动了。
• 网桥接口是一种由一个或多个以太网络接口组成的虚拟网络接口,这些以太网络接口可以是物理网络接口或Open×××所使用的虚拟TAP接口。
• 当你配置以太网桥接接口时,你需要手工设置网桥接口的IP地址和子网掩码并且不要在Open×××配置文件中使用ifconfig选项来配置。这是因为与TUN/TAP接口不一样,Open×××程序不能配置网桥接口的IP地址和子网掩码。
• Open×××配置文件应该通过dev选项来指定已经加入网桥TAP接口,而不是指定网桥接口的名字。
• 对于Windows系统,使用dev-node选项来指定已经加入网桥TAP-Win32适配器(dev-node这个名字是网络连接控制面板上显示的名字)。
• 在Linux/BSD/Unix系统中,对于dev tap选项,使用你已经加入网桥的TUN/TAP的序号如dev tap0。
• 如果你的Open×××工作在点对点模式,去掉ifconfig选项,如果你使用的是客户/服务器模式,在服务器端使用server-bridge选项。
• 桥接的时候,你必须手工设置网桥接口的TCP/IP设置。例如在Linux中,可以使用ifconfig命令配置而在Windows XP中可以通过配置网络连接面板中网桥接口的TCP/IP属性来实现(在Windows XP和更高版本的网络连接面板中可以通过鼠标操作来实现桥接)。
• 确定只有桥接的TAP接口和内部以太网络接口是被防火墙保护的。不要把TAP接口和连接互联网的网络接口进行桥接,这样可能存在潜在的安全漏洞。
• local 和 remote 所使用的地址不能是桥接子网内的地址--否则将会出现路由环路。
• 理解以太网桥接很重要的一点就是每个加入网桥的网络接口将会失去原有的配置如IP地址和子网掩码。只有网桥接口的TCP/IP设置有效。
• 手工配置网桥时常见的错误是在为网桥配置IP地址和子网掩码之前把主要的以太网络适配器加入到网桥中。这就导致主要的以太网卡“丢失”了原有的配置,但是所属的网桥接口还没有配置,所以这就造成了以太网络接口的连接就丢失了。
• 在大多数情况下,只是在服务器端配置一个可用的桥接,而不是在客户端配置。这样一来,当客户机连接上服务器后就成为了多宿主系统了,例如:它们仍然拥有原有的以太网接口,但是连接到Open×××服务器的上层连接,它们将会有一个新的TAP接口和服务器端的以太网接口桥接(并且有可能是所有连接到服务器的客户机的TAP接口如果在服务器的配置文件里申明了client-to-client选项)。
说明 – Windows下的以太网桥接
Check out this HOWTO by Adam Pavelec.
Windows Notes 页面有更多关于以太网桥接的说明。
说明 – Linux下的以太网桥接, 配置脚本
这些脚本将处理Linux下的网桥的启动和停止。在Open×××发行包的sample-scripts下可以找到。
sample-scripts/bridge-start
#!/bin/bash
#################################
# Set up Ethernet bridge on Linux
# Requires: bridge-utils
#################################
# Define Bridge Interface
# 定义网桥接口
br="br0"
# Define list of TAP interfaces to be bridged,
# for example tap="tap0 tap1 tap2".
# 定义需要桥接的TAP接口列表,如:
tap="tap0"
# Define physical ethernet interface to be bridged
# with TAP interface(s) above.
# 定义需要和TAP接口桥接的物理接口
eth="eth0"
eth_ip="192.168.8.4"
eth_netmask="255.255.255.0"
eth_broadcast="192.168.8.255"
for t in $tap; do
open*** --mktun --dev $t
done
brctl addbr $br
brctl addif $br $eth
for t in $tap; do
brctl addif $br $t
done
for t in $tap; do
ifconfig $t 0.0.0.0 promisc up
done
ifconfig $eth 0.0.0.0 promisc up
ifconfig $br $eth_ip netmask $eth_netmask broadcast $eth_broadcast
sample-scripts/bridge-stop
#!/bin/bash
####################################
# Tear Down Ethernet bridge on Linux
####################################
# Define Bridge Interface
br="br0"
# Define list of TAP interfaces to be bridged together
tap="tap0"
ifconfig $br down
brctl delbr $br
for t in $tap; do
open*** --rmtun --dev $t
done
为什么使用TUN模式时,Open×××的"ifconfig-pool"选项使用/30子网(一个客户端占用4个私网IP地址)? 这是为了和Windows下的客户端兼容,由于TAP-Win32的TUN模拟模式的限制,Open×××为每个客户端分配一个/30的子网,如果连接Open×××服务器的都是非Windows客户端,则可以在配置文件中使用ifconfig-pool-linear指令来避免这一行为。在Open××× 2.0中,Open×××服务端可以在仅有一个tun接口的机器上处理多个客户端。要做到这些,可以将你在服务端上看到的点到点PtP连接想象为操作系统和Open×××间的一个连接。在Open×××内部还需要为每个客户端创建另外一个点到点连接。如果所有的O/S都支持tun接口上的真正的PtP连接,则Open×××服务器使用一个IP地址而每个客户端使用另外一个IP地址是可以实现的。但是,Windows下的TUN/TAP驱动实现并不支持真正的PtP连接,它是通过一个/30子网来模拟的。所以,首先在Open×××服务器和操作系统之间有一个PtP连接192.168.1.1<->192.168.1.2. 然后Open×××为每一个连接的客户端分配一个/30的子网,第一个/30子网(除掉服务器使用的)是: 192.168.1.4/30 192.168.1.4 -- 网络地址192.168.1.5 -- 在Open×××服务端上的虚拟IP地址192.168.1.6 -- 分配给客户端192.168.1.7 -- 广播地址要到达Open×××服务器后网络的其它部分,需要给客户端添加(push)一条路由,使流量通过192.168.1.5路由。因为192.168.1.5是Open×××服务器内部的一个虚拟IP地址,用作路由的一个端点(endpoint),所以Open×××不响应在这一地址上的ping包.而192.168.1.1是服务器操作系统上的一个真实IP地址,所以它会响应ping包。这的确浪费了一些IP地址,但是这是使配置文件在Open×××所支持的所有操作系统中保持一致的最好方法。TAP-Win32驱动包括了一个给你分配192.168.1.6 IP地址的DHCP服务器,这就是你看到192.168.1.5作为DHCP服务器地址的原因了。