Architettura
Lo stack che uso per il provisioning PPPoE:
- FreeRADIUS 3.x su Debian 12 (VPS Hetzner CX23)
- MySQL 8 come backend per utenti e accounting
- MikroTik CCR2116 come NAS (Network Access Server)
- Comunicazione RADIUS su porta UDP 1812/1813
Installazione FreeRADIUS con MySQL
apt install freeradius freeradius-mysql mysql-server -y
Importa lo schema RADIUS nel database
mysql -u root -p << 'EOF'
CREATE DATABASE radius;
CREATE USER 'radius'@'localhost' IDENTIFIED BY 'PASSWORD_SICURA';
GRANT ALL ON radius.* TO 'radius'@'localhost';
EOF
mysql -u root -p radius < /etc/freeradius/3.0/mods-config/sql/main/mysql/schema.sql
Configurazione del modulo SQL
Modifica /etc/freeradius/3.0/mods-available/sql:
sql {
driver = "rlm_sql_mysql"
dialect = "mysql"
server = "localhost"
port = 3306
login = "radius"
password = "PASSWORD_SICURA"
radius_db = "radius"
acct_table1 = "radacct"
acct_table2 = "radacct"
postauth_table = "radpostauth"
authcheck_table = "radcheck"
groupcheck_table = "radgroupcheck"
usergroup_table = "radusergroup"
read_groups = yes
deletestalesessions = yes
sqltrace = no
num_sql_sockets = 5
}
Abilita il modulo:
ln -s /etc/freeradius/3.0/mods-available/sql /etc/freeradius/3.0/mods-enabled/sql
Aggiungere un client MikroTik
In /etc/freeradius/3.0/clients.conf:
client mikrotik-ccr2116 {
ipaddr = IP_DEL_TUO_MIKROTIK
secret = SECRET_CONDIVISO
shortname = isp-core
nas_type = other
}
Aggiungere un utente PPPoE
Tramite SQL direttamente:
INSERT INTO radcheck (username, attribute, op, value)
VALUES ('cliente01', 'Cleartext-Password', ':=', 'password123');
INSERT INTO radreply (username, attribute, op, value)
VALUES ('cliente01', 'Framed-IP-Address', ':=', '80.71.239.10');
INSERT INTO radreply (username, attribute, op, value)
VALUES ('cliente01', 'Framed-IP-Netmask', ':=', '255.255.255.0');
Configurazione MikroTik PPPoE server
/interface pppoe-server server
add interface=ether1-uplink service-name=isp-pppoe \
authentication=mschap2 \
default-profile=pppoe-profile
/radius
add address=IP_FREERADIUS secret=SECRET_CONDIVISO service=ppp
/ppp profile
set [find name=pppoe-profile] use-radius=yes
Test della configurazione
# Test autenticazione da riga di comando
radtest cliente01 password123 localhost 0 testing123
Output atteso:
Received Access-Accept Id 0 from 127.0.0.1:1812 to 0.0.0.0:0 length 20
Accounting e monitoring
Con l'accounting attivo su MySQL puoi vedere sessioni attive, traffico consumato e disconnessioni:
SELECT username, acctstarttime, acctinputoctets, acctoutputoctets
FROM radacct
WHERE acctstoptime IS NULL
ORDER BY acctstarttime DESC;
Conclusioni
Questo setup copre il provisioning base. Il passo successivo è integrarlo con il CRM (nel nostro caso FastAPI + Next.js) per automatizzare la creazione degli utenti alla firma del contratto e la disattivazione alla scadenza del pagamento.