FreeRadius 3.0版本,用了mysql,配置了eap-peap支持,到这一步网上教程很多不多说。
企业里面要用多个ap配置wifi认证通过radius统一管理,好方便结合企业的oa权限等。
先是安装了openwrt的wpad-openssl模块让ap支持wpa-eap企业模式。
继续配置freeradius的sql认证,给radcheck表加一个字段macaddr来绑账号到mac地址,但发现如果要在认证时取mac地址属性${Calling-Station-Id}来参与认证,在认证authorize_check_query的sql中写${Calling-Station-Id}取不到值,是空的。
折腾nn小时后发现原因:
因为使用了eap认证模式,认证过程会调用内部通道模式inner-tunnel,所以必须修改/etc/raddb/sites-available/inner-tunnel 这个文件,把Calling-Station-Id属性从外部request集合中传进来,否则取到是空值。
然后就可以在sql配置中%{Calling-Station-Id}直接引用
/etc/raddb/sites-available/inner-tunnel 文件修改如下:
authorize {
...
# add by et, 2025-4-30, mac address
update request {
Calling-Station-Id := "%{outer.request:Calling-Station-Id}"
}
sql
...
}
post-auth {
...
# add by et, 2025-4-30, mac address
update request {
Calling-Station-Id := "%{outer.request:Calling-Station-Id}"
}
-sql
...
}
然后,是认证检查的sql修改如下,macaddr一开始为空能认证,传入mac地址等于绑定mac也能认证:
authorize_check_query = "\
SELECT id, username, attribute, value, op \
FROM ${authcheck_table} \
WHERE username = '%{SQL-User-Name}' AND (macaddr IS NULL OR macaddr ='' OR macaddr = '%{Calling-Station-Id}') \
ORDER BY id"
然后是修改start段的sql,目标是在原来认证通过后插入新会话记录到radacct表时,同时执行update更新radcheck账号表,把认证时取到的设备mac地址写入关联账号记录绑定。同时更新下mac绑定创建时间和最后使用时间。注意是在原来的sql后面用分号隔开第2条update语句哈。改完就大功告成。
start {
#
# Insert a new record into the sessions table
#
query = "\
INSERT INTO ${....acct_table1} \
(${...column_list}) \
VALUES \
('%{Acct-Session-Id}', \
'%{Acct-Unique-Session-Id}', \
'%{SQL-User-Name}', \
'%{Realm}', \
'%{NAS-IP-Address}', \
'%{%{NAS-Port-ID}:-%{NAS-Port}}', \
'%{NAS-Port-Type}', \
${....event_timestamp}, \
${....event_timestamp}, \
NULL, \
'0', \
'%{Acct-Authentic}', \
'%{Connect-Info}', \
'', \
'0', \
'0', \
'%{Called-Station-Id}', \
'%{Calling-Station-Id}', \
'', \
'%{Service-Type}', \
'%{Framed-Protocol}', \
'%{Framed-IP-Address}', \
'%{Framed-IPv6-Address}', \
'%{Framed-IPv6-Prefix}', \
'%{Framed-Interface-Id}', \
'%{Delegated-IPv6-Prefix}' \
${....class.packet_xlat}); \
UPDATE ${....authcheck_table} SET \
macstarttime = ${....event_timestamp}, \
maclasttime = ${....event_timestamp}, \
macaddr = '%{Calling-Station-Id}' \
WHERE UserName = '%{SQL-User-Name}' \
AND (macaddr IS NULL OR macaddr ='');"
#### up modify by et, 2025-4-29, put macaddr to radcheck table on login auth ok. #####################
就是这里,UPDATE是用分号隔开的,前面是原来的默认sql
大功告成。折腾nn小时。。。。发上来记录分享。。。