http://bbs.chinaunix.net/archiver/tid-1649418.html
http://dozview.com/blog/an-implementation-of-openvpn-system-based-on-userpass-authentication-bandwidth-control
https://tomem.info/blog/2010/06/207
http://b.gkp.cc/2010/08/11/resolv-openvpn-linux-client-dns-issue/
http://dozview.com/blog/an-implementation-of-openvpn-system-based-on-userpass-authentication-bandwidth-control
http://wiki.freeradius.org/index.php/FAQ
http://blog.163.com/dyc_888@126/blog/static/1004433512010827111128958/
- 准备工作
- 安装build-essential
apt-get install build-essential wget - 安装基础组件(Apache2, PHP5, MySQL5)
sudo apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server php5-mcrypt openssl php-pear php5-gd php-DB
期间会要求设置mysql的root账户密码 - 此时访问phpinfo.php,php可以解析但浏览器提示下载,这是缺少MIME TYPE参数引起的。修改/etc/apache2/apache2.conf,加入
AddType application/x-httpd-php .php
- 安装phpMyAdmin
wget http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.3.8/phpMyAdmin-3.3.8-all-languages.tar.gz - 安装FreeRadius,目前源里的版本是2.1.9
apt-get install freeradius freeradius-mysql libgcrypt11-dev
/*编译安装FreeRadius
wget ftp://ftp.freeradius.org/pub/freeradius/freeradius-server-2.1.10.tar.gz
# 我实际操作时上面的地址超时了,我用的是下面这个:
# wget ftp://ftp.ntua.gr/pub/net/radius/freeradius/freeradius-server-2.1.10.tar.gz
# FreeRadius的下载页面在这里 -> http://freeradius.org/download.html
tar -zxvf freeradius-server-2.1.10.tar.gz
cd freeradius-server-2.1.10
./configure
cp libltdl/ltdl.h src/include/ # 这步很重要
make
make install */这样,各种教程里提到的raddb目录就是/etc/freeradius目录。
如果服务器有ip6的话,这里有点小问题:修改信任客户端里面的本机IP。没ip6的话直接跳到下个section吧。
vi /etc/freeradius/clients.conf
修改第一个ipaddr为服务器的ip4地址(不是环回,原因不知道)。这里不设置的话,后果就是radius拒绝连接。
确认freeradius服务运行之后执行下面命令来测试:
radtest root root帐号的密码 127.0.0.1 1812 testing123
无ip6的服务服务器可以把这里的127.0.0.1换成localhost试试。
如果不使用freeradius服务而是执行freeradius -X可以以debug模式执行,找出问题来。 - 装配OpenVPN服务器
- 下载和安装,iptable用于设置nat伪装,很重要
apt-get install liblzo2-2 libpkcs11-helper1 openssl-blacklist openvpn-blacklist python iptables
wget https://launchpad.net/~berni/+archive/ipv6/+files/openvpn_2.1.0-1%2Bipv6-2~intrepid_i386.deb
dpkg -i openvpn_2.1.0-1+ipv6-2~intrepid_i386.deb - 配置OpenVPN服务器端,生成证书和配置文件这两部分请参考 http://d.ream.at/ipv6-vpn/
服务器配置文件server.conf
port 53
proto udp6
……
push “dhcp-option DNS 208.67.222.222″
push “dhcp-option DNS 208.67.220.220″
client-to-client
keepalive 10 120
comp-lzo
persist-key
persist-tun
verb 3
客户端配置文件openvpn.ovpn
……
proto udp6
remote 不加中括号的ip6地址 53
……
#对于linux客户端要注意下面三行,否则无法使用推送的DNS
script-security 2
up /etc/openvpn/update-resolv-conf
down /etc/openvpn/update-resolv-conf - 配置nat伪装,注意我这是OpenVZ主机的用法。Xen的看这里 -> http://pityonline.info/?p=1054
iptables -t nat -A POSTROUTING -j SNAT --to-source 服务器ip4地址
这行也要放到/etc/init.d/rc.local里面去 - 开启路由(ip4包转发)
echo 1 > /proc/sys/net/ipv4/ip_forward
记得还要去修改/etc/sysctl.conf哦! - 完成以上步骤,客户端胜利地通过ip6用证书测试连接。
- 在MySQL中加入供radius使用的数据库(可以进入PMA操作),导入radius的数据表结构
mysql -uroot -p
use radius # radius是我的数据库名称
# 输入/etc/freeradius/sql/mysql/schema.sql文件的内容
CREATE TABLE nas (id int(10) NOT NULL auto_increment, nasname varchar(128) NOT NULL, shortname varchar(32), type varchar(30) DEFAULT 'other', ports int(5), secret varchar(60) DEFAULT 'secret' NOT NULL, community varchar(50), description varchar(200) DEFAULT 'RADIUS Client', PRIMARY KEY (id), KEY nasname (nasname)); # 加入用于管理的nas表
配置radius与mysql的连接:
vi /etc/freeradius/sql.conf
修改login、password、radius_db三个参数并且去除readclients = yes的注释。
打开sql权限:
vi /etc/freeradius/radiusd.conf
在modules部分的约660行去除对“$INCLUDE sql.conf”的注释;
vi /etc/freeradius/sites-enabled/default
在authorize部分约159行去除sql的注释,accounting部分383行也是,session部分428行也是,post-auth部分449行也是。
下面来个测试用户试试,在radius数据库中执行INSERT INTO radcheck (UserName, Attribute, Value) VALUES ('sqltest', 'Password', 'testpwd');FLUSH PRIVILEGES;
启动freeradius -X之后输出了好多好乱的信息,但至少是就绪了;在另一个终端执行radtest sqltest testpwd 127.0.0.1 1812 testing123胜利。 - 装配FreeRadius的Web后台daloRADIUS
- 下载解压
wget http://downloads.sourceforge.net/project/daloradius/daloradius/daloradius-0.9-8/daloradius-0.9-8.tar.gz
tar -zxvf daloradius-0.9-8.tar.gz
mv daloradius-0.9-8 dalo - 导入表,文件在contrib/db/mysql-daloradius.sql
- 配置daloRADIUS连接数据库,文件是library/daloradius.conf.php,这个不用说的大家都会的。ip6用户注意如果你在添加mysql用户的时候限制了只允许从本机访问,这里连接又很操蛋地把你认为是外面的ip的话,不妨把数据库服务器从127.0.0.1改成::1,反正我就是这么做的。
- 还有就是daloradius.conf.php的37行那个usergroup要改成radusergroup,进数据库,把表radusergroup复制一份叫usergroup,不然daloRADIUS后台好多页面会报错。
- 连接OpenVPN和FreeRadius
- 下载插件
wget http://www.nongnu.org/radiusplugin/radiusplugin_v2.1_beta9.tar.gz
tar zxvf radiusplugin_v2.1_beta9.tar.gz
cd radiusplugin/
make
cp radiusplugin.cnf radiusplugin.so /etc/openvpn
vi /etc/openvpn/radiusplugin.cnf
修改sharedsecret和/etc/freeradius/clients.conf的一致,61行附近的服务器ip也别忘了改成127.0.0.1。注意默认的radiusplugin.cnf里面有两个server,你可能需要删掉其中一个。 - 修改OpenVPN配置,具体而言是server.conf里,在server行下面加入
client-cert-not-required
username-as-common-name
plugin /etc/openvpn/radiusplugin.so /etc/openvpn/radiusplugin.cnf
auth RSA-SHA512
cipher AES-256-CBC - 在客户端的openvpn.ovpn中加入
auth-user-pass
auth RSA-SHA512
cipher AES-256-CBC - 客户端测试连接是成功的
- 复制多份服务器端的server.conf文件,使用不同协议。注意要使用local x.x.x.x 和local xx:xx:xx:xx:xx:xx:xx:xx来指明监听
没有评论:
发表评论