PPTP/L2TP安装方法就不写了,前面好多文章都介绍了安装方法。
下面先安装FreeRADIUS-server
1
2
3
4
5
6
7
|
#sudo apt-get install mysql5
#sudo apt-get install mysql-server
#sudo apt-get install freeradius
#sudo apt-get install freeradius-mysql
#sudo apt-get install freeradius-utils
#sudo apt-get install freeradius-dialupadmin
|
由于要用到数据库,这里采用mysql,因此先安装mysql,我在没有安装mysql的机器上安装freeradius会出问题,因此先把mysql安装好。
修改配置文件radius.conf
修改主配置文件/etc/freeradius/radiusd.conf。其他系统的相应配置文件可能在/etc/raddb/*下。
对listen字段配置,按需要进行监听
1
2
3
4
5
6
7
8
|
listen
{
.
.
.
ipaddr
=
192.168.1.130
#默认为*,可修改为所需的本机ip地址
type
=
auth
#acct类型下的配置写法也类似
.
.
.
#interface = eth0 #多个网络接口的情况下,可以指定其中一个
.
.
.
}
|
对modules字段配置,选择需要的模块
1
2
3
4
5
6
7
|
modules
{
.
.
.
$INCLUDE
$
{
confdir
}
/
modules
/
#pap、chap等模块的配置也在该目录下
.
.
.
$INCLUDE
sql
.conf
#反注释,以开启sql的相关配置
.
.
.
}
|
1
|
vim
/
etc
/
freeradius
/
sites
-
enabled
/
default
|
找到authorize {}模块,注释掉files(152行),去掉sql前的#号(159行)。
找到preacct {}模块,注释掉files(354行)。
找到accounting {}模块,注释掉radutmp(378行),去掉sql前面的#号(388行)。
找到session {}模块,注释掉radutmp(432行),去掉sql前面的#号(436行)。
找到post-auth {}模块,去掉sql前的#号(457行),去掉sql前的#号(545行)。
1
|
vim
/
usr
/
local
/
etc
/
raddb
/
sites
-
enabled
/
inner
-
tunnel
|
1
2
3
|
找到
authorize
{
}模块,注释掉
files(
124行),去掉
sql前的
#号(131行)。
找到
session
{
}模块,注释掉
radutmp(
251行),去掉
sql前面的
#号(255行)。
找到
post
-
auth
{
}模块,去掉
sql前的
#号(277行),去掉sql前的#号(301行)。
|
freeradius2.1.3 防止用户帐号重复登录
一、修改 etc/raddb/sites-enabled 目录中的default 及inner-tunnel 这两个文件中的
# Session database, used for checking Simultaneous-Use. Either the radutmp
# or rlm_sql module can handle this.
# The rlm_sql module is *much* faster
session {
#radutmp
#原来使用的是radutmp文档
# See "Simultaneous Use Checking Querie" in sql.conf
sql
#现在采用sql数据库验证
}
二、修改etc/raddb/sql/mysql 目录下的 dialup.conf
# Uncomment simul_count_query to enable simultaneous use checking
把 simul_count_query 这一组前的#号去掉 如下
simul_count_query = "SELECT COUNT(*) \
FROM ${acct_table1} \
WHERE username = '%{SQL-User-Name}' \
AND acctstoptime IS NULL"
三、进入MYSQL在radgroupcheck添加Simultaneous-Use:=1 命令如下
INSERT INTO radgroupcheck
( id
, GroupName
, Attribute
, op
, Value
)
VALUES (
NULL , ’user’, ’Simultaneous-Use’, ’:=’, ’1’
);
注意user 为组名,这个改成你自己用的组名
限制VPN流量的方法
# vi /etc/freeradius/radiusd.conf
取消注释695行, $INCLUDE sql/mysql/counter.conf
# vi /etc/freeradius/sql/mysql/counter.conf
最底行加入
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
sqlcounter
monthlytrafficcounter
{
counter
-
name
=
Monthly
-
Traffic
check
-
name
=
Max
-
Monthly
-
Traffic
reply
-
name
=
Monthly
-
Traffic
-
Limit
sqlmod
-
inst
=
sql
key
=
User
-
Name
reset
=
monthly
query
=
"SELECT SUM(acctinputoctets + acctoutputoctets) FROM radacct WHERE UserName='%{%k}' AND UNIX_TIMESTAM(AcctStartTime) > '%b'"
}
# vi /etc/freeradius/sites-enabled/default
找到
authorize
{
.
.
.
}这栏
在
" } "
前面一行加入
monthlytrafficcounter
# vi /etc/freeradius/dictionary
最底行插入
|
1
2
|
ATTRIBUTE
Max
-
Monthly
-
Traffic
3003
integer
ATTRIBUTE
Monthly
-
Traffic
-
Limit
3004
integer
|
1
|
# 限制用户组流量SQL操作
|
1
|
mysql
>
INSERT
INTO
radgroupcheck
(
GroupName
,
Attribute
,
op
,
Value
)
values
(
"user1"
,
"Max-Monthly-Traffic"
,
":="
,
"1024"
)
;
|
1
|
# 针对每个用户分配特定IP
|
1
|
mysql
>
INSERT
INTO
radreply
(
UserName
,
Attribute
,
op
,
Value
)
values
(
"user"
,
"Framed-IP-Address"
,
":="
,
"192.168.0.99"
)
;
|
1
2
3
|
客户端配置文件
clients
.
conf
修改客户端配置文件
/
etc
/
freeradius
/
clients
.
conf,以添加一个允许连接的客户端,例如
|
1
2
3
4
|
client
192.168.1.4
{
#客户端的ip地址,可以是ip段,如192.168.1.0/24
secret
=
testing123
shortname
=
private
-
network
-
client
}
|
这里,也可以将radiusd.conf的clients.conf注释掉
#$INCLUDE clients.conf
并将sql.conf的readclients反注释
1
2
3
4
5
|
sql
{
.
.
.
readclients
=
yes
.
.
.
}
|
这样就不会使用配置文件clients.conf,而使用数据库里的nas表读取客户端信息。
接下来对authorize字段和accounting字段进行配置。需要注意的是,Ubuntu下这两个字段的内容移到了/etc/freeradius/sites-avaible/default下 :
为了启动对mysql的支持,在authorize字段里,注释files,反注释sql
1
2
3
4
5
6
|
authorize
{
.
.
.
#files #注释,不使用files文件进行授权
sql
#反注释,以使用sql进行授权
.
.
.
}
|
在accounting字段里,反注释sql
1
2
3
4
5
|
accounting
{
.
.
.
sql
#反注释,以使用sql进行计费
.
.
.
}
|
数据库配置文件sql.conf
修改访问数据库的配置文件/etc/freeradius/sql.conf
1234567891011 sql {. . .driver = "mysql"server = "localhost"login = "root"password = "radpass"radius_db = "radius". . .#readclients = yes #去掉这里的注释可以从数据库的nas表读取client. . .}
这里假定在MySQL里,root用户的密码为radpass,预定为FreeRADIUS建立的新数据库名为radius。
在MySQL建立数据库
在MySQL里面创建FreeRADIUS使用的数据库:
123456 #/usr/local/mysqladmin -u root -p create radius#cd /etc/freeradius/raddb/sql/mysql#mysql -u root -p radius < schema.sql#mysql -u root -p radius < nas.sql#mysql -u root -p radius < ippool.sql#mysql -u root -p radius < wimax.sql还可以一开始就用/etc/freeradius/sql/mysql/admin.sql来生成MySQL新用户,专门用来访问FreeRADIUS的数据库。
FreeRADIUS-client 客户端安装
服务端已经好了,下一步就开始安装客户端。
12345 wget - c ftp : / / ftp .freeradius .org / pub / freeradius / freeradius - client - 1.1.6.tar.gztar - zxf freeradius - client - 1.1.6.tar.gzcd freeradius - client - 1.1.6. / configuremake && make install修改客户端的配置文件
/usr/local/etc/radiusclient/servers
加入
1 localhost testing123 #这个是服务器的地址和密钥根据实际情况修改增加字典
这一步很重要!否则windows客户端无法连接服务器。
12 wget - c http : / / small - script .googlecode .com / files / dictionary .microsoftmv . / dictionary .microsoft / usr / local / etc / radiusclient /
12345678 #下面是将字典文件加入到配置文件中cat >> / usr / local / etc / radiusclient / dictionary << EOFINCLUDE / usr / local / etc / radiusclient / dictionary .sipINCLUDE / usr / local / etc / radiusclient / dictionary .ascendINCLUDE / usr / local / etc / radiusclient / dictionary .meritINCLUDE / usr / local / etc / radiusclient / dictionary .compatINCLUDE / usr / local / etc / radiusclient / dictionary .microsoftEOF客户端配置结束。
与PPTP/L2TP整合
1234567 sed - i 's/logwtmp/\#logwtmp/g' / etc / pptpd .confsed - i 's/radius_deadtime/\#radius_deadtime/g' / usr / local / etc / radiusclient / radiusclient .confsed - i 's/bindaddr/\#bindaddr/g' / usr / local / etc / radiusclient / radiusclient .confcat >> / etc / ppp / pptpd - options < plugin / usr / lib / pppd / 2.4.5 / radius .soradius - config - file / usr / local / etc / radiusclient / radiusclient .confEOF下面与XL2TPD整合
123 cat >> / etc / ppp / options .xl2tpd < plugin / usr / lib / pppd / 2.4.5 / radius .soradius - config - file / usr / local / etc / radiusclient / radiusclient .confEOF基于Web管理FreeRADIUS
http服务器的架设就不介绍了,下面直接进入正题。
修改主配置文件/etc/freeradius-dialupadmin/admin.conf
12345678910 general_encryption_method : clear #可按需要取值为crypt,md5,clearsql_type : mysqlsql_server : localhostsql_port : 3306sql_username : rootsql_password : radpasssql_database : radius. . .sql_usergroup_table : radusergroup. . .
在apache的配置文件httpd.conf加上该路径:
1 Include / etc / freeradius - dialupadmin / apache2 .conf继续导入freeradius-dialupadmin中用到的几个表:
12345 #cd /usr/share/freeradius-dialupadmin/sql/mysql/#mysql -u root -p radius < badusers.sql#mysql -u root -p radius < mtotacct.sql#mysql -u root -p radius < totacct.sql#mysql -u root -p radius < userinfo.sql
这里,自己在导入userinfo时提示有错误
ERROR 1067 (42000): Invalid default value for 'id'
于是将userinfo.sql里的
1 id int(10) DEFAULT '0' NOT NULL auto_increment,改为
1 id int(10) unsigned NOT NULL auto_increment,
下面给数据库添加一些基本信息。先进入radius数据库
12 #mysql -u root -pmysql > use radius ;添加用户信息:
12 mysql > insert into radcheck ( username , attribute , value ) values ( 'test1' , 'User-Password' , '123456' ) ;mysql > insert into radreply ( username , attribute , op , value ) values ( 'test1' , 'Reply-Message' , '=' , 'Yes,Good!' ) ;
添加组信息:
1234 mysql > insert into radgroupcheck ( groupname , attribute , op , value ) values ( 'group1' , 'Auth-Type' , ':=' , 'Local' ) ;mysql > insert into radgroupreply ( groupname , attribute , op , value ) values ( 'group1' , 'Auth-Type' , ':=' , 'Local' ) ;mysql > insert into radgroupreply ( groupname , attribute , op , value ) values ( 'group1' , 'Service-Type' , '=' , 'Framed-User' ) ;mysql > insert into radgroupreply ( groupname , attribute , op , value ) values ( 'group1' , 'Framed-IP-Netmask' , '=' , '255.255.255.255' ) ;然后把用户加到组里:
1 mysql > insert into radusergroup ( username , groupname ) values ( 'test1' , 'group1' ) ;客户端安装方法2:
首先下载并安装daloRADIUS,其中需要安装一个Pear-DB的包:这里关于Pear-DB,搞了好长时间才搞定,我用的是lnmp安装包,对于安装这个东西,用如下方法:
12 wget < a href = "http://pear.php.net/go-pear" target = "_blank" > http : / / pear .php .net / go - pear < / a > - O go - pear .phpphp go - pear .php按提示安装设置
执行:安装目录/pear install db
wget http://sourceforge.net/projects/daloradius/files/daloradius/daloradius0.9-9/daloradius-0.9-9.tar.gz
pear
install
DB
mkdir
/usr/share/daloRadius
tar
zxvf daloradius-0.9-8.
tar
.gz
mv
daloradius-0.9-8/*
/usr/share/daloRadius/
rm
-r daloradius-0.9-8
但是,这样有时候还会出问题,如果你们可以正常访问控制页面可以无视下面的操作,如果不能访问,拷贝/usr/share/php目录下所有文件到daloradius的目录下即可解决,该目录中有PHP-DB的插件。
1 cp < / code > < code > / usr / share / php / * / var / www / daloradius /这样弄好以后,就可以将管理系统的数据导入到数据库中了,执行下面这条命令
1 mysql - uroot - p radius < / usr / share / daloRadius / contrib / db / fr2 - mysql - daloradius - and - freeradius .sql此外还要修改配置文件:
/var/www/daloradius/library/daloradius.conf.php
可能要修改下面这些地方:
12345678 $configValues [ 'CONFIG_DB_HOST' ] = ‘ localhost’ ; / * MYSQL服务器地址 * /$configValues [ 'CONFIG_DB_USER' ] = ‘ radius’ ; / * MYSQL服务器登陆用户名 * /$configValues [ 'CONFIG_DB_PASS' ] = ‘ radpass’ ; / * MYSQL服务器登陆密码 * /$configValues [ 'CONFIG_DB_NAME' ] = ‘ radius’ ; / * MYSQL服务器 radius _db数据库名 * /$configValues [ 'CONFIG_FILE_RADIUS_PROXY' ] = ‘ / usr / local / etc / raddb / proxy .conf’ ;$configValues [ 'CONFIG_PATH_RADIUS_DICT' ] = ‘ / usr / local / share / freeradius’ ;$configValues [ 'CONFIG_PATH_DALO_VARIABLE_DATA' ] = ‘ / var / www / daloradius / var’ ;$configValues [ 'CONFIG_LOG_FILE' ] = ‘ / tmp / daloradius .log’ ; / * daloRADIUS日志路径 * /到此管理系统已经配置完成了。
测试
12345678 # 添加用户并且加入"user"用户组,注意是在radcheck、radusergroup表。mysql > INSERT INTO radcheck ( username , attribute , op , VALUE ) VALUES ( 'demo' , 'Password' , ':=' , 'demo' ) ;mysql > INSERT INTO radusergroup ( username , groupname ) VALUES ( 'demo' , 'user' ) ;# 限制同时登陆次数,注意是在radgroupcheck表mysql > INSERT INTO radgroupcheck ( groupname , attribute , op , VALUE ) VALUES ( 'normal' , 'Simultaneous-Use' , ':=' , '1' ) ;#测试是否生效freeradiusd - Xradtest demo demo localhost 0 testing123
参考资料:
1. https://tomem.info/blog/2011/04/562
2. https://tomem.info/blog/2011/04/577
3. http://www.xtgly.com/2011/01/05/...
4. http://ichinihachi.blogspot.com/2011/02/ubuntufreeradius.html
5、http://www.deepvps.com/poptop-freeradius-daloradius-setup.html
6、http://www.gjia.cn/2011/06/20/daloradius%E5%AE%89%E8%A3%85%E5%90%8E%E7%99%BB%E5%BD%95%E5%87%BA%E7%8E%B0%E7%A9%BA%E7%99%BD%E9%A1%B5%E6%88%96500%E9%94%99%E8%AF%AF/7、http://dayanjia.com/2011/03/configure-freeradius-and-daloradius-on-pptp-vpn-server.html
8、http://www.deepvps.com/poptop-freeradius-daloradius-setup.html
9、http://code.google.com/p/tuo/wiki/Radius_MySQL_daloRadius
10、http://ihipop.info/2011/05/2332.html
11、https://wangyan.org/blog/freeradius-pptp-l2tp-html.html
12、http://ichinihachi.blogspot.com/2011/02/ubuntufreeradius.html
声明: 本文由( liva )原创编译,转载请保留链接: Ubuntu下配置FreeRADIUS + PPTP/L2TP + Mysql + daloRADIUS