GoAdmio

fail2ban

Install and configure Fail2ban to ban brute-force sources against SSH, FTP, SMTP, and Dovecot

On this page: Overview · Quick start · Syntax · Options · Output · Examples · Troubleshooting · Details · See also


Overview

/go/fail2ban installs Fail2ban if it isn't already, then writes four jail configuration files — SSH, FTP, SMTP, and Dovecot — and restarts the service. Each jail reuses the server's IP whitelist (see white) as its ignoreip list.

[!WARNING] Every run, including a plain /go/fail2ban with no arguments, unbans every currently banned IP on the server, not only /go/fail2ban clear. There's no way to update the jail configuration or whitelist without also clearing the current ban list. See Known issues.

The call is appended to /var/log/go/fail2ban.log.


Quick start

# Install (if needed) and configure the standard jails
/go/fail2ban

Syntax

/go/fail2ban
/go/fail2ban clear
Form Behavior
/go/fail2ban Installs Fail2ban if missing, writes all four jail files, unbans everyone, and restarts the service.
/go/fail2ban clear Unbans every IP and restarts the service. Does not touch the jail files. Exits immediately after.

Any other first argument is ignored; the command behaves the same as with no arguments.


Options

None. The whitelist used for ignoreip comes from /var/go/etc/white, managed with white, not from a command-line option here.


Output

The command prints nothing of its own. fail2ban-client and the package manager print their own progress and errors.

# Check jail status afterwards
sudo fail2ban-client status
sudo fail2ban-client status sshd

Examples

# Set up or refresh the standard jails
/go/fail2ban
# Unban everyone without touching the jail configuration
/go/fail2ban clear
# Check who is currently banned
sudo fail2ban-client status sshd

Troubleshooting

Symptom Likely cause Fix
Everyone who was banned is suddenly unbanned Expected. Every run, not just clear, unbans all IPs. See Known issues. If you need bans to persist across configuration changes, don't re-run this command casually.
Jail files weren't written /etc/fail2ban/jail.d doesn't exist, usually because Fail2ban didn't install correctly. Check command -v fail2ban-client and the package manager's output.
The SMTP or Dovecot jail never bans anyone on Debian or Ubuntu Both jails are hardcoded to logpath = /var/log/maillog, which is the RHEL-family path. Debian and Ubuntu normally log mail to /var/log/mail.log. Edit /etc/fail2ban/jail.d/smtp.conf and dovecot.conf to point at the real mail log on your system, then restart Fail2ban.
The FTP jail never bans anyone vsftpd isn't installed, or it logs somewhere other than /var/log/vsftpd.log. Confirm vsftpd is in use and check its actual log path.
An IP that should be whitelisted still gets banned The IP in /var/go/etc/white doesn't match one of the supported wildcard patterns (see Whitelist conversion), or it was added after the last run. Check the pattern, then run /go/fail2ban again to regenerate the jail files.
fail2ban-client: command not found Something failed during install. Install Fail2ban manually for your OS and run the command again.
Hand-edited jail files lost their changes Every run overwrites all four jail files from scratch. Keep custom settings in a separate .conf file under jail.d, not in ssh.conf, ftp.conf, smtp.conf, or dovecot.conf.

Details

Jails written

File Jail Port(s) maxretry findtime bantime
jail.d/ssh.conf sshd (default) 30 3600s (1h) 86400s (24h)
jail.d/ftp.conf vsftpd ftp,ftp-data,ftps,ftps-data 30 not set (jail.conf default) 1h
jail.d/smtp.conf postfix-sasl smtp,ssmtp,submission,465,587 5 3600s (1h) 1h
jail.d/dovecot.conf dovecot pop3,pop3s,imap,imaps,submission,465,sieve 5 3600s (1h) 1h

Every jail is written with enabled = true and the same ignoreip line. All four files are overwritten on every run, whether or not Fail2ban needed installing.

Whitelist conversion

The ignoreip list always starts with 127.0.0.1/8 ::1. If /var/go/etc/white exists, each line is added, with wildcard-style entries converted to CIDR:

In the whitelist file Becomes
a.b.c.* a.b.c.0/24
a.b.* a.b.0.0/16
a.* a.0.0.0/8
Anything else (a plain IP, an existing CIDR, an IPv6 address) Passed through unchanged

A pattern with more than one * (such as 10.*.*.*) isn't converted and is passed through unchanged, which Fail2ban will not treat as a valid address or range.

Known issues


See also

Command Description
white Add an IP to the whitelist
block Block an IP address on a GoAdmio server
unblock Unblock an IP address on a GoAdmio server
blacklist Block blacklisted IPs (bad bots and SSH brute-force attacks)
sshtop Report top SSH brute-force sources and optionally block them
sasltop Report SASL LOGIN authentication failures and block persistent sources
firewall Install a firewall on a GoAdmio server