参考:
https://www.cnblogs.com/opsprobe/p/9420502.html
https://blog.csdn.net/lassewang/article/details/9159543
0 RADIUS RADIUS:(Remote Authentication Dial In User Service)中文名为远程用户拨号认证服务,简称RADIUS,是目前应用最广泛的AAA协议(认证、授权和计费)
图中Device(例如交换机)向远程接入用户提供接入及与RADIUS服务器交互的服务。RADIUS服务器上则存储用户的身份信息、授权信息以及访问记录,对用户进行认证、授权和计费服务
认证过程如下
(1)客户端向接入设备发送一个EAPoL-Start报文,开始802.1x认证接入;
(2)接入设备向客户端发送EAP-Request/Identity报文,要求客户端将用户名送上来;
(3)客户端回应一个EAP-Response/Identity给接入设备的请求,其中包括用户名;
(4)接入设备将EAP-Response/Identity报文封装到RADIUS Access-Request报文中,发送给认证服务器;
(5)认证服务器产生一个Challenge,通过接入设备将RADIUS Access-Challenge报文发送给客户端,其中包含有EAP-Request/MD5-Challenge;
(6)接入设备通过EAP-Request/MD5-Challenge发送给客户端,要求客户端进行认证;
(7)客户端收到EAP-Request/MD5-Challenge报文后,将密码和Challenge做MD5算法后的Challenged-Pass-word,在EAP-Response/MD5-Challenge回应给接入设备;
(8)接入设备将Challenge,Challenged Password和用户名一起送到RADIUS服务器,由RADIUS服务器进行认证;
(9)RADIUS服务器根据用户信息,做MD5算法,判断用户是否合法,然后回应认证成功/失败报文到接入设备。如果成功,携带协商参数,以及用户的相关业务属性给用户授权。如果认证失败,则流程到此结束;
(10)如果认证通过,用户通过标准的DHCP协议 (可以是DHCP Relay) ,通过接入设备获取规划的IP地址;
(11)如果认证通过,接入设备发起计费开始请求给RADIUS用户认证服务器;
(12)RADIUS用户认证服务器回应计费开始请求报文,用户上线完毕。
freeradius是GNU/GPL(通用公共许可证)的原则下,开发的高性能开源radius服务器。常见的radius服务器种类不多,比较强大的当属开源的freeradius,世界上大部分的radius服务器都是基于freeradius开发而来的。
freeradius可以对支持radius协议的网络设备进行账户认证、授权和记账管理,常见的开源路由器操作系统:如Openwrt,DD-wrt等,都支持radius协议,常见的电信运营商的宽带账户,上网账户管理,记账,也都是使用的radius服务器进行鉴权记账的。
RADIUS服务器和NAS服务器通过UDP协议进行通信,RADIUS服务器的1812端口负责认证,1813端口负责计费工作。采用UDP的基本考虑是因为NAS和RADIUS服务器大多在同一个局域网中,使用UDP更加快捷方便,而且UDP是无连接的,会减轻RADIUS的压力,也更安全。
以下均在Ubuntu18上操作的,Ubuntu16上坑太多..看网上教程,CentOS更多..
1 安装Apache Web Server和PHP 在Ubuntu上安装Apache,运行以下命令安装Apache Web服务器:
1 sudo apt-get install apache2
要在Ubuntu 18.04上安装PHP,请运行(直接运行可能会不成功,因为没这个源 )
1 2 sudo apt-get install php libapache2-mod-php php-gd php-common php-mail \ php-mail-mime php-mysql php-pear php-db php-mbstring php-xml php-curl
PHP安装:
1 添加PHP PPA
添加ondrej/php,它包含PHP包和其他必需的PHP扩展
1 2 3 sudo apt-get install software-properties-common sudo add-apt-repository ppa:ondrej/php sudo apt-get update
通过复制以下代码并将其添加到系统的软件源中,可以手动将此PPA添加到系统中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 deb http://ppa.launchpad.net/ondrej/php/ubuntu bionic main deb-src http://ppa.launchpad.net/ondrej/php/ubuntu bionic main sudo vim /etc/apt/sources.list sudo apt update && sudo apt upgrade sudo apt-get install php libapache2-mod-php php-gd php-common php-mail \ php-mail-mime php-mysql php-pear php-db php-mbstring php-xml php-curl php -v
2 安装MariaDB并创建数据库 MariaDB是MySQL的一个分支,目前最新稳定版是10.5,以下是安装步骤
1 2 3 4 5 6 7 8 9 sudo apt-get install software-properties-common ssudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc' sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] https://mirrors.tuna.tsinghua.edu.cn/mariadb/repo/10.5/ubuntu bionic main' sudo apt update sudo apt -y install mariadb-server mariadb-client
安装并运行后,为FreeRADIUS创建一个数据库,这将在稍后阶段使用:
数据库名称:radius
数据库用户:radius
数据库用户密码:radiuspassword
如果你有专用数据库服务器,请将localhost替换为源FreeRadius服务器的IP:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 sudo mysql_secure_installation Switch to unix_socket authentication [Y/n] >> [直接Enter] 切换到unix_socket身份验证 Change the root password? [Y/n] y New password: Re-enter new password: Remove anonymous users ? [Y/n] >> [直接Enter] 是否删除匿名用户 Disallow root login remotely? [Y/n] >> [直接Enter] 禁止远程root角色登录 Remove test database and access to it? [Y/n] >> [直接Enter] 是否删除test 数据库 Reload privilege tables now? [Y/n] >> [直接Enter] 是否重新加载权限表 mysql -u root -p CREATE DATABASE radius; GRANT ALL ON *.* TO 'root' @'%' IDENTIFIED BY "password" ; GRANT ALL ON radius.* TO 'radius' @'localhost' IDENTIFIED BY "radiuspassword" ; flush privileges; \q
完全卸载MySQL/MariaDB
首先删除mysql:sudo apt-get remove mysql-*
然后清理残留的数据dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P
查看状态 sudo systemctl status mysql
启动 sudo systemctl start mysql
重启 sudo systemctl restart mysql
关闭 sudo systemctl stop mysql
3 安装和配置FreeRADIUS 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 sudo apt-get install freeradius freeradius-mysql freeradius-utils ps -ef | grep freeradius ll /etc/freeradius/3.0/mods-config/sql/main/mysql/schema.sql sudo chmod 666 /etc/freeradius/3.0/mods-config/sql/main/mysql/schema.sql mysql -u root -p radius < /etc/freeradius/3.0/mods-config/sql/main/mysql/schema.sql mysql -u root -p -e "use radius; show tables;" +------------------+ | Tables_in_radius | +------------------+ | nas | | radacct | | radcheck | | radgroupcheck | | radgroupreply | | radpostauth | | radreply | | radusergroup | +------------------+ sudo ln -s /etc/freeradius/3.0/mods-available/sql /etc/freeradius/3.0/mods-enabled/ sudo vim /etc/freeradius/3.0/mods-enabled/sql sql { driver = "rlm_sql_mysql" dialect = "mysql" server = "localhost" port = 3306 login = "radius" password = "radiuspassword" radius_db = "radius" read_clients = yes client_table = "nas" } sudo chgrp -h freerad /etc/freeradius/3.0/mods-available/sql sudo chown -R freerad:freerad /etc/freeradius/3.0/mods-enabled/sql sudo systemctl restart freeradius.service
4 安装和配置Daloradius 我们需要安装Daloradius才能获得FreeRADIUS Web管理界面
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 wget https://github.com/lirantal/daloradius/archive/master.zip unzip master.zip mv daloradius-master/ daloradiuscd daloradiusmysql -u root -p radius < contrib/db/fr2-mysql-daloradius-and-freeradius.sql mysql -u root -p radius < contrib/db/mysql-daloradius.sql cd ..sudo mv daloradius /var/www/html/ sudo chown -R www-data:www-data /var/www/html/daloradius/ sudo chmod 664 /var/www/html/daloradius/library/daloradius.conf.php sudo vim /var/www/html/daloradius/library/daloradius.conf.php CONFIG_DB_USER CONFIG_DB_PASS CONFIG_DB_NAME systemctl restart freeradius apache2
打开浏览器,访问**http://ip-address/daloradius/login.php
**
默认的管理员账户密码是 administrator:radius
查看syslog和daloradius.log时,可能会报错,修改syslog权限为644即可,加到用户组或许效果更好;至于daloradius.log去Config>Logging Settings中把想要监听的log设置成yes就好了
5 修改FreeRADIUS测试账户 FreeRADIUS的配置默认是文件,打开测试账户
1 2 3 4 5 6 7 8 9 10 11 sudo vim /etc/freeradius/3.0/users 73 steve Cleartext-Password := "testing" 74 Service-Type = Framed-User, 75 Framed-Protocol = PPP, 76 Framed-IP-Address = 172.16.3.33, 77 Framed-IP-Netmask = 255.255.255.0, 78 Framed-Routing = Broadcast-Listen, 79 Framed-Filter-Id = "std.ppp" , 80 Framed-MTU = 1500, 81 Framed-Compression = Van-Jacobsen-TCP-IP
配置路由器或交换机的账号
1 2 3 4 5 6 sudo vim /etc/freeradius/3.0/clients.conf client x.x.x.x { ipaddr = x.x.x.x secret = xxxxx }
重新开一终端
1 2 3 4 5 service freeradius restart radtest steve testing localhost 1812 testing123
这也确实,表明FreeRADIUS是通过文件进行配置的,接下来将其改为sql模式,上面改得差不多了,再改俩就行
修改配置文件/etc/freeradius/3.0/sites-enabled/default
1 找到authorize {
(273行),注释其中的files
,并将sql
去掉注释或-
2 找到preacct {
(555行),注释其中的files
3 找到accounting {
(608行),去掉sql
的注释或-
4 找到session {
(677行),去掉sql
的注释或-
5 找到post-auth {
(689行),去掉sql
的注释或-
6 找到pre-proxy {
(861行),注释掉files
修改配置文件/etc/freeradius/3.0/sites-enabled/inner-tunnel
,和上面一样,注释掉files
,去掉sql
的注释或-
1 2 3 4 service mysql restart service apache2 restart service freeradius restart
下面进行测试,直接进入MySQL可以通过Navicat或者直接终端(mysql -u root -p; use radius;
),输入下面的sql语句
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 # 创建用户组 INSERT INTO radius.radgroupreply (groupname, attribute, op, `value `) VALUES ('locahost' , 'Service-Type' , ':=' , 'Framed-User' );INSERT INTO radius.radgroupreply (groupname, attribute, op, `value `) VALUES ('locahost' , 'Framed-Protocol' , ':=' , 'PPP' );INSERT INTO radius.radgroupreply (groupname, attribute, op, `value `) VALUES ('locahost' , 'Framed-IP-Address' , ':=' , '192.168.1.109' );INSERT INTO radius.radgroupreply (groupname, attribute, op, `value `) VALUES ('locahost' , 'Framed-IP-Netmask' , ':=' , '255.255.255.0' );INSERT INTO radius.radgroupreply (groupname, attribute, op, `value `) VALUES ('locahost' , 'Framed-Routing' , ':=' , 'Broadcast-Listen' );INSERT INTO radius.radgroupreply (groupname, attribute, op, `value `) VALUES ('locahost' , 'Framed-Filter-Id' , ':=' , '"std.ppp"' );INSERT INTO radius.radgroupreply (groupname, attribute, op, `value `) VALUES ('locahost' , 'Framed-MTU' , ':=' , '1500' );INSERT INTO radius.radgroupreply (groupname, attribute, op, `value `) VALUES ('locahost' , 'Framed-Compression' , ':=' , 'Van-Jacobsen-TCP-IP' );# 创建用户 INSERT INTO radius.radcheck (username, attribute, op, `value `) VALUES ('user1' , 'Cleartext-Password' , '==' , 'password1' );# 将用户加入组 INSERT INTO radius.radusergroup (username, groupname) VALUES ('user1' , 'locahost' );
执行完之后,另打开一个终端进行本地测试
1 2 radtest user1 password1 localhost 1812 testing123
由于没有路由器和交换机,就只能再开一个Win虚拟机,进行测试,首先向/etc/freeradius/3.0/clients.conf
添加Win虚拟机的信息
1 2 3 4 5 6 sudo vim /etc/freeradius/3.0/clients.conf client 192.168.1.109 { ipaddr = 192.168.1.109 secret = justpwd }
好了,这时候,Win虚拟机上需要一个软件,NTRadPing,测试手法如下
天翼云:https://cloud.189.cn/t/AFJnYfy6Jbq2(访问码:kb1q)
蓝奏云:https://sidneygod.lanzous.com/iHcxEfxkqgf
RADIUS Server/port就填安装freeradius的ip和freeradius的默认端口1812
Reply timeout这一行就这样
RADIUS Secret key就是上面配置的secret值
User-Name和Password还是之前的user1和password1
其余不用管,点击send,右侧就会得到服务器返回的数据
毕竟我们有前端页面了,所以添加用户组和用户什么的,肯定不用手动去输MySQL语句,不友好。
添加用户组:Management > Profiles
添加用户:Management > Users
其实这些页面应该对应着数据库的操作..没咋研究,但是像client似乎比如通过配置文件,毕竟路由器没那么多吧..
还有,关于路由器和交换机的配置,由于手头没设备,没法玩..看教程,tplink的wap2能设置radius服务器信息
6 拾遗 6.1 环境问题 用Ubuntu16搞了一上午,php和MariaDB都不行,然后果断选择Ubuntu18,基本上没出啥错,哦,用的是清华源,不知道和这个有没有关系,本来觉得阿里源挺好,但是16上用的就是,想着换一下..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak sudo gedit /etc/apt/sources.list deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse sudo apt-get update && sudo apt upgrade
6.1 重启服务报错 用systemctl或者service进行重启freeradius时,有时候会报错,说启动不了。大概长这样子
1 2 Job for freeradius.service failed because the control process exited with error code. See "systemctl status freeradius.service" and "journalctl -xe" for details.
直接reboot就好 ,当然了,实在启动不了,也可以执行sudo freeradius -X
,可以看到调试信息
6.1 关于log daloradius有个Reports模块,默认显示四种log:daloRADIUS Log,Radius Log,System Log,Boot Log。其中前俩正常,就是后俩,syslog有这个文件,但是没权限;Boot Log显示的是dmesg,但Ubuntu18上却不是/var/log/dmesg
这个文件,而是/var/log/kern.log
于是,修改文件:/var/www/html/daloradius/library/exten-boot_log.php
,加三句话
1 2 3 4 5 6 7 8 9 10 11 $logfile_loc1 = '/var/log/dmesg'; $logfile_loc2 = '/usr/local/var/log/dmesg'; + $logfile_loc3 = '/var/log/kern.log'; if (file_exists($logfile_loc1)) $logfile = $logfile_loc1; else if (file_exists($logfile_loc2)) $logfile = $logfile_loc2; + else if (file_exists($logfile_loc3)) + $logfile = $logfile_loc3; else {
但是呢,还是有权限问题,因为syslog
和kern.log
,要是把这俩文件权限改为644倒是没问题,问题是重启就又不行了。顺带一提,mysql,apache2,freeradius都是开机自启的。不是syslog用户或adm组是没有读文件权限的,于是就把www-data
加到adm用户组了,问题解决
1 sudo gpasswd -a www-data adm
如果/var/log/
下连syslog,kern.log..都没有,查看/etc/rsyslog.d/50-default.conf
,是不是把那些log给禁用了,打开注释就好了
6.1 证书配置 参考:https://blog.csdn.net/lassewang/article/details/9159543