Architecting a Collaborative Defense: Integrating CrowdSec with Mikrotik

In this post, we’ll move beyond static firewall rules and integrate CrowdSec with Mikrotik RouterOS v7. We are shifting from a traditional "set-and-forget" firewall to an Intelligence-Driven Defense that reacts to global threats in real-time.

The Goal

To offload the heavy lifting of log analysis to a dedicated Debian 12 LXC and use the Mikrotik API to dynamically block malicious IPs at the edge. This setup ensures your router stays fast while benefiting from a global community of threat intelligence.

Why CrowdSec?

  • Behavioral Analysis: It doesn't just look at IPs; it looks at patterns (e.g., SSH brute force).
  • Community Powered: If an IP is banned in Europe or the US, it’s automatically added to your Mikrotik’s blacklist.
  • Resource Efficient: The LXC does the "thinking," the Mikrotik does the "dropping."
Architect's Note: This setup is perfect for homelabs running on low-resource hardware. We avoid the CPU overhead of running heavy IDS/IPS rules directly on the router.

1. Provisioning the Debian LXC

Standard Debian 12 (Bookworm) template on Proxmox. 512MB RAM is plenty.

# Add CrowdSec Repo
curl -s https://install.crowdsec.net | os=debian dist=bookworm bash

# Install Engine and Mikrotik Bouncer
apt update && apt install crowdsec crowdsec-mikrotik-bouncer -y

2. Mikrotik Side Setup

We need to allow the LXC to talk to the router. Use a restricted user for security.

# Enable API
/ip service set api port=8728 disabled=no

# Create restricted group and user
/user group add name=crowdsec-api policy=api,read,write,test
/user add name=crowdsec-agent group=crowdsec-api password="YourSecurePassword"

3. Configuring the Bouncer

Edit the bouncer config to bridge the two systems: /etc/crowdsec/bouncers/crowdsec-mikrotik-bouncer.yaml

hosts:
  - address: "192.168.88.1:8728" # Mikrotik IP
    user: "crowdsec-agent"
    password: "YourSecurePassword"
    address_list: "CrowdSec_Blacklist"
    update_interval: 10s

Restart to apply: systemctl restart crowdsec-mikrotik-bouncer

4. The Firewall Rule

The "Enforcer" rule. This drops packets at the L3 level using the dynamic list.

/ip firewall filter
add chain=input action=drop src-address-list=CrowdSec_Blacklist comment="DROP: CrowdSec Global Threats"
add chain=forward action=drop src-address-list=CrowdSec_Blacklist comment="DROP: CrowdSec Forwarding"

Verification

Check the Mikrotik's IP > Firewall > Address Lists. You should see the CrowdSec_Blacklist populating with IPs. On the LXC, run cscli decisions list to see active bans.


Found this helpful? Check out my other deep-dives into Proxmox and Networking on Pinoy Tech Share.

Comments

Popular posts from this blog

Suricata on Mikrotik(IDS+IPS) = Part 4 - Configuration of the IPS Part

DHCP for Dummies: How Your Devices Get Online Without You Lifting a Finger

AdGuard Home DNS for Newbies - Part 3