CentOS7 搭建Radius认证服务器
一. 概述
本手册是实现如下功能:CentOS7上部署 freeradius 服务、radius 简单使用、堡垒机实现radius用户认证。
二. CentOS7 环境准备
1. 设置网络
- # 设置网络,使用的NetworkManager的nmtui自动分配的网络,这里不详细说明了,配好网络的可以跳过
- # nmtui
- # 关闭防火墙、selinux
- systemctl stop firewalld
- systemctl disable firewalld
- sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
- setenforce 0
复制代码 2. 安装基础工具
- # 安装数据库、vim 等应用和工具
- # yum不行可以切换阿里源
- yum groupinstall "Development tools" -y
- yum install telnet net-tools -y
- yum install httpd mariadb-server -y
- yum install php php-mysql php-gd php-ldap php-odbc -y
- yum install php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap -y
- yum install vim -y
- yum install lsof -y
复制代码 三. 安装 FreeRadius
安装 freeradius 并启动 mariadb、http
1. 安装 freeradius
- yum install freeradius freeradius-mysql freeradius-utils -y
复制代码 2. 启动 mariadb、http 服务
- # systemctl start mariadb
- systemctl restart mariadb
- systemctl restart httpd
复制代码 四. MySQL 数据库配置
1. 对 MySQL 数据库进行初始化
- # Y Y N Y Y / Y Y N N Y
- mysql_secure_installation
复制代码 2. 创建 radius 数据库并设置暗码
- mysql -uroot -p
- create database radius;
- # 这个PASSWORD是密码,可以自定义换成自己的
- grant all privileges on radius.* to radius@localhost identified by 'PASSWORD';
- use radius;
- source /etc/raddb/mods-config/sql/main/mysql/schema.sql;
- quit;
复制代码 3. 重启数据库- dailordius
- systemctl restart mariadb
- ln -s /etc/raddb/mods-available/sql /etc/raddb/mods-enabled/
- chgrp -h radiusd /etc/raddb/mods-enabled/sql
复制代码 4. 修改 freeradius 配置文件
4.1 修改radiusd.conf
- vim /etc/raddb/radiusd.conf
- # 将下面三项内容修改为 yes
- auth = no
- auth_badpass = no
- auth_goodpass = no
- # 修改为
- auth = yes
- auth_badpass = yes
- auth_goodpass = yes
复制代码 4.2 修改default
- vim /etc/raddb/sites-available/default
- 1)将
- -sql
- 修改为
- sql
- 2)查找到 session { 中内容
- 去掉 sql 前面的注释
复制代码 4.3 修改sql
- vim /etc/raddb/mods-available/sql
- 1)将
- driver = "rlm_sql_null"
- 修改为
- driver = "rlm_sql_mysql"
- (2)将
- dialect = "sqlite"
- # server = "localhost"
- # port = 3306
- # login = "radius"
- # password = "radpass"
- 修改为
- dialect = "mysql"
- server = "localhost"
- port = 3306
- login = "radius"
- # PASSWORD输入上面MySQL里设置的密码
- password = "PASSWORD"
- (3)将
- # read_clients = yes
- 修改为
- read_clients = yes
复制代码 5. debug 调试
出现以下情况表现正常:
- Listening on auth address * port 1812 bound to server default
- Listening on acct address * port 1813 bound to server default
- Listening on auth address :: port 1812 bound to server default
- Listening on acct address :: port 1813 bound to server default
- Listening on auth address 127.0.0.1 port 18120 bound to server inner-tunnel
- Listening on proxy address * port 55876
- Listening on proxy address :: port 44691
- Ready to process requests
复制代码 报错可以使用radiusd -C 检查配置文件或者查看日志/var/log/radius/radius.log,查看端口netstat -tunlp | grep radius等方法处置处罚
6. 启动 radius
- systemctl restart radiusd
- # 可能会出现启动失败地方情况,原因是端口被自己占用,以下方法解决
- # lsof -i :1812
- # kill 加上端口进程 ID
- # systemctl start radiusd
复制代码 五. 配置 daloradius
1. 上传文件解压移动
- tar zxvf daloradius-0.9-9.tar.gz
- mv daloradius-0.9-9 /var/www/html/daloradius
- chown -R apache:apache /var/www/html/daloradius/
- chmod 664 /var/www/html/daloradius/library/daloradius.conf.php
- cd /var/www/html/daloradius/
复制代码 2. 导入数据库
- mysql -u radius -p radius < contrib/db/fr2-mysql-daloradius-and-freeradius.sql
- 输入密码:PASSWORD
- mysql -u radius -p radius < contrib/db/mysql-daloradius.sql
- 输入密码:PASSWORD
复制代码 3. 修改 daloradis 数据库连接文件
- vim /var/www/html/daloradius/library/daloradius.conf.php
- 将
- $configValues['FREERADIUS_VERSION'] = '2';
- $configValues['CONFIG_DB_USER'] = 'root';
- $configValues['CONFIG_DB_PASS'] = '';
- 修改为:
- $configValues['FREERADIUS_VERSION'] = '2';
- $configValues['CONFIG_DB_USER'] = 'radius';
- $configValues['CONFIG_DB_PASS'] = 'PASSWORD';
- # 注意:如果版本修改为3的话,将不显示连接日志
复制代码 4. 安装 php-pear-DB
- # 说明:Centos 7 默认没有 php-pear-DB 安装包,否则无法进入 daloradius 为空白
- yum -y install epel-release
- yum -y install php-pear-DB
复制代码 5. 重启服务
- systemctl restart mariadb.service
- systemctl restart radiusd.service
- systemctl restart httpd
复制代码 6. 配置日志查询
- chmod 644 /var/log/messages
- chmod 755 /var/log/radius/
- chmod 644 /var/log/radius/radius.log
- touch /tmp/daloradius.log
- chmod 644 /tmp/daloradius.log
- chown -R apache:apache /tmp/daloradius.log
复制代码 7. 访问 daloradius
- http://IP/daloradius 访问
- 用户名:administrator
- 密码:radius
复制代码 六. 使用
Daloradius 配置用户及 NAS
1. 增加 vpn 账号及暗码
2. 增加 nas 信息
- NAS IP 0.0.0.0/0
- NAS-Secert:testing123
- NAS Type:other
- NAS Shortname :radius-network
- 其中0.0.0.0/0 表示任意 IP 都可以连接到 radius
- testing123 设置连接 radius 的共享密钥
复制代码
- #上面 nas 配置完成需要重启 radiusd 才能生效
- systemctl restart radiusd
复制代码 3. 测试账号连通性
测试之前添加一个用户
- radtest [用户] [密码] [访问的 ip] [端口] [密钥]
- radtest jack 1234567890 127.0.0.1 1812 testing123
复制代码 出现下面表现,代表连接乐成:
- Sent Access-Request Id 63 from 0.0.0.0:38938 to 127.0.0.1:1812 length 74
- User-Name = "jack"
- User-Password = "1234567890"
- NAS-IP-Address = 127.0.0.1
- NAS-Port = 1812
- Message-Authenticator = 0x00
- Cleartext-Password = "1234567890"
- Received Access-Accept Id 63 from 127.0.0.1:1812 to 0.0.0.0:0 length 20
复制代码 七. Radius 应用
1. radius 在堡垒机中可以实现哪些功能
- AAA 服务 可提供认证、授权、计费等功能
- 同一认证 对于工作人员的同一认证管理
- 双因素认证 使用radius和OTP认证方式实现口令+动态暗码的方式实现双因素认证
以上就是本次分享的内容,有错误的地方接待指出
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |