Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 04/24/2007
In this article I will show how to install and configure fail2ban on a Debian Etch system. Fail2ban is a tool that observes login attempts to various services, e.g. SSH, FTP, SMTP, Apache, etc., and if it finds failed login attempts again and again from the same IP address or host, fail2ban stops further login attempts from that IP address/host by blocking it with an iptables firewall rule.
This document comes without warranty of any kind! I want to say that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!
Fail2ban is similar to DenyHosts which I covered in this tutorial: http://www.howtoforge.com/preventing_ssh_dictionary_attacks_with_denyhosts, but unlike DenyHosts which focuses on SSH, fail2ban can be configured to monitor any service that writes login attempts to a log file, and instead of using /etc/hosts.deny to block IP addresses/hosts, fail2ban uses iptables.
In this example I will configure fail2ban to monitor login attempts to the SSH server, the Proftpd server, login attempts to .htaccess/.htpasswd protected web sites, to Courier POP3 and Courier IMAP, and to SASL (for sending emails). I will install the fail2ban package that is available for Debian Etch. It comes with a default configuration, but unfortunately that configuration doesn’t quite work for most of the aforementioned services. Therefore I will create a customized fail2ban configuration that I have tested and that works for me.