How to Install and Configure FreeRADIUS with MariaDB on CentOS Stream 9

Context: The Authentication Challenge When Scaling an Organization

Picture this: your office has just crossed the 80-employee mark. Every time an employee leaves, the IT team has to rotate the office-wide Wi-Fi password. Then comes the tedious task of distributing the new password to every department so they can re-enter it across dozens of phones and laptops. To make matters worse, managing manual accounts scattered across individual firewalls and routers for the internal VPN turns network administration into an absolute nightmare.

This is why the RADIUS (Remote Authentication Dial-In User Service) protocol has become the enterprise standard. Access Points (APs) and VPN Gateways don’t need to store credentials locally. Instead, all network devices (acting as RADIUS Clients / NAS) forward authentication requests to a single, centralized server: FreeRADIUS.

Pairing FreeRADIUS with MariaDB on CentOS Stream 9 delivers a robust, standardized AAA (Authentication, Authorization, and Accounting) architecture. User accounts, passwords, group permissions, and active sessions are neatly managed within database tables. This makes it effortless to write Python automation scripts to revoke access upon HR notifications or plug in an intuitive web management UI.

Enterprise Linux infrastructure demands uncompromising stability. When CentOS 8 reached EOL, I had to urgently migrate five server clusters to Rocky Linux in just one week. The biggest takeaway from that experience: mastering service architecture and standard configurations on RHEL/CentOS-family systems will save you from sleepless on-call nights.

Installing Components on CentOS Stream 9

The system consists of two core components: freeradius and mariadb-server, joined by the freeradius-mysql bridge module.

Step 1: Update the OS and Install Packages

Log in to your CentOS Stream 9 terminal with root privileges and run:

# Update repositories and install MariaDB, FreeRADIUS, and the MySQL module
dnf update -y
dnf install -y mariadb-server freeradius freeradius-mysql freeradius-utils

The freeradius-utils package provides the radtest utility. This CLI tool simulates network devices sending authentication packets, letting you test your setup rapidly without touching physical APs.

Step 2: Start and Secure MariaDB

Enable and start the MariaDB service on system boot:

systemctl enable --now mariadb
mysql_secure_installation

The security wizard will prompt you to set a database root password, remove anonymous users, disallow remote root logins, and drop the test database. Simply follow the on-screen instructions.

Configuring FreeRADIUS to Sync with MariaDB

Bước 1: Initialize the Database and Import the FreeRADIUS Schema

FreeRADIUS includes standard SQL schema files out of the box in its configuration directory. Log in to MariaDB to create the dedicated database and user:

mysql -u root -p

Execute the following commands to create the radius database and grant privileges to radius_user:

CREATE DATABASE radius;
CREATE USER 'radius_user'@'localhost' IDENTIFIED BY 'MatKhauCucKyKhoNho123!';
GRANT ALL ON radius.* TO 'radius_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Next, import FreeRADIUS’s default table structure into your newly created database:

mysql -u radius_user -p'MatKhauCucKyKhoNho123!' radius < /etc/raddb/mods-config/sql/main/mysql/schema.sql

Step 2: Configure the SQL Module for Database Connectivity

Open the FreeRADIUS SQL driver configuration file:

vi /etc/raddb/mods-available/sql

Locate the sql { ... } configuration block and update the connection parameters:

sql {
    dialect = "mysql"
    driver = "rlm_sql_mysql"

    server = "localhost"
    port = 3306
    login = "radius_user"
    password = "MatKhauCucKyKhoNho123!"
    radius_db = "radius"

    # Enable reading client definitions from the nas table
    read_clients = yes
    client_table = "nas"
}

Then, create a symlink to enable the SQL module and set the correct file ownership:

ln -s /etc/raddb/mods-available/sql /etc/raddb/mods-enabled/
chgrp -h radiusd /etc/raddb/mods-enabled/sql

Step 3: Define Network Devices (RADIUS Clients / NAS)

Any Access Point or VPN Router forwarding authentication requests must share a secret key to perform a secure handshake with the server. You can store clients directly in the database’s nas table or declare them in /etc/raddb/clients.conf.

Here is an example configuring a UniFi Access Point (IP 192.168.1.200) and the local loopback interface for testing (127.0.0.1) in /etc/raddb/clients.conf:

client localhost {
    ipaddr = 127.0.0.1
    secret = Testing123
    require_message_authenticator = no
    nas_type = other
}

client office_ap {
    ipaddr = 192.168.1.200
    secret = SecretRadiusKey2026
    shortname = AP_Tang2
}

Step 4: Create a Test User Account

With the SQL module active, user credentials are stored in the radcheck table. Insert a test user nhanvien01 using a Cleartext-Password attribute:

mysql -u radius_user -p'MatKhauCucKyKhoNho123!' -D radius -e "INSERT INTO radcheck (username, attribute, op, value) VALUES ('nhanvien01', 'Cleartext-Password', ':=', 'VpNWifi@2026');"

Testing the Service & Production Operations

Step 1: Run in Debug Mode to Catch Configuration Errors

An essential real-world tip: don’t rush to run systemctl start radiusd right away. If syntax errors or improper file permissions exist, the service will terminate silently without clear indicators. Instead, stop the service and run FreeRADIUS directly in Debug Mode:

# Ensure the background daemon is stopped
systemctl stop radiusd

# Start in detailed debug mode
radiusd -X

Your terminal will display verbose logs covering module initialization and MySQL connection status. When you see the line Ready to process requests. at the bottom, your server is ready to accept traffic.

Step 2: Verify Authentication with the radtest Command

Open a second SSH session to the server and fire a test authentication packet:

radtest nhanvien01 VpNWifi@2026 127.0.0.1 0 Testing123

If your settings are correct, you will receive an almost instantaneous response:

Sent Access-Request Id 141 from 0.0.0.0:41785 to 127.0.0.1:1812 length 79
Received Access-Accept Id 141 from 127.0.0.1:1812 to 0.0.0.0:0 length 20

The Received Access-Accept message confirms that FreeRADIUS successfully queried and validated the user from MariaDB. You can now return to the first terminal and press Ctrl + C to exit debug mode.

Step 3: Configure Firewall Ports and Enable the Service

FreeRADIUS listens on UDP port 1812 for authentication and UDP port 1813 for accounting. Allow both ports through the firewall so remote Access Points can connect:

firewall-cmd --permanent --add-port=1812/udp
firewall-cmd --permanent --add-port=1813/udp
firewall-cmd --reload

systemctl enable --now radiusd

Step 4: Monitor Logs and Active Sessions

In production environments with Enterprise Wi-Fi (WPA2/WPA3-Enterprise 802.1X) or OpenVPN, inspect real-time Access-Reject logs using:

tail -f /var/log/radius/radius.log

Additionally, complete user session histories are tracked in MariaDB’s radacct table. This allows you to query active connection times, assigned IP addresses, and consumed data volumes for transparent auditing across all client workstations.

Share: