On this page
- What does this setup give you?
- What do you need before installing?
- How do you install FreeRADIUS and PostgreSQL?
- How do you create the radius database and load the schema?
- How do you point the sql module at PostgreSQL?
- How do you add users, groups and NAS clients?
- How do you test that authentication works?
- Which firewall rules should you add?
- How do you maintain and troubleshoot it?
- Questions
What does this setup give you?
You get one central place that answers the question "may this user connect, and with which settings?" for every network device that speaks RADIUS. Wi-Fi access points using WPA2 or WPA3 Enterprise, VPN concentrators, switches with 802.1X and hotspot controllers all act as RADIUS clients (called NAS in the FreeRADIUS world). Each one forwards a login attempt to UDP port 1812 and, if accounting is on, reports session start, interim and stop records to UDP port 1813.
Keeping users in PostgreSQL instead of the flat users file means you can add, disable or regroup people with a single SQL statement or from a small admin script, and every accounting record lands in a table you can query for reports. FreeRADIUS reads the database at request time, so changes apply without a restart.
What do you need before installing?
Start with a fresh Ubuntu 24.04, Ubuntu 22.04, Debian 12 or Debian 13 server, a sudo user (see your first SSH session) and the public IPv4 addresses of the devices that will talk to it. A small plan is plenty for a few hundred users: RADIUS packets are tiny, and PostgreSQL with a modest table set needs little memory. Update the system first:
sudo apt update && sudo apt upgrade -yUbuntu 24.04 and both Debian releases ship FreeRADIUS 3.2, while Ubuntu 22.04 carries 3.0.26. The configuration directory is /etc/freeradius/3.0 on all of them, so the steps below match each release. Check what the archive offers before you install:
apt policy freeradius postgresqlHow do you install FreeRADIUS and PostgreSQL?
Install the server, the PostgreSQL driver module, the client tools for testing and the database itself in one command:
sudo apt install -y freeradius freeradius-postgresql freeradius-utils postgresql
freeradius -v | head -n 1
psql --version
systemctl status freeradius postgresql --no-pagerThe package starts freeradius.service right away with its default file based setup. That is fine for now; you will switch it to SQL in a moment. If the service failed to start, the most common reason is that another process already holds port 1812. sudo ss -ulpn | grep 181 shows who is listening.
How do you create the radius database and load the schema?
Create a dedicated role with a strong password and a database owned by that role, then load the PostgreSQL schema bundled with FreeRADIUS while logged in as the new role, so the tables belong to it:
sudo -u postgres psql -c "CREATE ROLE radius WITH LOGIN PASSWORD 'Change-This-Long-Secret';"
sudo -u postgres createdb -O radius radius
sudo cat /etc/freeradius/3.0/mods-config/sql/main/postgresql/schema.sql | psql -h 127.0.0.1 -U radius -d radius
psql -h 127.0.0.1 -U radius -d radius -c "\dt"The last command should list nas, radacct, radcheck, radgroupcheck, radgroupreply, radpostauth, radreply and radusergroup. The connection goes over 127.0.0.1, which the default pg_hba.conf on Debian and Ubuntu allows with password (scram) authentication, so the database never needs to listen on the public address. For more on roles and grants, read PostgreSQL roles.
How do you point the sql module at PostgreSQL?
Edit the module file, set the dialect, driver and credentials, and turn on reading clients from the nas table:
sudo nano /etc/freeradius/3.0/mods-available/sqlThe relevant lines inside the sql { ... } block should read:
dialect = "postgresql"
driver = "rlm_sql_${dialect}"
server = "127.0.0.1"
port = 5432
login = "radius"
password = "Change-This-Long-Secret"
radius_db = "radius"
read_clients = yes
client_table = "nas"The stock file contains a mysql { tls { ... } } subsection; it only affects the MySQL driver and can stay as it is. Enable the module by linking it into mods-enabled and fix ownership so the freerad user can read the password:
sudo ln -s ../mods-available/sql /etc/freeradius/3.0/mods-enabled/sql
sudo chown -h freerad:freerad /etc/freeradius/3.0/mods-enabled/sql
sudo chgrp freerad /etc/freeradius/3.0/mods-available/sql
sudo chmod 640 /etc/freeradius/3.0/mods-available/sqlThe default virtual server in sites-enabled/default already calls -sql in the authorize, accounting, session and post-auth sections. The leading minus means "skip if the module is missing", so once the link exists those calls become active without further edits.
How do you add users, groups and NAS clients?
Users live in radcheck (attributes that must match, such as the password) and radreply (attributes sent back on success). Groups work the same way through radgroupcheck, radgroupreply and the mapping table radusergroup:
psql -h 127.0.0.1 -U radius -d radius <<'SQL'
INSERT INTO radcheck (username, attribute, op, value)
VALUES ('alice', 'Cleartext-Password', ':=', 'Alice-Wifi-2026');
INSERT INTO radgroupreply (groupname, attribute, op, value)
VALUES ('staff', 'Session-Timeout', ':=', '28800');
INSERT INTO radusergroup (username, groupname, priority)
VALUES ('alice', 'staff', 1);
INSERT INTO nas (nasname, shortname, type, secret)
VALUES ('203.0.113.10', 'office-ap', 'other', 'Shared-Secret-For-AP');
SQLClients from the nas table are read once when the server starts, so restart after adding one. Pick a long random shared secret per device; the RADIUS protocol hides passwords with it, and a weak secret weakens every login. If your devices use EAP methods such as PEAP, the user still sits in radcheck with a Cleartext-Password or an NT-Password hash, and the EAP certificates are configured in mods-available/eap.
How do you test that authentication works?
Run the server in debug mode once, because it prints every module, query and decision on screen. Stop the service, start the foreground debugger, and watch for "Ready to process requests":
sudo systemctl stop freeradius
sudo freeradius -XIn a second SSH window, send a test request from the server to itself. The default clients.conf already trusts localhost with the secret testing123:
radtest alice Alice-Wifi-2026 127.0.0.1 0 testing123A working setup returns Received Access-Accept and lists Session-Timeout = 28800 taken from the group. A wrong password returns Access-Reject. When the result looks right, press Ctrl+C in the debug window and bring the service back:
sudo systemctl enable --now freeradius
sudo systemctl status freeradius --no-pagerCheck accounting the same way after a real device connects: SELECT username, acctstarttime, acctstoptime FROM radacct ORDER BY radacctid DESC LIMIT 5; should show its sessions.
Which firewall rules should you add?
Allow UDP 1812 and 1813 only from the addresses of your NAS devices; nothing else on the internet has a reason to reach them. Keep PostgreSQL closed, since it only listens on localhost. On Ubuntu or Debian with ufw:
sudo ufw allow from 203.0.113.10 to any port 1812,1813 proto udp
sudo ufw status numberedIf you manage nftables directly, the same idea is covered in firewall rules and the ufw guide. Devices behind a home or office connection with a changing address are a poor fit for an allow list; put them behind a WireGuard tunnel and let them reach RADIUS over the tunnel address instead.
How do you maintain and troubleshoot it?
Updates arrive through the normal package flow, so sudo apt upgrade keeps both FreeRADIUS and PostgreSQL patched. After any edit under /etc/freeradius/3.0, check the syntax before restarting:
sudo freeradius -XC
sudo systemctl restart freeradius
sudo journalctl -u freeradius -n 50 --no-pagerThe radacct table grows with every session. Archive or delete old rows on a schedule, for example everything older than a year, and run VACUUM ANALYZE radacct; afterwards. Back up the database with pg_dump alongside your other data; the optional daily backups described in daily backups cover the whole disk as well.
Typical problems: "Ignoring request from unknown client" means the NAS address or secret does not match a row in nas or an entry in clients.conf, or you forgot to restart after adding it. "Failed to connect to database" points at a wrong password or host in the sql module. A reject with no SQL lines in the debug output means the module link is missing.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
Questions about FreeRADIUS with PostgreSQL
Can I keep some clients in clients.conf and others in the database?
Yes. FreeRADIUS merges both sources at startup. Many admins keep localhost and a few fixed devices in clients.conf and put everything that changes often in the nas table.
Should I store passwords in clear text?
PAP requests can be checked against hashed values such as SHA2-Password or Crypt-Password. MSCHAPv2 and PEAP need either the clear text or an NT-Password hash, so the method your devices use decides what you can store. Restrict database access tightly either way.
Does this work over IPv6?
Yes. FreeRADIUS listens on both families by default, and you can add NAS entries with IPv6 addresses. Remember to add the matching firewall rule for the IPv6 source as well.
Why does radtest work but my access point gets no answer?
Usually the firewall drops the packet, the NAS row has the wrong address (for example a private address while the device reaches you through NAT), or the secret differs. Run freeradius -X and look for the request; if nothing appears, the packet never arrived.
How do I disable a user without deleting them?
Add a radcheck row with attribute Auth-Type, op := and value Reject. Delete that row later to let them back in.
Can PostgreSQL run on a separate server?
It can, but you then expose the database across the network. Connect over a tunnel or TLS and allow the port only from the RADIUS server. For most setups one server holding both is simpler.
More in Networking and diagnostics
- IPv6 on your server
- The ip command
- DNS lookups with dig
- Listening ports with ss and netstat
- Test ports and transfer data with netcat
- Trace network paths with mtr
- Capture packets with tcpdump
- Live bandwidth with iftop and nethogs
- HTTP requests with curl
- Dynamic DNS updates from a server
- Latency graphs with SmokePing
- Traffic analysis with ntopng
- Check which ports are reachable