When you expose any service to the internet, brute-force attacks are not a matter of if but when. SSH servers see thousands of failed login attempts per day from botnets scanning the entire IPv4 space. Web applications face credential stuffing and directory enumeration. Without automated protection, your server wastes resources on malicious traffic and eventually risks compromise.
This guide compares three self-hosted intrusion prevention systems: Fail2Ban (the battle-tested standard), SSHGuard (the lightweight alternative), and CrowdSec (the modern crowdsourced solution). We’ll cover architecture, deployment, configuration, and help you choose the right tool for your infrastructure.
For a broader view of network security, see our Suricata vs Snort vs Zeek IDS/IPS guide for deep packet inspection, and our pfSense vs OPNsense firewall router guide for perimeter defense.
Why Self-Host Intrusion Prevention
Cloud providers offer managed WAF and DDoS protection, but they can’t replace local log-based intrusion prevention at the server level. Self-hosted tools:
- Monitor local log files in real-time for authentication failures, 404 scanning, rate limit violations, and other suspicious patterns
- Automatically ban offending IPs via iptables, nftables, or firewall APIs before damage is done
- Work behind any reverse proxy — they don’t depend on cloud infrastructure
- Provide granular control over ban duration, threshold levels, and notification preferences
- Are completely free with no per-request pricing or bandwidth limits
Unlike network-level IDS/IPS systems that inspect packet payloads, these tools work by parsing application logs and reacting to patterns — making them complementary to, not a replacement for, tools like Suricata or Zeek.
Fail2Ban: The Battle-Tested Standard
Fail2Ban (17,600+ stars, updated April 2026) has been the go-to intrusion prevention tool since 2004. It monitors log files, applies configurable filters (regex patterns), and bans IPs that exceed a threshold of failures.
How Fail2Ban Works
- Log monitoring — Tail specified log files (auth.log, nginx access.log, etc.)
- Filter matching — Apply regex filters to detect failed authentication, scanning, or other suspicious patterns
- Jail enforcement — When a filter matches N times within a time window, trigger an action (typically iptables DROP)
- Auto-unban — After a configurable ban duration, remove the block automatically
Docker Deployment
Fail2Ban doesn’t ship an official Docker Compose file, but the LinuxServer.io image provides a production-ready setup:
| |
The network_mode: host is critical — Fail2Ban needs to modify the host’s iptables/nftables rules, which requires direct network namespace access.
Configuration Example
| |
Fail2Ban Strengths
- 150+ pre-built filters — SSH, Apache, Nginx, Postfix, Dovecot, WordPress, and more
- Massive community — Any log format you can think of has a filter
- Mature and stable — 20+ years of development, extremely reliable
- Flexible actions — Can ban via iptables, nftables, send email, run custom scripts
- Simple to understand — The jail/filter/action model is straightforward
Fail2Ban Limitations
- No built-in dashboard — CLI-only (
fail2ban-client status) - No IP reputation data — Only reacts to what it sees locally
- Single-node only — Each server independently discovers and bans IPs
- Regex-based filters — Can be brittle; complex log formats require custom regex
SSHGuard: The Lightweight Alternative
SSHGuard (78 stars) takes a minimalist approach. Instead of parsing diverse log formats with complex regex, it hooks directly into system log mechanisms (syslog, systemd journal) and monitors for repeated authentication failures across multiple services.
How SSHGuard Works
- Log ingestion — Reads from syslog or journalctl natively (no tail + regex)
- Pattern detection — Built-in parsers for SSH, FTP, SMTP, IMAP, POP3, and HTTP authentication failures
- IP blocking — Adds offending IPs to firewall rulesets via pf, iptables, ipfw, or netfilter
- Auto-unban — Removes blocks after the configured penalty period
Docker Deployment
SSHGuard also lacks an official Docker image, but can be run via community images:
| |
Configuration Example
| |
For a custom filter on Nginx, SSHGuard uses a simpler pattern-matching approach:
| |
SSHGuard Strengths
- Extremely lightweight — Written in C, minimal CPU and memory footprint
- No regex complexity — Built-in parsers are faster and more reliable than regex
- Simple configuration — Single config file with clear options
- Multi-protocol support — SSH, FTP, SMTP, IMAP, POP3 out of the box
- Permanent blacklist — Can maintain a persistent blacklist of repeat offenders
SSHGuard Limitations
- Small community — Fewer contributors and less active development
- Limited filter extensibility — Adding support for new log formats requires C code changes
- No crowdsourced intelligence — Purely local detection
- Fewer pre-built integrations — Doesn’t cover as many services as Fail2Ban
CrowdSec: The Modern Crowdsourced Solution
CrowdSec (13,160+ stars, updated April 2026) represents a paradigm shift in intrusion prevention. Instead of each server independently discovering threats, CrowdSec shares IP reputation data across its entire user base. If one user’s server detects a malicious IP, all other CrowdSec users are protected from it.
How CrowdSec Works
- Log parsing — Uses YAML-based parsers (not regex) to extract structured events from logs
- Scenario detection — Apply behavioral scenarios (brute-force, port scan, web crawl) to parsed events
- Local decisions — Ban IPs locally via bouncers (iptables, nginx, Traefik, Cloudflare)
- Community sharing — Anonymously share detected malicious IPs with the CrowdSec network
- Global intelligence — Receive IP reputation scores from the community CTI (Cyber Threat Intelligence) database
Docker Deployment
CrowdSec provides official Docker images and a recommended Docker Compose setup:
| |
Acquisition Configuration
| |
Scenario Example
| |
Nginx Bouncer Integration
To block malicious IPs at the reverse proxy level:
| |
CrowdSec Strengths
- Crowdsourced IP intelligence — 100M+ shared IP reputations from the community
- Structured YAML parsers — More reliable and maintainable than regex
- Built-in dashboard — Metabase integration provides visual analytics
- Flexible bouncer architecture — Block at iptables, nginx, Traefik, HAProxy, Cloudflare, or AWS WAF level
- API-first design — Full REST API for integration with other tools
- Active development — 13,000+ stars, frequent releases, growing ecosystem
CrowdSec Limitations
- More complex setup — Parser/bouncer/scenario architecture has a steeper learning curve
- Requires internet access — Community sharing needs outbound connectivity (can run in local-only mode but loses crowdsourced benefits)
- Higher resource usage — More CPU and memory than SSHGuard or Fail2Ban
- Privacy considerations — Shares detected IPs with the community (anonymized, but still a consideration)
Comparison Table
| Feature | Fail2Ban | SSHGuard | CrowdSec |
|---|---|---|---|
| Stars / Activity | 17,600+ / Active | 78 / Low | 13,160+ / Very Active |
| Language | Python | C | Go |
| Log Parsing | Regex filters | Built-in parsers | YAML parsers |
| Crowdsourced IPs | No | No | Yes (100M+ shared) |
| Web Dashboard | No (CLI only) | No (CLI only) | Yes (Metabase) |
| Services Covered | 150+ | ~10 | 50+ via collections |
| Docker Support | Community image | Community image | Official image |
| Blocking Methods | iptables, nftables | iptables, pf, ipfw | iptables, nginx, Traefik, Cloudflare |
| IP Blacklist | Manual | Persistent file | Local + community |
| API | CLI client | None | Full REST API |
| Resource Usage | Low | Very Low | Moderate |
| Learning Curve | Easy | Easy | Moderate |
| Best For | General-purpose servers | Minimal SSH protection | Modern infra with dashboards |
How to Choose
Choose Fail2Ban if:
- You need broad service coverage (150+ filters)
- You want the simplest, most battle-tested solution
- Your infrastructure is small-to-medium (single servers or a few nodes)
- You don’t need a web dashboard
Choose SSHGuard if:
- You primarily need SSH protection
- Resource usage is a critical concern (IoT, edge devices, low-memory VPS)
- You prefer minimal configuration and C-level performance
- You want a permanent blacklist for repeat offenders
Choose CrowdSec if:
- You value crowdsourced threat intelligence
- You want a visual dashboard for security analytics
- You’re running modern infrastructure (Kubernetes, containers, cloud)
- You need API integration with other security tools
- You want to block at multiple layers (host, reverse proxy, CDN)
Recommended Architecture
For a production server, the most robust setup combines CrowdSec with a reverse proxy bouncer:
| |
This blocks malicious IPs at the reverse proxy level before they even reach your application, while the CrowdSec agent continuously learns from the community threat feed.
For simpler setups (single VPS running SSH + a few services), Fail2Ban with its pre-built jails is the path of least resistance. Install, enable the sshd and nginx-http-auth jails, and you’re protected within minutes.
FAQ
Is Fail2Ban still relevant in 2026?
Yes. Fail2Ban remains the most widely deployed intrusion prevention tool. Its 150+ pre-built filters cover virtually every common service, and its maturity means it works reliably out of the box. For many use cases, it’s still the best choice despite newer alternatives.
Can I run multiple intrusion prevention tools at the same time?
Yes, but with caution. Running Fail2Ban and CrowdSec together is possible since they use different detection mechanisms. However, running two tools that both modify iptables can cause conflicts — one tool might unban an IP that the other still wants blocked. If you run CrowdSec, it’s generally recommended to disable Fail2Ban for the same services.
Does CrowdSec work offline without internet access?
CrowdSec can run in local-only mode without sharing data with the community. You lose access to the crowdsourced IP reputation database, but local detection and banning still work normally. This is suitable for air-gapped networks or strict privacy requirements.
How much system resources does each tool consume?
SSHGuard is the lightest, typically using less than 5 MB of RAM and near-zero CPU. Fail2Ban uses 20-50 MB RAM depending on the number of active jails. CrowdSec uses 100-300 MB RAM due to its Go runtime, parser pipeline, and database. For resource-constrained systems, SSHGuard or Fail2Ban are the better choices.
Can these tools protect web applications against credential stuffing?
Fail2Ban and CrowdSec can both detect and block credential stuffing attacks by monitoring HTTP authentication failures in web server logs. CrowdSec has built-in scenarios specifically for HTTP credential stuffing, while Fail2Ban requires custom filter configuration for this use case. SSHGuard does not support HTTP log parsing.
What’s the difference between intrusion prevention and IDS/IPS?
Intrusion prevention tools like Fail2Ban, SSHGuard, and CrowdSec work at the application log level — they parse authentication logs and web access logs to detect and ban malicious IPs. Network IDS/IPS systems like Suricata and Snort inspect packet payloads at the network level to detect attack signatures. They serve complementary roles: IDS/IPS catches network-level attacks, while log-based tools catch application-level abuse. For full-stack security, also consider runtime security monitoring with Falco and web application protection with BunkerWeb.