// Engineering Log
080 | Classic Brute-Force Protection: Fail2ban
Published on 2025-08-12
// Fast route
This article belongs to the topic Security and protection.
Introduction: Server Security — The First Line of Defense
Once you deploy any server or virtual machine, one of the first and most important tasks is ensuring its security. Even if your server doesn’t contain critical data, it can still be targeted by automated bots constantly scanning the internet for vulnerabilities. The most common type of attack against any server is brute-force password guessing, typically aimed at SSH access, FTP services, or web control panels.
There are many tools available to combat this threat, and one of the most popular, simple, and effective solutions is Fail2ban.
What is Fail2ban and How Does It Work?
Fail2ban is an open-source intrusion prevention framework written in Python. Its primary job is to scan server log files, detect suspicious IP addresses that make too many failed login attempts, and temporarily block them.
Fail2ban’s logic is straightforward and consists of three key components:
- Filters: These are regular expressions used by Fail2ban to analyze log files. Filters search for lines matching failed login attempts. For example, for an SSH server, a filter would look for entries in
/var/log/auth.logsuch as"Failed password for...". - Jails: A jail is a rule set that links a specific filter to an action. An SSH jail uses the SSH filter and takes an action to block the offending IP address.
- Actions: These are the commands executed when suspicious activity is detected. This is where Fail2ban interacts with the firewall to actually block the IP address.
Fail2ban and Firewalls: iptables vs. nftables
To temporarily block an IP address, Fail2ban modifies the host’s firewall rules. Historically, Fail2ban was closely tied to iptables, but modern Linux distributions increasingly favor nftables.
iptables(classic approach):iptableshas long been the standard tool for managing firewalls on Linux. By default, Fail2ban usesiptablesto insert temporary rules denying access from offending IPs. For example, it can add a rule that drops (DROP) all traffic from a blocked IP on port 22 (SSH). This method is reliable and time-tested.nftables(modern approach):nftablesis a newer, more flexible, and more efficient replacement foriptables. It provides a unified syntax and allows dynamic rule updates without reloading the entire firewall. Fail2ban fully supportsnftables, and for fresh installations, this backend is often preferred. You can specify whether Fail2ban should useiptablesornftablesin its configuration.
Advantages of Fail2ban
- Simple and reliable: Easy to install and configure. Predefined filters and jails for popular services (SSH, Nginx, Apache, Postfix) make it almost a “plug-and-play” solution.
- Effective: It’s highly efficient at mitigating brute-force attacks, instantly blocking repeated login attempts and reducing server load.
- Lightweight: Runs in the background, using minimal memory and CPU, making it ideal for small servers and VPS environments.
- Flexible: Custom filters can be created for any application that generates logs, enabling protection even for non-standard services.
Limitations of Fail2ban
- Log-based detection: Fail2ban doesn’t analyze network traffic in real time—it only reacts to events after they’re recorded in log files, introducing a slight delay.
- Basic attack prevention: Great against simple, repetitive attacks but less effective against sophisticated, distributed brute-force attempts from multiple IPs.
- No centralized intelligence: Fail2ban works independently on each server. It has no knowledge of attacks on your other servers or the broader internet and cannot share threat data with others.
Conclusion
Fail2ban is an essential baseline security tool for every server. Its simplicity, effectiveness, and low resource consumption make it an ideal first line of defense. It excels at stopping common brute-force attacks by leveraging the power of iptables or nftables.
However, for building a more robust and modern defense system—especially against distributed threats—you’ll need more advanced tools. In the next article, we’ll look at CrowdSec, a modern solution that takes a crowdsourced approach to server security.
// Similar task
If you are dealing with something similar
This article belongs to one of the main working topics. You can keep reading on the topic, go to the homepage to understand what I do, or open the service pages directly.
Article topic
Security and protection
SSL, hardening, access control, service protection, and secure configurations.
Typical tasks behind this topic
- Set up SSL, certificates, and secure connections
- Restrict access and close unnecessary entry points
- Harden server and service configuration
// Next step
If you need help with this topic, not just another article, it is better to go straight to the service page. The homepage and topic collection stay available as secondary routes.
Open services// Reviews
Related reviews
There were several issues concerning both the technical side and overall understanding. Mikhail responded quickly, resolved the technical problems, and helped me understand them — many thanks. I'm satisfied with the result.
There were several issues concerning both the technical side and overall understanding. Mikhail responded quickly to the request, helped sort things out and resolved the technical problems and helped clarify …
VPS setup, server setup
2026-02-18 · ★ 5/5
Everything was done quickly and efficiently. I recommend.
Everything was done quickly and efficiently. I recommend.
VPS setup, server setup
2026-01-17 · ★ 5/5
Everything went well; the contractor responded quickly to questions and helped resolve the issue. Thanks!
Everything went well, the contractor responded quickly to questions and helped resolve the issue. Thank you!
VPS setup, server setup
2025-12-16 · ★ 5/5
Everything was done promptly. We'll use them again. Highly recommend!
Everything was done promptly. We'll continue to use their services. I recommend!
VPS setup, server setup
2025-12-10 · ★ 5/5
Everything was done promptly. Mikhail is always available. We'll continue to contact him.
Everything was done promptly. Mikhail is always available. We'll continue to reach out
VPS setup, server setup
2025-12-10 · ★ 5/5
Mikhail is a professional! He's shown this in practice more than once.
Mikhail, a professional! Not the first time he's demonstrated this in practice.
// Contact
Need help?
Get in touch with me and I'll help solve the problem
// Related