Plugin Directory

WP fail2ban

Write all login attempts to syslog for integration with fail2ban.

WP_FAIL2BAN_AUTH_LOG - what's it all about?

By default, WPf2b uses LOG_AUTH for logging authentication success or failure. However, some systems use LOG_AUTHPRIV instead, but there's no good run-time way to tell. If your system uses LOG_AUTHPRIV you should add the following to wp-config.php:


WP_FAIL2BAN_LOG_PINGBACKS - what's it all about?

Based on a suggestion from maghe, WPf2b can now log pingbacks. To enable this feature, add the following to wp-config.php:


By default, WPf2b uses LOG_USER for logging pingbacks. If you'd rather it used a different facility you can change it by adding something like the following to wp-config.php:



Brute-forcing WP requires knowing a valid username. Unfortunately, WP makes this all but trivial.

Based on a suggestion from geeklol and a plugin by ROIBOT, WPf2b can now block user enumeration attempts. Just add the following to wp-config.php:


WP_FAIL2BAN_PROXIES - what's it all about?

The idea here is to list the IP addresses of the trusted proxies that will appear as the remote IP for the request. When defined:

  • If the remote address appears in the WP_FAIL2BAN_PROXIES list, WPf2b will log the IP address from the X-Forwarded-For header
  • If the remote address does not appear in the WP_FAIL2BAN_PROXIES list, WPf2b will return a 403 error
  • If there's no X-Forwarded-For header, WPf2b will behave as if WP_FAIL2BAN_PROXIES isn't defined

To set WP_FAIL2BAN_PROXIES, add something like the following to wp-config.php:


WPf2b doesn't do anything clever with the list - beware of typos!

WP_FAIL2BAN_BLOCKED_USERS - what's it all about?

The bots that try to brute-force WordPress logins aren't that clever (no doubt that will change), but they may only make one request per IP every few hours in an attempt to avoid things like fail2ban. With large botnets this can still create significant load.

Based on a suggestion from jmadea, WPf2b now allows you to specify a regex that will shortcut the login process if the requested username matches.

For example, putting the following in wp-config.php:


will block any attempt to log in as admin before most of the core WordPress code is run. Unless you go crazy with it, a regex is usually cheaper than a call to the database so this should help keep things running during an attack.

WPf2b doesn't do anything to the regex other than make it case-insensitive.

Why is fail2ban complaining on my flavour of Linux?

Depending on your fail2ban configuration, you may need to add a line like:

port = http,https

to the [wordpress] section in jail.local.

Requires: 3.4.0 or higher
Compatible up to: 4.0.5
Last Updated: 2014-11-3
Active Installs: 10,000+


4.9 out of 5 stars


0 of 1 support threads in the last two months have been resolved.

Got something to say? Need help?


Not enough data

3 people say it works.
0 people say it's broken.

100,1,1 100,2,2
100,2,2 100,2,2
100,1,1 100,1,1