Building a Powerful RADIUS Server with FreeRADIUS and Django for MikroTik Devices
If you're managing MikroTik routers and network access, you know how crucial authentication and user management are for securing your network. Today, I want to share a project I built — a robust RADIUS server powered by FreeRADIUS and Django, designed specifically to handle MikroTik logins with advanced user permissions and device management.
Why Build a Custom RADIUS Server?
While FreeRADIUS is a powerful open-source RADIUS server, integrating it with your business logic, user management, and device policies often requires customization. Especially for MikroTik networks, where device grouping, IP restrictions, and granular user permissions matter, a tailored solution provides better control and scalability.
By combining FreeRADIUS's reliable authentication engine with Django’s flexible web framework, I built a system that meets complex requirements:
-
User Permissions & Status: Store hashed passwords securely. Manage active/inactive user status so that only valid users get network access.
-
IP Restriction: Limit login attempts based on allowed IP addresses for users, enhancing security by preventing unauthorized device access.
-
Device Grouping: Group MikroTik devices and define user access based on device groups. Users can only authenticate to devices within their permitted groups.
-
Comprehensive User Management: A web interface powered by Django for managing users, devices, and groups easily.
-
Hashing & Security: Passwords are stored hashed (with industry best practices), protecting sensitive data.
-
Seamless MikroTik Integration: Compatible with RouterOS and MikroTik’s login mechanisms.
How It Works
-
FreeRADIUS Backend
FreeRADIUS handles the RADIUS protocol itself—authenticating users and managing sessions. It’s configured to communicate with a Django backend through a database or a custom interface. -
Django Web Application
The Django app stores all user credentials, device information, and groups in a database. It also manages permissions, IP address restrictions, and user statuses. When FreeRADIUS receives an authentication request, it queries Django's database to validate users. -
Device Group Access Control
Each MikroTik device belongs to one or more device groups. Users have permissions assigned per device group. This means you can allow or deny access to devices on a per-group basis. -
User Authentication Flow
When a MikroTik router receives a login request, it forwards it to FreeRADIUS. FreeRADIUS checks the user’s password, status, allowed IPs, and device group permissions from Django. If all checks pass, the user is authenticated; otherwise, access is denied.
Key Features
1. Hashed Password Storage
Passwords are never stored in plain text. I implemented hashing using secure algorithms so even if the database is compromised, passwords remain safe.
2. User Active/Inactive Status
Administrators can deactivate users instantly without deleting them. Inactive users cannot authenticate until reactivated.
3. Allowed IP Restrictions
Users can only login from specific IP addresses or IP ranges, preventing unauthorized access.
4. Device Grouping
Group devices logically (e.g., by location, department, or type). Assign user access to these groups to simplify permissions management.
5. User-Friendly Django Admin
A clean Django admin interface provides easy management of users, groups, devices, and policies.
Why This Setup Is Ideal for MikroTik Networks
MikroTik RouterOS supports RADIUS for authentication, but default setups don’t provide granular user and device group control out of the box. This custom solution fills that gap, giving you:
-
Fine-grained access control
-
Better security with IP restrictions
-
Easier user and device management
-
Scalable architecture for large deployments
What’s Next?
This project is live in my production environment, supporting multiple MikroTik devices and hundreds of users with zero issues so far.
If you’re interested in building a similar setup or want to learn more about integrating FreeRADIUS with Django for network authentication, feel free to reach out!
Download: Click Here
About Me
I’m a network engineer and developer passionate about combining open-source tools and custom development to solve real-world networking challenges. Follow my blog for more projects and tutorials on network automation, security, and Python development.