MyNixOS website logo
option

services.fail2ban.jails

The configuration of each Fail2ban “jail”. A jail consists of an action (such as blocking a port using iptables) that is triggered when a filter applied to a log file triggers more than a certain number of times in a certain time period. Actions are defined in /etc/fail2ban/action.d, while filters are defined in /etc/fail2ban/filter.d.

NixOS comes with a default sshd jail; for it to work well, services.openssh.logLevel should be set to "VERBOSE" or higher so that fail2ban can observe failed login attempts. This module sets it to "VERBOSE" if not set otherwise, so enabling fail2ban can make SSH logs more verbose.

Declarations
Type
attribute set of (strings concatenated with "\n" or (submodule))
Default
{ }
Example
{
  apache-nohome-iptables = {
    settings = {
      # Block an IP address if it accesses a non-existent
      # home directory more than 5 times in 10 minutes,
      # since that indicates that it's scanning.
      filter = "apache-nohome";
      action = ''iptables-multiport[name=HTTP, port="http,https"]'';
      logpath = "/var/log/httpd/error_log*";
      backend = "auto";
      findtime = 600;
      bantime = 600;
      maxretry = 5;
    };
  };
  dovecot = {
    settings = {
      # block IPs which failed to log-in
      # aggressive mode add blocking for aborted connections
      filter = "dovecot[mode=aggressive]";
      maxretry = 3;
    };
  };
};