CentOS7 搭建Radius认证服务器

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 调试

radiusd -X

出现以下情况表示正常:

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 在堡垒机中可以实现哪些功能

  1. AAA 服务 可提供认证、授权、计费等功能
  2. 统一认证 对于工作人员的统一认证管理
  3. 双因素认证 使用radius和OTP认证方式实现口令+动态密码的方式实现双因素认证

以上就是本次分享的内容,有错误的地方欢迎指出

以下是在CentOS 7上搭建公网邮件服务器的步骤: 1. 安装必要的软件包: ```shell yum install postfix dovecot cyrus-sasl-* mailx -y ``` 2. 移除Sendmail(如果已安装): ```shell yum remove -y sendmail ``` 3. 配置Postfix: 编辑主配置文件`/etc/postfix/main.cf`,确保以下配置项正确设置: ```shell myhostname = your_domain.com # 设置你的域名 mydomain = your_domain.com # 设置你的域名 myorigin = $mydomain inet_interfaces = all inet_protocols = all mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain mynetworks = 0.0.0.0/0 home_mailbox = Maildir/ ``` 4. 配置Dovecot: 编辑Dovecot的邮件配置文件`/etc/dovecot/conf.d/10-mail.conf`,取消注释并添加以下行: ```shell mail_location = maildir:~/Maildir ``` 5. 配置SASL认证: 编辑SASL配置文件`/etc/postfix/sasl/smtpd.conf`,确保以下配置项正确设置: ```shell pwcheck_method: saslauthd mech_list: plain login ``` 6. 启动和设置服务: ```shell systemctl start postfix systemctl enable postfix systemctl start dovecot systemctl enable dovecot systemctl restart saslauthd systemctl enable saslauthd ``` 7. 配置防火墙: 如果你的服务器上启用了防火墙,确保允许SMTP(端口25)和IMAP(端口143)流量通过防火墙。 8. 创建邮件用户: ```shell useradd -m -s /sbin/nologin username # 替换username为你想要创建的用户名 passwd username # 设置用户密码 ``` 现在你已经成功搭建了CentOS 7上的公网邮件服务器
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值