Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › email alerts

Getting Thousands of Fail2ban Emails? How to Tune It Without Losing Protection

By Freedom251 Team · · 10 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Thousands of Fail2ban emails usually mean that one or more enabled jails are using an email action for every ban. Inspect each jail’s action first. Keep a ban-only action for noisy services, reserve WHOIS and log-report emails for the few jails where an individual alert is worth the operational cost, then tune findtime, maxretry, and bantime in a local override. Test changes with fail2ban-client and save the working values in jail.local or a file under jail.d.

Why Fail2ban can send thousands of messages

Fail2ban watches service logs, counts failures from each source address, and applies a jail action when the threshold is reached. The ban itself does not require email. Email is an additional part of the selected action, so a server can block attackers correctly while still overwhelming an administrator’s mailbox.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A burst is especially likely when several conditions occur together:

  • Many jails are enabled and each jail has an email action.
  • An attacker uses rotating addresses, causing a fresh ban for every address.
  • bantime is short, so the same address can return and trigger another ban later.
  • maxretry is low or findtime is long enough to turn ordinary user mistakes into bans.
  • The selected action includes WHOIS data or matching log lines, making every message large as well as numerous.

There is no authoritative published statistic that defines how many messages constitute a Fail2ban “flood.” Treat the volume as an operational symptom: determine which jail and action are generating it instead of blindly disabling Fail2ban.

Understand the three upstream action variants

In the upstream configuration, the action names describe what happens after a host is banned. The exact firewall or firewall-set implementation can vary by distribution, so confirm the installed action definitions before changing a production server.

Action What it does When it fits
action_ Performs the basic ban action without the WHOIS and matching-log email additions. No per-ban email is needed, or the event stream is too noisy for individual messages.
action_mw Applies the ban and sends a WHOIS report for the banned address. A smaller number of high-value alerts where ownership or network information helps triage.
action_mwl Applies the ban and sends WHOIS information plus relevant matching log lines. Incidents where the evidence in the triggering log entries is worth receiving immediately.

If every jail uses action_mw or action_mwl, every qualifying address can generate a message. Switching a noisy jail to action_ keeps the ban while removing those email additions. Do not assume that an action name is identical on every packaged release; inspect the action files shipped by your operating system if the names or parameters differ.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Find the jail responsible before changing thresholds

  1. List enabled jails. Run sudo fail2ban-client status. The output includes the jail list and tells you whether the flood could be coming from one service or many.
  2. Inspect each jail’s activity. Run sudo fail2ban-client status <JAIL>, replacing <JAIL> with a name such as sshd. Record the currently failed count, total failed count, currently banned count, and total banned count.
  3. Review configured actions and mail destinations. Check the enabled jail definition and its local overrides for action, as well as the destination and sender settings used by your installed action. A quick file search is sudo grep -R "^[[:space:]]*action" /etc/fail2ban/jail.local /etc/fail2ban/jail.d 2>/dev/null. Then inspect the relevant action definition under /etc/fail2ban/action.d/.
  4. Correlate the timestamps. Compare the message timestamps with the jail’s log and ban counters. A single jail with a rapidly increasing “Total banned” count needs a different response from several moderate jails that happen to notify the same mailbox.
  5. Check for rotating sources. If addresses change on nearly every event, raising the threshold for one address may not reduce the total much. In that case, remove per-ban mail from the noisy jail and send aggregate security events through a rate-limited monitoring system.

Keep a short sample of the messages, including the jail name, action name, source address, and time. Those details let you verify that a later configuration change affected the intended path.

Stop the emails while keeping bans

For a jail that should continue blocking but does not need one message per ban, set its action to the ban-only variant in a local override:

[sshd]
action = %(action_)s

Use the actual jail name and, if your distribution defines a different ban action, use the corresponding ban-only action from its installed configuration. This override changes the notification behavior for that jail; it does not turn the jail off.

A practical split is to keep email only on services where a human must react to each event, such as an externally exposed administrative interface, and use ban-only behavior for high-volume authentication logs. The right choice depends on attack surface, normal user-error rate, notification value, and the time required to process each message.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep alerts for selected jails

Actions are configured per jail. You can therefore leave an email action on a high-value jail while assigning %(action_)s to a noisy web-authentication or mail-service jail. If you need awareness of the latter, route its events to a digesting or rate-limited monitoring path rather than restoring unrestricted per-ban email.

Do not disable Fail2ban to solve a mail problem

Commenting out enabled = true or stopping the service removes the bans as well as the emails. Change only the action when blocking is still required. After reloading, verify both that the jail remains active and that a new ban no longer invokes the mail-producing action.

Tune findtime, maxretry, and bantime as a system

Fail2ban’s rule is straightforward: a host is banned when it has generated maxretry failures during the last findtime seconds. The manual accepts seconds and abbreviations such as 10m, 1h, and 1d.

Setting Meaning What changing it does Primary risk
findtime Look-back interval in which failures are counted. A longer interval allows failures spread over more time to reach the threshold; a shorter interval requires a faster burst. Too long can count unrelated mistakes; too short can miss slow attacks.
maxretry Number of failures required within findtime. A higher value tolerates more mistakes; a lower value bans earlier. High values delay blocking; low values can lock out legitimate users.
bantime How long a successful ban remains in force. A longer period reduces how quickly a returning address can trigger another ban. Legitimate users remain blocked longer and support recovery becomes more important.

The upstream sample configuration uses bantime = 10m, findtime = 10m, and maxretry = 5. These are examples, not universal recommendations. A public SSH service, a customer login portal, and an internal mail server have different legitimate-failure patterns.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose values from observed behavior

  • Measure how many failed attempts a normal user can produce during password recovery, a mobile-network change, or an expired credential incident.
  • Look at the spacing of attacks in the jail log. If malicious attempts arrive rapidly, a shorter findtime can still catch them while excluding occasional human errors.
  • Raise maxretry only when evidence shows false positives. Do not use it as a substitute for removing unnecessary notification email.
  • Increase bantime when the same sources return soon after expiry and create repeated alerts. Balance that against the support impact of a long block.
  • Add trusted administrative or monitoring addresses to ignoreip where appropriate, and verify that the list is maintained as those networks change.

Example starting point

The following is an illustration of the syntax, not a recommendation for every service:

[sshd]
enabled = true
action = %(action_)s
findtime = 10m
maxretry = 8
bantime = 1h
ignoreip = 127.0.0.1/8 192.0.2.10

The example makes SSH ban-only, tolerates eight failures in ten minutes, and bans for one hour. Replace the example address with a real, trusted management address; do not copy documentation-only ranges into an allowlist without understanding their effect.

Test changes at runtime before making them permanent

Runtime changes let you observe ban behavior without repeatedly editing and reloading files. Apply them to one jail, watch its status and message volume, and then persist the values if the result is acceptable.

sudo fail2ban-client set <JAIL> findtime 10m
sudo fail2ban-client set <JAIL> maxretry 8
sudo fail2ban-client set <JAIL> bantime 1h

Use the same jail name in all three commands. Confirm the result with:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo fail2ban-client status <JAIL>

Runtime settings are a test instrument, not a durable configuration strategy. Record the values that worked and place them in /etc/fail2ban/jail.local or a dedicated file under /etc/fail2ban/jail.d/. Reload or restart the service using your operating system’s normal service procedure, then check the jail status again. Existing bans may retain their original expiry; evaluate new bans when judging a changed bantime.

Put customizations where package updates will not erase them

Do not edit the packaged /etc/fail2ban/jail.conf for site-specific policy. The upstream configuration comment says, “You SHOULD NOT modify this file,” and directs administrators to jail.local or separate files under jail.d. Package updates can replace jail.conf, discarding direct edits.

Use one of the supported local locations

  • /etc/fail2ban/jail.local is suitable for a small installation with a single, easily reviewed policy file.
  • /etc/fail2ban/jail.d/ is useful when you want separate files for SSH, web authentication, mail services, or environment-specific overrides. Use the filename conventions documented by your package so the service loads the file.

Keep only the settings you intend to override. A concise local file is easier to audit than a copied version of the entire vendor configuration, and it makes upgrades less likely to hide an accidental change.

Validate after an upgrade

  1. Check that the jail is still listed by sudo fail2ban-client status.
  2. Check the jail’s action and counters with sudo fail2ban-client status <JAIL>.
  3. Review the effective local files and the installed action definition if an action name or parameter changed.
  4. Generate a controlled test event only in a safe environment, or wait for naturally occurring events; never deliberately lock out production users to prove a rule works.

Choose a policy for different services

There is no single threshold that suits every jail. Compare each service on four axes: how exposed it is, how often legitimate users fail, how valuable an immediate notification is, and what each email costs your team in time and storage.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Service pattern Notification approach Tuning emphasis
Internet-facing administrative login Keep an email action if each event requires investigation; otherwise use ban-only with separate aggregate monitoring. Protect trusted addresses with ignoreip; choose thresholds that do not lock out routine administration.
High-volume web authentication Usually ban-only or digesting alerts; per-ban WHOIS and log attachments can become disproportionately noisy. Study normal login and password-reset failures before changing maxretry or findtime.
Mail service Retain individual alerts only when the team acts on them; otherwise prefer rate-limited reporting. Account for shared NAT addresses and automated clients that may produce clustered failures.
Internal service Use ban-only if the event has little immediate response value. Coordinate ignoreip with changing office, VPN, and monitoring ranges.

This service-by-service policy prevents a noisy jail from dictating the notification behavior of every other jail.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common outcomes

The mailbox is still flooded after changing one jail

Another enabled jail may still use action_mw or action_mwl, or several jails may be watching the same authentication stream. Re-run the jail list and search all local action overrides. Identify the message’s jail name rather than assuming the first change was ineffective.

Bans stopped as well as emails

The action was likely disabled, misspelled, or replaced with a notification definition that does not contain the ban command. Compare the jail’s effective action with the installed ban-only definition. Restore a known-good ban action and verify the jail status before adjusting thresholds.

Legitimate users are being banned

First identify whether the failures come from a shared NAT, a stale application credential, a health check, or a real attack. Add only verified trusted addresses to ignoreip, fix the underlying client where possible, and then adjust maxretry or findtime based on measured behavior. Increasing both blindly can leave the service exposed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Attackers return as soon as a ban expires

A longer bantime can reduce repeat events, but it is not a replacement for addressing the attack surface. Confirm that the firewall action is applied correctly, consider whether the service needs stronger authentication controls, and monitor whether longer bans create support problems.

One email contains unexpectedly large log excerpts

The jail is probably using action_mwl, which adds matching log lines to the WHOIS report. Switch to action_mw if WHOIS is useful but the excerpts are not, or to action_ if the jail needs blocking without per-ban email.

A repeatable low-noise workflow

  1. List active jails and locate the message-producing jail.
  2. Inspect that jail’s effective action and determine whether it is action_, action_mw, action_mwl, or a distribution-specific equivalent.
  3. Change a noisy but important jail to ban-only; leave email enabled only where a person will act on each alert.
  4. Review the observed failure pattern before changing findtime, maxretry, or bantime.
  5. Apply candidate values with fail2ban-client set and watch counters, bans, legitimate access, and mailbox volume.
  6. Persist the accepted policy in jail.local or a file in jail.d, never in the vendor-managed jail.conf.
  7. After upgrades, recheck loaded jails, actions, and local overrides.

This approach separates two decisions that are often confused: whether an address should be blocked and whether a human should receive an individual message about that block.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

email alertsFail2banintrusion preventionLinux securityserver administration

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.