Commands

fail2ban-client commands

fail2ban-client is the command-line tool that controls the fail2ban server. This page covers its syntax and options, the commands you will use every day with real output, and the complete list of all 96 commands.

Updated 14 min readChecked against fail2ban 1.1.1

fail2ban-client sends commands to the running fail2ban server over its Unix socket. The syntax is fail2ban-client [OPTIONS] <COMMAND>, and it needs root. The most used commands are sudo fail2ban-client status (list jails), status <jail> (failures and bans), set <jail> unbanip <IP>, set <jail> banip <IP> and reload. Run fail2ban-client -h to print every command your installed version supports.

bash
sudo fail2ban-client status                       # list jails
sudo fail2ban-client status sshd                  # one jail: failures, bans, banned IPs
sudo fail2ban-client set sshd banip 203.0.113.42  # ban an IP
sudo fail2ban-client set sshd unbanip 203.0.113.42
sudo fail2ban-client reload                       # re-read configuration

fail2ban-client syntax#

text
fail2ban-client [OPTIONS] <COMMAND>

<COMMAND> is a sequence of words such as status sshd or set sshd bantime 1h. Three verbs cover most of it:

  • Server and jail control: start, stop, restart, reload, status, ping.
  • get reads a setting: get loglevel (server-wide) or get <jail> bantime (per jail).
  • set changes a setting at runtime: set loglevel DEBUG or set <jail> maxretry 3.

Runtime set changes take effect immediately but are not saved. The next reload or restart applies whatever is in your configuration files again, so put permanent changes in /etc/fail2ban/jail.local — see the jail.local example.

The jail name is the section name in your configuration ([sshd], [nginx-http-auth], [recidive]), not the filter file name. If you mistype it, the client tells you:

output
$ sudo fail2ban-client status sshdx
... ERROR   NOK: ('sshdx',)
Sorry but the jail 'sshdx' does not exist

Global options#

Options go before the command. These are the ones from fail2ban-client -h in 1.1.1:

Option What it does
-c, --conf <DIR> Use another configuration directory (default /etc/fail2ban)
-s, --socket <FILE> Socket path (default /var/run/fail2ban/fail2ban.sock)
-p, --pidfile <FILE> PID file path
-d Dump the parsed configuration and exit — useful for debugging
--dp, --dump-pretty Same as -d, more readable
-t, --test Test the configuration and exit
-i Interactive mode (a fail2ban> prompt)
-v / -q Increase / decrease verbosity (repeatable: -vvv)
-x Force start: remove a stale socket file first
-b / -f Start the server in background (default) / foreground
--loglevel <LEVEL>, --logtarget <TARGET> Override logging when starting the server
--str2sec <STRING> Convert a time abbreviation to seconds and exit
-h, --help Print options and all commands
-V, --version Print the version (-V prints a short machine-readable form)

A few of these are worth knowing by heart:

output
$ sudo fail2ban-client --version
Fail2Ban v1.1.1
bash
# test the configuration without touching the running server
sudo fail2ban-client -t

# show exactly what fail2ban will load for each jail
sudo fail2ban-client -d | grep sshd

# how many seconds is 1d12h?
fail2ban-client --str2sec 1d12h

-t prints OK: configuration test is successful, or the errors and ERROR: test configuration failed. More on that in testing your configuration.

Interactive mode#

fail2ban-client -i opens a prompt where you type commands without the fail2ban-client prefix. Type help for the command list and exit or quit to leave. It's handy when you run many get/set commands in a row:

text
$ sudo fail2ban-client -i
fail2ban> status sshd
fail2ban> get sshd maxretry
fail2ban> exit

Status and listing jails#

output
$ sudo fail2ban-client status
Status
|- Number of jail:	2
`- Jail list:	recidive, sshd
output
$ sudo fail2ban-client status sshd
Status for the jail: sshd
|- Filter
|  |- Currently failed:	2
|  |- Total failed:	6
|  `- File list:	/var/log/auth.log
`- Actions
   |- Currently banned:	1
   |- Total banned:	1
   `- Banned IP list:	203.0.113.42

Since 1.1.0 you can also get every jail at once with status --all and a compact table with stats. Each field is explained on the fail2ban status page.

Command Output
status Number of jails and their names
status <jail> Failures, bans and banned IPs for one jail
status <jail> short Same, without the banned IP list
status --all Server status plus every jail (1.1.0+)
stats One table: backend, failed and banned counts per jail (1.1.0+)
ping Server replied: pong if the server is alive

Ban and unban commands#

output
$ sudo fail2ban-client set sshd banip 192.0.2.15 192.0.2.16
2
$ sudo fail2ban-client set sshd unbanip 192.0.2.15
1
$ sudo fail2ban-client unban 192.0.2.16
1

banip and unbanip print the number of addresses they changed, not OK. unban <IP> (without a jail) removes the address from every jail and from the database; unban --all clears everything. Details and edge cases: unban an IP and ban an IP manually.

To see what is banned:

output
$ sudo fail2ban-client banned
[{'sshd': ['203.0.113.42']}, {'recidive': []}]
$ sudo fail2ban-client banned 203.0.113.42
[['sshd']]
$ sudo fail2ban-client get sshd banip --with-time
203.0.113.42 	2026-10-25 18:36:10 + 3600 = 2026-10-25 19:36:10

More ways to list banned IPs, including from the firewall and the database.

fail2ban-client get: read jail settings#

get <jail> <option> shows the value the running jail actually uses — after jail.conf, jail.d/ and jail.local have been merged. That makes it the quickest way to check whether your override took effect.

output
$ sudo fail2ban-client get sshd bantime
3600
$ sudo fail2ban-client get sshd findtime
600
$ sudo fail2ban-client get sshd maxretry
3
$ sudo fail2ban-client get sshd logpath
Current monitored log file(s):
`- /var/log/auth.log
$ sudo fail2ban-client get sshd actions
The jail sshd has the following actions:
nftables

Times are always printed in seconds, even if you wrote 1h in the config. Other useful get commands: get <jail> ignoreip, get <jail> failregex, get <jail> journalmatch, get <jail> usedns, and server-wide get loglevel, get logtarget, get dbfile, get dbpurgeage.

fail2ban-client set: change settings at runtime#

output
$ sudo fail2ban-client set sshd bantime 86400
86400
$ sudo fail2ban-client set sshd addignoreip 192.168.1.0/24
These IP addresses/networks are ignored:
|- 127.0.0.0/8
|- 192.168.1.0/24
`- ::1

Useful runtime changes:

bash
sudo fail2ban-client set sshd maxretry 3
sudo fail2ban-client set sshd findtime 1h
sudo fail2ban-client set sshd delignoreip 192.168.1.0/24
sudo fail2ban-client set loglevel DEBUG
sudo fail2ban-client set sshd idle on      # pause the jail without stopping it

Remember: these vanish on reload. Copy them into jail.local once you are happy with them. The jail options reference lists what each setting does.

Start, stop, restart and reload#

Command Effect
start Start the server and all enabled jails (Server ready)
stop Stop all jails and the server (Shutdown successful)
restart Stop and start the server
reload Re-read config; keep the server and existing bans (OK)
reload <jail> Reload one jail
restart <jail> Fully restart one jail (alias for reload --restart <jail>)
restart --unban <jail> Restart one jail and drop its bans
start <jail> / stop <jail> Start or stop (remove) a single jail

On systemd hosts, use sudo systemctl restart fail2ban for the service and fail2ban-client reload for config changes. Which one you need for which change is covered in restart vs reload.

Logging and database commands#

output
$ sudo fail2ban-client get loglevel
Current logging level is 'INFO'
$ sudo fail2ban-client get logtarget
Current logging target is:
`- /var/log/fail2ban.log
$ sudo fail2ban-client get dbpurgeage
Current database purge age is:
`- 86400seconds

set loglevel <LEVEL> accepts CRITICAL, ERROR, WARNING, NOTICE, INFO, DEBUG, TRACEDEBUG and HEAVYDEBUG. flushlogs reopens the log file after rotation. See fail2ban logs for log locations and levels.

When fail2ban-client can't reach the server#

output
$ sudo fail2ban-client status
2026-10-25 18:36:27,357 fail2ban                [2083]: ERROR   Failed to access socket path: /var/run/fail2ban/fail2ban.sock. Is fail2ban running?

The server isn't running, or you forgot sudo (the socket is only accessible to root). Check sudo systemctl status fail2ban and read failed to access socket. If the command itself is missing (fail2ban-client: command not found), fail2ban isn't installed — see install fail2ban.

Complete fail2ban-client command list#

All 96 commands from the fail2ban 1.1.1 protocol, grouped as fail2ban-client -h prints them. <JAIL>, <IP> and similar are placeholders. The command builder fills them in for you.

Basic#

CommandWhat it does
fail2ban-client startstarts the server and the jails
fail2ban-client restartrestarts the server
fail2ban-client restart [--unban] [--if-exists] <JAIL>restarts the jail <JAIL> (alias for 'reload --restart ... <JAIL>')
fail2ban-client reload [--restart] [--unban] [--all]reloads the configuration without restarting of the server, the option '--restart' activates completely restarting of affected jails, thereby can unban IP addresses (if option '--unban' specified)
fail2ban-client reload [--restart] [--unban] [--if-exists] <JAIL>reloads the jail <JAIL>, or restarts it (if option '--restart' specified)
fail2ban-client stopstops all jails and terminate the server
fail2ban-client unban --allunbans all IP addresses (in all jails and database)
fail2ban-client unban <IP> ... <IP>unbans <IP> (in all jails and database)
fail2ban-client bannedreturn jails with banned IPs as dictionary
fail2ban-client banned <IP> ... <IP>]return list(s) of jails where given IP(s) are banned
fail2ban-client statusgets the current status of the server
fail2ban-client status --all [FLAVOR]gets the current status of all jails, with optional output style [FLAVOR]. Flavors: 'basic' (default), 'cymru', 'short', 'stats'
fail2ban-client stat[istic]sgets the current statistics of all jails as table
fail2ban-client pingtests if the server is alive
fail2ban-client echofor internal usage, returns back and outputs a given string
fail2ban-client versionreturn the server version

Logging#

CommandWhat it does
fail2ban-client set loglevel <LEVEL>sets logging level to <LEVEL>. Levels: CRITICAL, ERROR, WARNING, NOTICE, INFO, DEBUG, TRACEDEBUG, HEAVYDEBUG or corresponding numeric value (50-5)
fail2ban-client get loglevelgets the logging level
fail2ban-client set logtarget <TARGET>sets logging target to <TARGET>. Can be STDOUT, STDERR, SYSLOG, SYSTEMD-JOURNAL or a file
fail2ban-client get logtargetgets logging target
fail2ban-client set syslogsocket auto|<SOCKET>sets the syslog socket path to auto or <SOCKET>. Only used if logtarget is SYSLOG
fail2ban-client get syslogsocketgets syslog socket path
fail2ban-client flushlogsflushes the logtarget if a file and reopens it. For log rotation.

Database#

CommandWhat it does
fail2ban-client set dbfile <FILE>set the location of fail2ban persistent datastore. Set to "None" to disable
fail2ban-client get dbfileget the location of fail2ban persistent datastore
fail2ban-client set dbmaxmatches <INT>sets the max number of matches stored in database per ticket
fail2ban-client get dbmaxmatchesgets the max number of matches stored in database per ticket
fail2ban-client set dbpurgeage <SECONDS>sets the max age in <SECONDS> that history of bans will be kept
fail2ban-client get dbpurgeagegets the max age in seconds that history of bans will be kept

Jail Control#

CommandWhat it does
fail2ban-client add <JAIL> <BACKEND>creates <JAIL> using <BACKEND>
fail2ban-client start <JAIL>starts the jail <JAIL>
fail2ban-client stop <JAIL>stops the jail <JAIL>. The jail is removed
fail2ban-client status <JAIL> [FLAVOR]gets the current status of <JAIL>, with optional output style [FLAVOR]. Flavors: 'basic' (default), 'cymru', 'short', 'stats'

Jail Configuration#

CommandWhat it does
fail2ban-client set <JAIL> idle on|offsets the idle state of <JAIL>
fail2ban-client set <JAIL> ignoreself true|falseallows the ignoring of own IP addresses
fail2ban-client set <JAIL> addignoreip <IP>adds <IP> to the ignore list of <JAIL>
fail2ban-client set <JAIL> delignoreip <IP>removes <IP> from the ignore list of <JAIL>
fail2ban-client set <JAIL> ignorecommand <VALUE>sets ignorecommand of <JAIL>
fail2ban-client set <JAIL> ignorecache <VALUE>sets ignorecache of <JAIL>
fail2ban-client set <JAIL> addlogpath <FILE> ['tail']adds <FILE> to the monitoring list of <JAIL>, optionally starting at the 'tail' of the file (default 'head').
fail2ban-client set <JAIL> dellogpath <FILE>removes <FILE> from the monitoring list of <JAIL>
fail2ban-client set <JAIL> logencoding <ENCODING>sets the <ENCODING> of the log files for <JAIL>
fail2ban-client set <JAIL> addjournalmatch <MATCH>adds <MATCH> to the journal filter of <JAIL>
fail2ban-client set <JAIL> deljournalmatch <MATCH>removes <MATCH> from the journal filter of <JAIL>
fail2ban-client set <JAIL> addfailregex <REGEX>adds the regular expression <REGEX> which must match failures for <JAIL>
fail2ban-client set <JAIL> delfailregex <INDEX>removes the regular expression at <INDEX> for failregex
fail2ban-client set <JAIL> addignoreregex <REGEX>adds the regular expression <REGEX> which should match pattern to exclude for <JAIL>
fail2ban-client set <JAIL> delignoreregex <INDEX>removes the regular expression at <INDEX> for ignoreregex
fail2ban-client set <JAIL> findtime <TIME>sets the number of seconds <TIME> for which the filter will look back for <JAIL>
fail2ban-client set <JAIL> bantime <TIME>sets the number of seconds <TIME> a host will be banned for <JAIL>
fail2ban-client set <JAIL> datepattern <PATTERN>sets the <PATTERN> used to match date/times for <JAIL>
fail2ban-client set <JAIL> usedns <VALUE>sets the usedns mode for <JAIL>
fail2ban-client set <JAIL> attempt <IP> [<failure1> ... <failureN>]manually notify about <IP> failure
fail2ban-client set <JAIL> banip <IP> ... <IP>manually Ban <IP> for <JAIL>
fail2ban-client set <JAIL> unbanip [--report-absent] <IP> ... <IP>manually Unban <IP> in <JAIL>
fail2ban-client set <JAIL> maxretry <RETRY>sets the number of failures <RETRY> before banning the host for <JAIL>
fail2ban-client set <JAIL> maxmatches <INT>sets the max number of matches stored in memory per ticket in <JAIL>
fail2ban-client set <JAIL> maxlines <LINES>sets the number of <LINES> to buffer for regex search for <JAIL>
fail2ban-client set <JAIL> addaction <ACT>[ <PYTHONFILE> <JSONKWARGS>]adds a new action named <ACT> for <JAIL>. Optionally for a Python based action, a <PYTHONFILE> and <JSONKWARGS> can be specified, else will be a Command Action
fail2ban-client set <JAIL> delaction <ACT>removes the action <ACT> from <JAIL>

Command Action Configuration#

CommandWhat it does
fail2ban-client set <JAIL> action <ACT> actionstart <CMD>sets the start command <CMD> of the action <ACT> for <JAIL>
fail2ban-client set <JAIL> action <ACT> actionstop <CMD>sets the stop command <CMD> of the action <ACT> for <JAIL>
fail2ban-client set <JAIL> action <ACT> actioncheck <CMD>sets the check command <CMD> of the action <ACT> for <JAIL>
fail2ban-client set <JAIL> action <ACT> actionban <CMD>sets the ban command <CMD> of the action <ACT> for <JAIL>
fail2ban-client set <JAIL> action <ACT> actionunban <CMD>sets the unban command <CMD> of the action <ACT> for <JAIL>
fail2ban-client set <JAIL> action <ACT> timeout <TIMEOUT>sets <TIMEOUT> as the command timeout in seconds for the action <ACT> for <JAIL>

General Action Configuration#

CommandWhat it does
fail2ban-client set <JAIL> action <ACT> <PROPERTY> <VALUE>sets the <VALUE> of <PROPERTY> for the action <ACT> for <JAIL>
fail2ban-client set <JAIL> action <ACT> <METHOD>[ <JSONKWARGS>]calls the <METHOD> with <JSONKWARGS> for the action <ACT> for <JAIL>

Jail Information#

CommandWhat it does
fail2ban-client get <JAIL> bannedreturn banned IPs of <JAIL>
fail2ban-client get <JAIL> banned <IP> ... <IP>]return 1 if IP is banned in <JAIL> otherwise 0, or a list of 1/0 for multiple IPs
fail2ban-client get <JAIL> logpathgets the list of the monitored files for <JAIL>
fail2ban-client get <JAIL> logencodinggets the encoding of the log files for <JAIL>
fail2ban-client get <JAIL> journalmatchgets the journal filter match for <JAIL>
fail2ban-client get <JAIL> ignoreselfgets the current value of the ignoring the own IP addresses
fail2ban-client get <JAIL> ignoreipgets the list of ignored IP addresses for <JAIL>
fail2ban-client get <JAIL> ignorecommandgets ignorecommand of <JAIL>
fail2ban-client get <JAIL> failregexgets the list of regular expressions which matches the failures for <JAIL>
fail2ban-client get <JAIL> ignoreregexgets the list of regular expressions which matches patterns to ignore for <JAIL>
fail2ban-client get <JAIL> findtimegets the time for which the filter will look back for failures for <JAIL>
fail2ban-client get <JAIL> bantimegets the time a host is banned for <JAIL>
fail2ban-client get <JAIL> datepatterngets the pattern used to match date/times for <JAIL>
fail2ban-client get <JAIL> usednsgets the usedns setting for <JAIL>
fail2ban-client get <JAIL> banip [<SEP>|--with-time]gets the list of of banned IP addresses for <JAIL>. Optionally the separator character ('<SEP>', default is space) or the option '--with-time' (printing the times of ban) may be specified. The IPs are ordered by end of ban.
fail2ban-client get <JAIL> maxretrygets the number of failures allowed for <JAIL>
fail2ban-client get <JAIL> maxmatchesgets the max number of matches stored in memory per ticket in <JAIL>
fail2ban-client get <JAIL> maxlinesgets the number of lines to buffer for <JAIL>
fail2ban-client get <JAIL> actionsgets a list of actions for <JAIL>

Command Action Information#

CommandWhat it does
fail2ban-client get <JAIL> action <ACT> actionstartgets the start command for the action <ACT> for <JAIL>
fail2ban-client get <JAIL> action <ACT> actionstopgets the stop command for the action <ACT> for <JAIL>
fail2ban-client get <JAIL> action <ACT> actioncheckgets the check command for the action <ACT> for <JAIL>
fail2ban-client get <JAIL> action <ACT> actionbangets the ban command for the action <ACT> for <JAIL>
fail2ban-client get <JAIL> action <ACT> actionunbangets the unban command for the action <ACT> for <JAIL>
fail2ban-client get <JAIL> action <ACT> timeoutgets the command timeout in seconds for the action <ACT> for <JAIL>

General Action Information#

CommandWhat it does
fail2ban-client get <JAIL> actionproperties <ACT>gets a list of properties for the action <ACT> for <JAIL>
fail2ban-client get <JAIL> actionmethods <ACT>gets a list of methods for the action <ACT> for <JAIL>
fail2ban-client get <JAIL> action <ACT> <PROPERTY>gets the value of <PROPERTY> for the action <ACT> for <JAIL>

FAQ#

How do I list all jails in fail2ban?#

Run sudo fail2ban-client status. It prints the number of jails and a comma-separated Jail list. For the details of every jail in one go, use sudo fail2ban-client status --all (fail2ban 1.1.0 and later), or loop over the names with status <jail> on older versions.

Why does fail2ban-client say "command not found"?#

fail2ban isn't installed, or you're using an account whose PATH lacks /usr/bin (or /usr/local/bin for a source install). Install the fail2ban package for your distribution, then run the client with sudo. In Docker, run it inside the container with docker exec <container> fail2ban-client status.

Are changes made with fail2ban-client set permanent?#

No. set changes only the running server. A reload, a restart of the service or a reboot reapplies the configuration files. To keep a change, put it in /etc/fail2ban/jail.local (or a file in jail.d/) and run sudo fail2ban-client reload.

How do I see all fail2ban-client commands for my version?#

Run fail2ban-client -h. It prints the options and every command the installed version supports, with a one-line description. man fail2ban-client shows the same list. Older versions such as 1.0.2 lack status --all and stats, which arrived in 1.1.0.

Spotted something wrong or out of date? Tell us — every page is checked against the current fail2ban release.