Fail2Ban command snippets

Copy-paste-ready fail2ban-client commands for checking status, banning IPs, and testing filters.

Fail2Ban command snippets

Copy-paste-ready fail2ban-client commands for checking status, banning IPs, and testing filters.

List All Active Fail2Ban Jails

fail2ban-client lists every enabled jail:

sudo fail2ban-client status

Check Banned IPs for a Specific Fail2Ban Jail

fail2ban-client shows the number of bans and the list of currently banned IPs:

sudo fail2ban-client status sshd

Manually Ban an IP in Fail2Ban

fail2ban-client adds a ban for a specific IP in a jail:

sudo fail2ban-client set sshd banip 203.0.113.45

Manually Unban an IP in Fail2Ban

fail2ban-client removes a ban for a specific IP:

sudo fail2ban-client set sshd unbanip 203.0.113.45

Test a Fail2Ban Filter Against a Log File

fail2ban-regex reports how many lines match the filter's regex:

sudo fail2ban-regex /var/log/auth.log /etc/fail2ban/filter.d/sshd.conf

Test a Fail2Ban Filter Against the systemd Journal

fail2ban-regex reads from the journal when given systemd-journal as the log source:

sudo fail2ban-regex systemd-journal /etc/fail2ban/filter.d/sshd.conf

Reload Fail2Ban Configuration Without Restarting

fail2ban-client reloads all jails and filters:

sudo fail2ban-client reload

Show Fail2Ban Version and Configuration Summary

fail2ban-client displays the server version:

sudo fail2ban-client version

View the Fail2Ban Log File

The Fail2Ban log records all ban and unban actions:

sudo tail -50 /var/log/fail2ban.log