RadiusPlugin插件的下载地址:http://www.nongnu.org/radiusplugin/。
#下载插件
wget http://www.nongnu.org/radiusplugin/radiusplugin_v2.1a_beta1.tar.gz
#解压缩
tar xf radiusplugin_v2.1a_beta1.tar.gz
cd radiusplugin_v2.1a_beta1
#解决依赖问题
yum install libgcrypt-devel -y
#安装非常简单,直接在目录下make
make
#把编译好的模块拷贝到
cp radiusplugin.so /usr/lib64/open***/plugin/lib/
#拷贝相应的配置文件
cp radiusplugin.cnf /etc/open***/ 四、配置FreeRADIUS与MySQL的连接
对于FreeRADIUS服务器来说,根据需要,要对3个配置文件进行修改,其中一个是FreeRADIUS服务器的主配置文件radiusd.conf,一个是认证配置文件default,还有一个是与SQL数据库相关的配置文件sql.conf。
1、配置数据库
首先配置一下数据库,数据库的sql脚本是freeradius-mysql软件包带的,所以需要安装它。
mysql> create database radius;
mysql> grant all privileges on radius.* to radius@"localhost" identified by "radpass";
mysql> grant all privileges on radius.* to radius@"127.0.0.1" identified by "radpass";
mysql> use radius;
mysql> source /etc/raddb/sql/mysql/schema.sql
mysql> source /etc/raddb/sql/mysql/nas.sql
mysql> show tables;
+------------------+
| Tables_in_radius |
+------------------+
| nas |
| radacct |
| radcheck |
| radgroupcheck |
| radgroupreply |
| radpostauth |
| radreply |
| radusergroup |
+------------------+
# 插入测试数据,用于后面认证
mysql> insert into radcheck (username,attribute,op,value) values ('test','Cleartext-Password',':=','test');
8 rows in set (0.00 sec) 主数据库各字段含义:
radcheck 用户检查信息表
radreply 用户回复信息表
radgroupcheck 用户组检查信息表
radgroupreply 用户组检查信息表
radusergroup 用户和组关系表
radacct 计费情况表
radpostauth 认证后处理信息,可以包括认证请求成功和拒绝的记录。
nas 网络设备表
扩展功能表,可以按需导入ippool.sql、wimax.sql wimax、cui.sql cui详细的表定义。 2、配置主配置文件radiusd.conf
这个配置文件比较简单,在module模块里面把sql.conf和counter.conf前面的注释去掉即可,用来启用数据库连接查询等功能:
# As of 2.0.5, most of the module configurations are in a
# sub-directory. Files matching the regex /[a-zA-Z0-9_.]+/
# are loaded. The modules are initialized ONLY if they are
# referenced in a processing section, such as authorize,
# authenticate, accounting, pre/post-proxy, etc.
#
$INCLUDE ${confdir}/modules/
# Extensible Authentication Protocol
#
# For all EAP related authentications.
# Now in another file, because it is very large.
#
$INCLUDE eap.conf
# Include another file that has the SQL-related configuration.
# This is another file only because it tends to be big.
#
$INCLUDE sql.conf #打开这里的注释
#
# This module is an SQL enabled version of the counter module.
#
# Rather than maintaining seperate (GDBM) databases of
# accounting info for each counter, this module uses the data
# stored in the raddacct table by the sql modules. This
# module NEVER does any database INSERTs or UPDATEs. It is
# totally dependent on the SQL module to process Accounting
# packets.
#
$INCLUDE sql/mysql/counter.conf #打开这里的注释
# 3、配置radius认证文件
修改/etc/raddb/site_enabled下的defoult文件,默认是使用的文件认证,现在取消文件认证,改为sql认证,差不多少有file的注释掉,sql的启用,下面是我的模板。
[root@ios*** ~]# grep -Ev "^#|[:spcae:]*#|^$" /etc/raddb/sites-enabled/default
authorize {
preprocess
chap
mschap
digest
suffix
eap {
ok = return
}
sql #去掉注释,开启sql
expiration
logintime
pap
}
authenticate {
Auth-Type PAP {
pap
}
Auth-Type CHAP {
chap
}
Auth-Type MS-CHAP {
mschap
}
digest
unix
eap
}
preacct {
preprocess
acct_unique
suffix
# files
}
accounting {
detail
unix
radutmp
sql #去掉注释
exec
attr_filter.accounting_response
}
session {
radutmp
sql
}
post-auth {
sql
exec
Post-Auth-Type REJECT {
attr_filter.access_reject
}
}
pre-proxy {
}
post-proxy {
eap
} 4、配置与mysql数据库连接的配置文件sql.conf
其实按照上面的参数设定的话,这个文件不需要修改的,文件内容如下:
[root@ios*** ~]# grep -Ev "^#|[:spcae:]*#|^$" /etc/raddb/sql.conf
sql {
database = "mysql"
driver = "rlm_sql_${database}"
server = "localhost"
login = "radius"
password = "radpass"
radius_db = "radius"
acct_table1 = "radacct"
acct_table2 = "radacct"
postauth_table = "radpostauth"
authcheck_table = "radcheck"
authreply_table = "radreply"
groupcheck_table = "radgroupcheck"
groupreply_table = "radgroupreply"
usergroup_table = "radusergroup"
deletestalesessions = yes
sqltrace = no
sqltracefile = ${logdir}/sqltrace.sql
num_sql_socks = ${thread[pool].max_servers}
connect_failure_retry_delay = 60
lifetime = 0
max_queries = 0
nas_table = "nas"
$INCLUDE sql/${database}/dialup.conf
} 5、测试FreeRADIUS和MySQL的通信认证
配置到这里我们简单测试一下FreeRADIUS的认证是否可以了。需要命令radtest,如果没有这个命令,我们可以通过安装软件包来添加。
yum install freeradius-utils -y
# 启动freeradius,可以使用radiusd -X开启Debug模式
service radiusd start 用radtest测试test用户,密码是test。
[root@ios*** ~]# radtest test test localhost 0 testing123
Sending Access-Request of id 239 to 127.0.0.1 port 1812
User-Name = "test"
User-Password = "test"
NAS-IP-Address = 127.0.0.1
NAS-Port = 0
Message-Authenticator = 0x00000000000000000000000000000000
rad_recv: Access-Accept packet from host 127.0.0.1 port 1812, id=239, length=20 服务器如果返回有“Access-Accept”的字样,代表认证成功了,如果有“Access-Reject”字样则认证失败,这时可以停用radiusd服务,用命令radiusd -X开启服务从全部的debug信息中找到问题并解决,如果NAS-IP-Address显示的不是127.0.0.1那说明你没有配置主机名解析,请在hosts里面配置一下。 五、Open***通过插件连接FreeRADIUS进行认证
1、配置与客户端通信配置文件clients.conf
这个文件是FreeRADIUS与客户端(RadiusPlugin)通信使用的配置文件,默认文件只需添加shorname = localhost项,通信密钥可以默认。
[root@ios*** ~]# grep -Ev "^#|[:spcae:]*#|^$" /etc/raddb/clients.conf
client localhost {
ipaddr = 127.0.0.1
secret = testing123 #此参数与后面的radiusplugin.cnf内参数需一致
require_message_authenticator = no
shortname = localhost
} 2、配置radiusplugin.cnf
此文件是用来关联Open***和FreeRADIUS的,前面FreeRADIUS和MySQL的测试已经成功了,下面配置好此文件之后就可以测试***的认证了,此文件需要修改的地方不多,我这里的配置如下:
[root@ios*** ~]# grep -Ev "^#|^$" /etc/open***/radiusplugin.cnf
NAS-Identifier=Open***
Service-Type=5
Framed-Protocol=1
NAS-Port-Type=5
NAS-IP-Address=127.0.0.1
Open***Config=/etc/open***/server.conf
subnet=255.255.255.0
overwriteccfiles=true
nonfatalaccounting=false
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 #和FreeRadius的客户端配置文件保持一致
} 3、Open***服务端配置文件
通过plugin字段让Open***调用RadiusPlugin插件。
[root@ios*** ~]# grep -Ev "^#|^$|^;" /etc/open***/server.conf
management 127.0.0.1 5800 #开启管理接口,不需要可以注释掉
port 1194
proto tcp
dev tun
ca /usr/share/doc/open***-2.3.9/sample/sample-keys/ca.crt #注意证书的路径,不同版本不一样
cert /usr/share/doc/open***-2.3.9/sample/sample-keys/server.crt
key /usr/share/doc/open***-2.3.9/sample/sample-keys/server.key
dh /usr/share/doc/open***-2.3.9/sample/sample-keys/dh2048.pem
topology subnet #开启节省IP,具体为什么查看我的Open***安装文档
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push "route 10.0.0.0 255.0.0.0"
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 114.114.114.114"
client-to-client
duplicate-cn
keepalive 10 120
comp-lzo
persist-key
persist-tun
status /var/log/open***/open***-status.log
log-append /var/log/open***/open***.log
verb 3
script-security 3 system
plugin /usr/lib64/open***/plugin/lib/radiusplugin.so /etc/open***/radiusplugin.cnf
client-cert-not-required
username-as-common-name 4、Open***客户端配置文件
我这里是Windows的客户端,配置文件如下:
client
dev tun
proto tcp
remote 211.152.x.x 1194 #Open***服务器的IP地址
nobind
persist-key
persist-tun
ca ca.crt
;cert client.crt
;key client.key
comp-lzo
verb 3
auth-user-pass #客户端使用账号密码登录
reneg-sec 360000 5、***连接测试
重启Open*** 服务端后客户端就可以用“用户名/密码”的形式登录***了,如果要添加新的用户只需要在radius数据库的radcheck表插入新的记录即可,很是方便快捷。
在/var/log/radius和/var/log/open***下面有很多日志是记录连接状态的,如果连接有问题可以查看日志查找原因。
下面是我的Open***的日志,如果你的FreeRADIUS开启Debug模式的话也可以看到登录成功的信息。