ServerAvatarDocs
Servers

Fail2ban

Install Fail2ban on a server, turn on its jails, set the ban rules, keep trusted addresses safe, and ban or unban IP addresses.

Fail2ban bans IP addresses that keep failing to sign in to your server. Open Fail2ban in the server's sidebar. Central shows and changes the Fail2ban of the server itself. Once it is installed, the page refreshes itself about every 10 seconds, so bans appear as they happen.

The installed page has two tabs: Protection (the jails and Banned IPs) and Ban rules (the ban rules and the never-ban list).

The Fail2ban page on the Protection tab with the SSH and Repeat offenders jails and the Banned IPs list

Install Fail2ban

If Fail2ban is not on the server, the page says "Fail2ban isn't installed".

  1. Select Install Fail2ban.
  2. Wait. The page says "Installing Fail2ban…" and updates itself when done. It usually takes about a minute. If it takes longer, the page says "This is taking longer than usual. It may still be working."

If the install fails, the page shows "The install failed", the reason and a reference. "Nothing has changed on your server — you can try again." Select Try again.

When Fail2ban is installed, the header shows Running or Not running and the version. If it is stopped, the page says "Nobody is banned while it is stopped." Select Go to Services to start it again (see Services).

Set up protection in one step

When no jail is on, the card Your server is not protected yet offers Set up protection. It turns on the recommended jails and adds ServerAvatar's address to the never-ban list, so ServerAvatar cannot be locked out. You see "Protection is on."

Turn jails on and off

A jail watches one service. In Jails, use the switch (Enable name) of each jail you want.

  • SSH (sshd) bans an address that gets the SSH password or key wrong too many times. It is marked Can lock you out.
  • Repeat offenders (recidive): "An address banned 3 times in a day is banned from every service for a week."

Each jail shows Off, On, "n failing" or "n banned", and the card shows the totals since Fail2ban started ("n wrong tries, n bans").

When you turn on a jail that can ban ServerAvatar's own address, the dialog Keep ServerAvatar's address safe first asks you to add the address to the never-ban list. Select Add it and turn on. The field is filled with the address ServerAvatar connects from, when it is known. Select Turn on anyway only if you accept that ServerAvatar may lose access to the server.

Set the ban rules

Open the Ban rules tab. The Ban rules card applies to every jail.

The Ban rules tab with the Ban rules card (Banned for, Counted within, Wrong tries allowed and Rule preview) and the Never ban these addresses card

  1. Choose Banned for: Forever or a time of at least 1 minute.
  2. Set Counted within (seconds): a whole number from 30 to 86400. Older tries are forgotten.
  3. Set Wrong tries allowed: a whole number from 2 to 100.
  4. Check the Rule preview, for example "With these values, 5 wrong tries in 10 minutes would ban an address for the time you chose."
  5. Select Save ban rules. You see "Ban rules saved."

If a change could lock ServerAvatar out, the page says "This could lock ServerAvatar out" and offers Save anyway.

Never ban an address

In Never ban these addresses, add the addresses that Fail2ban must never ban, such as your office or ServerAvatar's own address.

  1. Enter an IP address or range, for example 203.0.113.5 or 203.0.113.0/24.
  2. Select Add address. You see "ip added. Fail2ban will not ban it." and the change applies within a few seconds.
  3. To remove an address, select Remove ip.

If ServerAvatar's address is not on the list, the page warns that a jail may ban it, and offers Add ServerAvatar's address. The address that belongs to ServerAvatar is marked with a ServerAvatar badge. The list holds at most 100 addresses.

See and unban banned addresses

Banned IPs lists who is banned right now: IP address, Jail, Banned (how long ago) and Expires ("n minutes left", Permanent, Ending now or Not known). Use Search address and the All jails filter to narrow it down.

  • Select Unban on a row and confirm Unban ip? The address can reach the server straight away. Fail2ban bans it again if it trips the same rules.
  • Select Unban all to unban every address.
  • For IPv6 addresses the row says "Use Unban all for IPv6 addresses".

Ban an address by hand

  1. Select Ban IP.
  2. Enter one IP address. Ranges are not allowed here.
  3. Choose the Jail that holds the ban. Turn on a jail first if none is on.
  4. Select Ban. You see "ip banned." The ban lasts for the current ban time.

The server does not ban ServerAvatar's own address ("This is ServerAvatar's address. The server won't ban it — that would lock ServerAvatar out.") or the server's own address ("Banning it would lock every tool out of the server.").

Limits

  • Ban time: Forever, or at least 60 seconds.
  • Counted within: 30 to 86400 seconds.
  • Wrong tries allowed: 2 to 100.
  • Never-ban list: up to 100 addresses or ranges.
  • A manual ban takes one IP address, not a range.

Who can do this

  • Seeing the page needs View on Fail2ban. Installing, turning jails on or off, saving rules, the never-ban list and banning or unbanning need Manage. Without it the page says "Your role can view this page but not change it."

Common errors

  • Fail2ban isn't installed on this server. Install it from the server's Fail2ban page first. Another screen called Fail2ban before it was installed.
  • That is not a valid IP address or range. (never-ban list)
  • That is not a valid IP address. Ranges are not allowed here. (ban)
  • Turn on a jail first — a ban needs a jail to hold it.
  • That is the most addresses this list can hold (100). Remove one to add another.
  • That address is not banned any more — nothing changed.

On this page