systemctl start fail2banStarts the Fail2Ban intrusion prevention service daemon.
Watches log files for repeated failures — SSH, web logins, mail — and bans offending IPs with firewall rules.
sudo apt install fail2bansystemctl start fail2banStarts the Fail2Ban intrusion prevention service daemon.
systemctl stop fail2banStops the running Fail2Ban service daemon.
systemctl restart fail2banRestarts the Fail2Ban service to apply new configurations.
systemctl status fail2banDisplays the current operational status and recent logs of the Fail2Ban service.
fail2ban-server --versionOutputs the installed version of the Fail2Ban server.
fail2ban-server -tTests the configuration files for syntax errors without starting the server.
fail2ban-client statusDisplays the global status including the number of currently active jails.
fail2ban-client status <JAIL>Shows detailed statistics for a specific jail including current ban count and list.
Example
fail2ban-client status sshdfail2ban-client start <JAIL>Manually starts a specific jail that is currently stopped.
Example
fail2ban-client start nginx-http-authfail2ban-client stop <JAIL>Manually stops a running jail without stopping the entire service.
Example
fail2ban-client stop postfixfail2ban-client reload <JAIL>Reloads the configuration for a single specific jail.
Example
fail2ban-client reload sshdfail2ban-client get loglevelRetrieves the current logging verbosity level of the server.
fail2ban-client set loglevel <LEVEL>Sets the logging verbosity to a specific level (CRITICAL, ERROR, WARNING, NOTICE, INFO, DEBUG).
Example
fail2ban-client set loglevel DEBUGfail2ban-client get logtargetDisplays the current file path or target where Fail2Ban writes its logs.
fail2ban-client set logtarget <TARGET>Changes the log output destination to a specified file path.
Example
fail2ban-client set logtarget /var/log/fail2ban-trace.logfail2ban-client set logtarget STDOUTRedirects log output to standard output for debugging purposes.
fail2ban-client set <JAIL> banip <IP>Manually bans a specific IP address in the specified jail immediately.
Example
fail2ban-client set sshd banip 192.168.1.50fail2ban-client set <JAIL> banip <CIDR>Manually bans an entire CIDR block in the specified jail.
Example
fail2ban-client set sshd banip 10.0.0.0/24fail2ban-client set <JAIL> unbanip <IP>Manually unbans a specific IP address from the specified jail.
Example
fail2ban-client set sshd unbanip 192.168.1.50fail2ban-client unban <IP>Unbans a specific IP address across all jails (requires version 0.11+).
Example
fail2ban-client unban 192.168.1.50fail2ban-client unban --allRemoves all active bans across all jails immediately.
fail2ban-client get <JAIL> logpathRetrieves the log file path currently being monitored by a specific jail.
Example
fail2ban-client get sshd logpathfail2ban-client get <JAIL> failregexDisplays the list of failure regexes currently loaded for the jail.
Example
fail2ban-client get sshd failregexfail2ban-client get <JAIL> ignoreregexDisplays the list of ignore regexes currently loaded for the jail.
Example
fail2ban-client get sshd ignoreregexfail2ban-client get <JAIL> maxretryShows the number of failures required to trigger a ban for the jail.
Example
fail2ban-client get sshd maxretryfail2ban-client get <JAIL> findtimeShows the time window in seconds during which failures are counted.
Example
fail2ban-client get sshd findtimefail2ban-client get <JAIL> bantimeShows the duration in seconds for which an IP is banned.
Example
fail2ban-client get sshd bantimefail2ban-client get <JAIL> usednsChecks if DNS resolution is enabled (yes, warn, no, raw) for the jail.
Example
fail2ban-client get sshd usednsfail2ban-client set <JAIL> maxretry <N>Updates the maximum retry threshold for a running jail dynamically.
Example
fail2ban-client set sshd maxretry 5fail2ban-client set <JAIL> findtime <SECONDS>Updates the lookback window duration for a running jail dynamically.
Example
fail2ban-client set sshd findtime 600fail2ban-client set <JAIL> bantime <SECONDS>Updates the ban duration for a running jail dynamically.
Example
fail2ban-client set sshd bantime 3600fail2ban-client get <JAIL> ignoreipLists all IP addresses and CIDR blocks currently ignored (whitelisted) by the jail.
Example
fail2ban-client get sshd ignoreipfail2ban-client set <JAIL> addignoreip <IP>Adds a specific IP address to the ignore list of a running jail.
Example
fail2ban-client set sshd addignoreip 192.168.10.5fail2ban-client set <JAIL> delignoreip <IP>Removes a specific IP address from the ignore list of a running jail.
Example
fail2ban-client set sshd delignoreip 192.168.10.5fail2ban-client get <JAIL> actionsLists the names of the actions configured for the specified jail.
Example
fail2ban-client get sshd actionsfail2ban-regex <LOGLINE> <FILTER>Tests a single log line string against a specific filter configuration.
Example
fail2ban-regex 'Failed password for root from 1.2.3.4' sshdfail2ban-regex <LOGFILE> <FILTER>Tests an entire log file against a specific filter and reports match statistics.
Example
fail2ban-regex /var/log/auth.log sshdfail2ban-regex --print-all-missed <LOGFILE> <FILTER>Runs a regex test and prints all log lines that did NOT match the filter.
Example
fail2ban-regex --print-all-missed /var/log/auth.log sshdfail2ban-regex --print-all-matched <LOGFILE> <FILTER>Runs a regex test and prints only the log lines that successfully matched the filter.
Example
fail2ban-regex --print-all-matched /var/log/auth.log sshdfail2ban-regex --print-all-ignored <LOGFILE> <FILTER>Runs a regex test and prints lines that matched but were ignored due to ignoreregex.
Example
fail2ban-regex --print-all-ignored /var/log/auth.log sshdfail2ban-regex -D <LOGFILE> <FILTER>Runs regex testing in debug mode, showing detailed internal processing logic.
Example
fail2ban-regex -D /var/log/auth.log sshdfail2ban-regex -v <LOGFILE> <FILTER>Runs regex testing with verbose output to analyze processing speed and stats.
Example
fail2ban-regex -v /var/log/nginx/error.log nginx-botsearchgrep 'Ban' /var/log/fail2ban.logSearches the primary Fail2Ban log file for all ban events.
grep 'Unban' /var/log/fail2ban.logSearches the primary Fail2Ban log file for all unban events.
tail -f /var/log/fail2ban.logFollows the Fail2Ban log file in real-time to monitor activity.
zgrep 'Ban' /var/log/fail2ban.log*Searches for ban events in both current and rotated (gzipped) Fail2Ban logs.
grep 'Found' /var/log/fail2ban.logSearches logs for 'Found' entries indicating a filter match before a ban threshold is reached.
fail2ban-client set <JAIL> action <ACTION> actionstart <CMD>Dynamically overrides the 'actionstart' command for a specific action in a running jail.
Example
fail2ban-client set sshd action iptables-multiport actionstart 'echo starting'fail2ban-client set <JAIL> action <ACTION> actionban <CMD>Dynamically overrides the 'actionban' command for a specific action in a running jail.
Example
fail2ban-client set sshd action iptables-multiport actionban 'echo banning <ip>'fail2ban-client set <JAIL> action <ACTION> actionunban <CMD>Dynamically overrides the 'actionunban' command for a specific action in a running jail.
Example
fail2ban-client set sshd action iptables-multiport actionunban 'echo unbanning <ip>'fail2ban-python --versionChecks the version of the embedded Python interpreter used by Fail2Ban.
fail2ban-client --testRuns a basic test to verify that the client can load the configuration modules.
sqlite3 /var/lib/fail2ban/fail2ban.sqlite3 'SELECT * FROM bans LIMIT 5;'Directly queries the persistent Fail2Ban database to view the first 5 bans.
sqlite3 /var/lib/fail2ban/fail2ban.sqlite3 'SELECT count(*) FROM bans;'Counts the total number of bans recorded in the persistent database history.
sqlite3 /var/lib/fail2ban/fail2ban.sqlite3 'SELECT ip FROM bans WHERE jail="sshd";'Retrieves all IPs ever banned by the sshd jail from the database.
fail2ban-client set <JAIL> backend <BACKEND>Changes the log monitoring backend (polling, pyinotify, systemd, auto) for a running jail.
Example
fail2ban-client set sshd backend pyinotifyfail2ban-client get <JAIL> backendDisplays the current log monitoring backend method being used by the jail.
Example
fail2ban-client get sshd backendtruncate -s 0 /var/log/fail2ban.logClears the Fail2Ban log file content without deleting the file (useful during testing).
fail2ban-client set <JAIL> addlogpath <FILE>Dynamically adds an additional log file to be monitored by a running jail.
Example
fail2ban-client set sshd addlogpath /var/log/auth.log.1fail2ban-client set <JAIL> dellogpath <FILE>Dynamically removes a log file from being monitored by a running jail.
Example
fail2ban-client set sshd dellogpath /var/log/auth.log.1awk '($(NF-1) == "Ban"){print $NF}' /var/log/fail2ban.log | sort | uniq -c | sort -nExtracts banned IPs from logs and displays frequency counts for threat analysis.
fail2ban-client set <JAIL> addfailregex <REGEX>Injects a new failure regex into a running jail without reloading config files.
Example
fail2ban-client set sshd addfailregex '^Failed publickey for .* from <HOST>#x27;fail2ban-client set <JAIL> delfailregex <INDEX>Removes a failure regex from a running jail by its index.
Example
fail2ban-client set sshd delfailregex 1fail2ban-client set <JAIL> banip <TEST_IP>Tests the ban action mechanism by banning a reserved test IP address.
Example
fail2ban-client set sshd banip 192.0.2.100iptables -L -n | grep f2bVerifies that Fail2Ban has correctly inserted its chains into the iptables firewall.
ipset listLists IP sets if Fail2Ban is configured to use ipset for higher performance banning.
nft list ruleset | grep f2bVerifies Fail2Ban rules in the nftables ruleset if using nftables backend.
logger -p auth.warn -t sshd 'Failed password for root from 192.0.2.200 port 22 ssh2'Injects a fake log entry into syslog to trigger Fail2Ban detection logic.
fail2ban-regex --print-all-matched <LOG> <FILTER> | wc -lCounts the total number of historical matches for a specific filter in a log file.
Example
fail2ban-regex --print-all-matched /var/log/auth.log sshd | wc -lrm /var/lib/fail2ban/fail2ban.sqlite3Deletes the persistent database to reset all historical ban data (requires service stop).
fail2ban-client status | grep 'Jail list' | sed 's/.*: //g' | tr ',' '\n'Parses the status output to generate a clean, newline-separated list of active jails.
fail2ban-client set <JAIL> idle onSets the jail to idle mode, effectively pausing it without stopping the service.
Example
fail2ban-client set sshd idle onfail2ban-client set <JAIL> idle offResumes the jail from idle mode to active monitoring.
Example
fail2ban-client set sshd idle offfail2ban-client get <JAIL> banip --with-timeRetrieves the list of banned IPs along with the timestamp of when they were banned.
Example
fail2ban-client get sshd banip --with-timefail2ban-client -v -v startStarts the Fail2Ban client in high verbosity mode for troubleshooting startup failures.
grep 'restore ban' /var/log/fail2ban.logChecks logs to verify if bans were successfully restored from the database after a restart.
fail2ban-client set <JAIL> action <ACTION> actioncheckManually triggers the 'actioncheck' command to verify firewall chain integrity.
Example
fail2ban-client set sshd action iptables-multiport actioncheckfail2ban-client set <JAIL> banaction <ACTION>Dynamically changes the banning action used by a jail (e.g., switching from multiport to allports).
Example
fail2ban-client set sshd banaction iptables-allportsfail2ban-client get <JAIL> action <ACTION> actionbanInspects the exact command string that will be executed when a ban occurs.
Example
fail2ban-client get sshd action iptables-multiport actionbanfail2ban-client --str2sec <TIME_STRING>Converts a time string (e.g., 1d12h) into seconds to verify configuration parsing logic.
Example
fail2ban-client --str2sec 1d12hfail2ban-client -x startStarts the server and forces the removal of the socket file if it exists (socket cleanup).
fail2ban-client set <JAIL> usedns noDisables DNS resolution for a jail to improve performance and prevent DNS timeouts.
Example
fail2ban-client set sshd usedns nofail2ban-client set <JAIL> usedns rawSets DNS mode to raw, processing IPs exactly as they appear in logs without resolution.
Example
fail2ban-client set sshd usedns rawpython3 -c 'import fail2ban.server.failmanager; print(fail2ban.server.failmanager)'Verifies that the Fail2Ban python modules are correctly installed and importable.
fail2ban-client set recidive banip <IP>Manually adds an IP to the recidive jail (long-term ban) usually reserved for repeat offenders.
Example
fail2ban-client set recidive banip 192.168.1.50fail2ban-regex /var/log/fail2ban.log /etc/fail2ban/filter.d/recidive.confTests the recidive filter against the Fail2Ban log itself to verify repeat offender detection.
fail2ban-regex 'Dec 10 10:00:00 server sshd[123]: Invalid user test from 1.2.3.4' '<HOST>'Tests the built-in <HOST> macro against a log line to ensure it extracts the IP 1.2.3.4.
nice -n -10 fail2ban-server -bStarts the Fail2Ban server in the background with high CPU priority.
fail2ban-client get <JAIL> action <ACTION> actionstopDisplays the command executed when the jail stops, useful for checking cleanup logic.
Example
fail2ban-client get sshd action iptables-multiport actionstopfail2ban-client set <JAIL> addignoreip <DNS_NAME>Adds a DNS hostname to the ignore list (requires usedns to be enabled).
Example
fail2ban-client set sshd addignoreip googlebot.comwatch -n 1 'fail2ban-client status sshd'Runs the status command every second to create a real-time dashboard of the sshd jail.
for jail in $(fail2ban-client status | grep 'Jail list' | sed 's/.*: //g' | tr ',' ' '); do fail2ban-client status $jail; doneLoops through all active jails and prints the detailed status for each one.
fail2ban-client set <JAIL> logpath <NEW_LOG_FILE>Updates the log file path for a running jail, useful during complex log rotation schemes.
Example
fail2ban-client set sshd logpath /var/log/auth.logfail2ban-client --dump-prettyDumps the current configuration in a human-readable, indented format (requires newer versions).
fail2ban-client -VShort flag to display the version of the client.
pgrep -a fail2banLists the process ID and full command line of the running Fail2Ban server.
fail2ban-client stop && rm -f /var/run/fail2ban/fail2ban.sockStops the client and forcefully removes the socket file to resolve connection refused errors.