Launcher Products Bitnami Documentationimaxe CLI Blog Contact
imaxe fail2ban bans v1.0.0

Bans under control, without touching fail2ban

Check and manage fail2ban bans from a single command: see which jails are active, who is banned, ban or unban IPs by hand and unblock in a pinch. Without remembering the syntax of fail2ban-client.

$ imaxe fail2ban status
Version
v1.0.0
Subcommands
7
Requires root
yes
JSON output
status · banned · check
Backend
fail2ban-client

What this module does #

fail2ban is the guardian that watches your server's logs and, when it detects malicious access attempts (for example, many SSH password failures), automatically bans the offending IP for a while. Each watched service is organized into a jail (for example sshd).

The fail2ban module gives you control of those bans at runtime, without having to remember the syntax of fail2ban-client: check the status of the jails, list who is banned, check whether a specific IP is blocked, ban or unban by hand, unblock everything at once in an emergency and reload the configuration after a change.

Before you start

This module acts on a fail2ban that is already installed and running. Every subcommand queries or modifies the state of the service, so they need root privileges (use sudo). If you've locked yourself out with your own IP, go straight to the emergency unblock.

Quick startstep-by-step tasks

Common tasks #

Pick what you want to do. Each recipe comes with the command ready to go — just swap the IP or the jail for yours, and hit Copy.

1

View the status and the jails

Check at a glance whether fail2ban is active and how many are banned.

Connect to your server over SSH as the ubuntu user and ask for the overall status:

terminal
$ sudo imaxe fail2ban status

Want it in machine-readable format, for a script or a dashboard? Add --json:

terminal
$ sudo imaxe fail2ban status --json
You'll see whether the service is active, the list of jails (such as sshd) and the number of banned IPs in each one.
2

See which IPs are banned

List the active bans, across all jails or just one.

All banned IPs, across every jail at once:

terminal
$ sudo imaxe fail2ban banned

Interested in only one jail? Give it as an argument:

terminal
$ sudo imaxe fail2ban banned sshd
You get the list of blocked IPs. If any is legitimate, take it to the Ban or unban recipe.
3

Check whether an IP is banned

Find out in which jails a specific address is blocked.

Ask directly about the IP; it will tell you in which jails it appears banned:

terminal
$ sudo imaxe fail2ban check 203.0.113.7
You'll instantly know whether that IP is blocked and in which jails. Use it before unbanning someone who reports access problems.
4

Ban or unban an IP

Block an abusive address by hand or free a legitimate user.

Ban an IP in a specific jail (if there's only one jail, it is inferred automatically):

terminal
$ sudo imaxe fail2ban ban 203.0.113.7 --jail sshd

Banned someone legitimate? Unban them from all jails at once:

terminal
$ sudo imaxe fail2ban unban 203.0.113.7
The change takes effect immediately. Confirm it with imaxe fail2ban check on that same IP.
5

Unblock everything (emergency)

You're locked out: free all IPs from all jails.

If your own IP got caught and you need to regain access now, unban them all. Add --yes to skip the confirmation:

terminal
$ sudo imaxe fail2ban unban-all --yes

After a change to the jail configuration, reload it so it takes effect:

terminal
$ sudo imaxe fail2ban reload
All jails are left with no bans. It's a temporary measure: fail2ban will ban the abusive ones again as soon as they reoffend.
Careful with unban-all

It's a destructive ban operation: it leaves all IPs unblocked, malicious ones included. Use it only to regain access in an emergency and check the status afterwards with imaxe fail2ban status.

CLI referencecommands, flags and files

Synopsis #

usage
imaxe fail2ban <subcomando> [<ip>|<jail>] [--jail JAIL] [flags]

Every subcommand requires root privileges (use sudo) because they query or modify the state of fail2ban through fail2ban-client. Add --json to status, banned or check for machine-readable output, suitable for scripting.

Subcommands #

SubcommandWhat it doesRelevant flags
statusfail2ban status: active, jails and number of banned IPs per jail.--json
bannedLists the banned IPs (all jails or a specific one).--json
checkIndicates in which jails an IP is banned.--json
banManually bans an IP in a jail.--jail
unbanUnbans an IP from all jails.
unban-allEMERGENCY: unbans ALL IPs from all jails.--yes
reloadReloads the fail2ban configuration (validates jail.local).

Arguments and flags #

Argument / FlagTypeDefaultDescription
<ip> req.stringThe IP to operate on. Required in check, ban and unban.
<jail>stringtodasIn banned, a specific jail to list. Without an argument, all jails are listed.
--jailstringautoIn ban, the target jail for the ban. If there's only one jail, it is inferred automatically.
--yesboolfalseIn unban-all, confirms without asking (destructive ban operation).
--jsonboolfalseIn status/banned/check, emits the result as JSON on stdout.

Files and paths #

PathContents
/etc/fail2ban/jail.localLocal fail2ban configuration: active jails, ban times and thresholds. What reload validates.
/var/run/fail2ban/fail2ban.sockControl socket that fail2ban-client uses to talk to the service.
/var/log/fail2ban.logfail2ban's own log: bans, unbans and reloads.

Exit codes and logs #

Each run returns a code you can check with echo $? — handy for chaining in scripts:

0OKOperation completed successfully.
1ERRGeneric unclassified error. Check the log.
2USAGEInvalid or missing arguments.
3SERVICEfail2ban is not active or not responding on the socket.
4JAILThe specified jail doesn't exist or couldn't be inferred.
5RELOADThe configuration doesn't validate; it was not reloaded.

Follow the log live while you troubleshoot:

terminal
$ sudo journalctl -u fail2ban -f
$ sudo tail -f /var/log/fail2ban.log

Troubleshooting #

SymptomLikely causeFix
You get SERVICE (code 3)fail2ban is stopped or the socket isn't responding.Start the service with systemctl start fail2ban and retry.
You get JAIL (code 4)The --jail jail doesn't exist, or there are several and it can't be inferred.Look at the jails with imaxe fail2ban status and give the correct one in --jail.
You get RELOAD (code 5)There's a syntax error in jail.local.Fix /etc/fail2ban/jail.local and run reload again.
I got locked out over SSHYour own IP accumulated failures and got banned in sshd.From another route, unban it with unban or free them all with unban-all --yes.

Stuck with the Fail2ban module?

Write to us with the output of «imaxe <module> status --json» and we'll get back to you fast.

Contact support