October DealsAmazon USOctober deal check: compare before you payAmazon 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 NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Configure Fail2ban With Email Notifications

A practical Fail2ban email-notification guide covering local overrides, action_mw versus action_mwl, MTA setup, jail backends, testing, and delivery troubleshooting.
Length10 min Posted Quest giverVGSources Team

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.

Fail2ban can ban hostile addresses and notify you by email, but only when two separate pieces are configured: a notification action in Fail2ban and a working mail-transfer agent (MTA) that can actually submit the message. Put your changes in a local override, choose action_mw for a Whois report or action_mwl for a Whois report plus matching log lines, then verify the jail, log backend, and mail path independently.

What Fail2ban email notifications actually require

Fail2ban watches authentication or application logs, counts failures within a defined interval, and invokes an action when a jail reaches its threshold. A ban action can update firewall rules without sending anything. Email requires an action that explicitly calls a mail command, plus an MTA such as sendmail or another service capable of relaying mail.

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.

That distinction explains a common failure pattern: the address is banned successfully, yet no message reaches the mailbox. Fail2ban may have run its action correctly while the MTA, DNS, relay policy, sender identity, or spam filtering prevented final delivery. Treat ban enforcement and message delivery as two connected but separately testable systems.

Choose the right notification action

Fail2ban’s upstream action definitions provide two standard email choices. Both perform the ban and send to the address in destemail; they differ in the evidence included in the message.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.
Action Message contents Use it when
action_mw A ban notice with a Whois report You want a compact alert identifying the network or registration information for the address.
action_mwl A ban notice with a Whois report and relevant matching log lines You need the log evidence that caused the ban for faster incident review.
action_ Ban-only behavior; no email notification Use only when you deliberately do not want mail.

The extra log lines in action_mwl are useful during an investigation, but they also make messages more detailed. Start with action_mwl when understanding attacks matters more than keeping alerts short; choose action_mw when a Whois summary is sufficient.

Prerequisites before editing Fail2ban

  • Fail2ban installed and running: The service must be present on the host and able to read the logs for the jail you intend to monitor.
  • An MTA or equivalent mail submission path: Ubuntu’s Fail2ban guidance explicitly notes that you need sendmail or another MTA. Configuring an email action without this component cannot deliver a message.
  • A destination mailbox: Use an address you monitor, and make sure your mail provider accepts messages from the sender identity you configure.
  • Accurate log access: Know whether the service writes to ordinary files or only to the systemd journal. The answer determines the backend and log settings.
  • Console access and a recovery path: A bad SSH jail or an overly aggressive threshold can lock you out. Keep an already-authorized session open while testing.

Install and configure the MTA through your operating system’s normal package and mail configuration process, then send a test message independently. If that test cannot leave the host, Fail2ban cannot fix the delivery problem.

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

Keep local overrides separate from vendor defaults

Fail2ban ships broad defaults in /etc/fail2ban/jail.conf. Editing that file directly makes upgrades harder to manage because package updates can replace it. Use jail.local or a file under /etc/fail2ban/jail.d/ for local settings. The Fail2ban manpage documents this override model for jails and actions.

Simple single-file method

  1. Copy the packaged jail configuration:
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
  1. Open the local copy:
sudoedit /etc/fail2ban/jail.local

This approach is easy to understand, especially on a single-purpose server. It also copies many defaults you may never change, so review the file after package upgrades.

Dedicated drop-in method

On distributions that support it, create a narrowly scoped file in /etc/fail2ban/jail.d/, such as mail-notifications.local. Keep global notification values and the jail-specific overrides there. A drop-in makes your intent clearer and limits the number of settings that need to be revisited when Fail2ban’s packaged defaults change.

Set the global email values

Place the following values in the [DEFAULT] section of your local configuration. They provide the destination, sender identity, mail command family, and default action for jails that do not override them.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed
[DEFAULT]
destemail = [email protected]
sender = [email protected]
mta = sendmail
action = %(action_mwl)s
  • destemail is the mailbox that receives ban notices.
  • sender is the envelope or header identity used by the selected action. Configure an address your relay permits and your receiving service can evaluate.
  • mta tells the action which mail-transfer command family to use. The example assumes sendmail compatibility; use the value appropriate to the MTA installed on your host.
  • action selects the default behavior. Replace %(action_mwl)s with %(action_mw)s if you want the Whois report without matching log lines.

Fail2ban’s interpolation syntax matters here. The percent expressions expand to the action definitions supplied by Fail2ban. A typo, an unmatched quote, or an invalid interpolation can stop the service from accepting the file; inspect the parsed configuration before restarting if you are unsure.

Configure the jail that should send alerts

Email is generated only when an enabled jail detects failures and invokes the selected action. For an SSH jail, a local configuration can look like this:

[sshd]
enabled = true
port = ssh
filter = sshd
logpath = %(sshd_log)s
maxretry = 5
findtime = 10m
bantime = 1h

What each threshold controls

Setting Meaning Operational effect
enabled Whether the jail is active If it is false, there is no ban and no notification.
port The service port or service name being protected Must correspond to the SSH service exposed on this host.
filter The pattern set used to recognize failures Must match the format of the service’s actual log entries.
logpath The file or path Fail2ban reads A wrong path leaves the filter with no usable events.
maxretry Number of failures allowed Lower values alert and ban sooner, but increase the chance of catching legitimate mistakes.
findtime Window in which failures are counted Failures outside this interval do not contribute to the current count.
bantime How long the address remains banned Longer bans reduce repeat attempts but raise the cost of an accidental ban.

Adapt the filter and log source to the service you actually run. Do not copy an SSH log setting to an application that writes different messages or uses a different location.

Match the backend to your logging system

Fail2ban supports the documented systemd, polling, pyinotify, and auto backends. The backend determines how new log events are discovered; it does not change what the filter considers a failure.

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

Services that log to the systemd journal

Use a journal-oriented configuration when the service does not write a traditional log file. In that case, configure the jail’s journal matching settings as appropriate for the service rather than pointing logpath at a file that does not exist. A valid filter with an empty or incorrect file path will never reach the email action.

Services that write log files

Use a file-monitoring backend and a logpath that exists and contains the events your filter expects. The documented file-oriented choices include polling and pyinotify; auto can select an available method according to the installation. Check permissions as well as the path, because Fail2ban must be able to read the file.

Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

Why backend mistakes look like email failures

If the jail never sees a matching line, it never executes action_mw or action_mwl. The symptom is “no email,” but the fault is upstream in enabled, the filter, the journal or file source, or backend selection. Confirm event detection before changing mail settings.

Apply the configuration and inspect the jails

After saving the local file, restart Fail2ban using the service manager provided by your distribution:

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

Then inspect the overall service and the SSH jail:

sudo fail2ban-client status
sudo fail2ban-client status sshd

The first command should list the enabled jails. The jail-specific status should show its filter and current counters, including any currently banned addresses. If the service refuses to start, do not repeatedly restart it while guessing. Parse the configuration first:

sudo fail2ban-client -d

The debug dump exposes Fail2ban’s interpreted settings and helps locate malformed interpolation, quoting, an unknown action, or a path that did not expand as expected. Correct the local file, run the dump again, and restart only after the parsed output is sensible.

Verify an email from detection through delivery

1. Confirm the jail can detect the event

Review the Fail2ban log and the jail status together. You are looking for evidence that the filter matched the intended log source and that the failure count reached maxretry. A controlled test from an allowed test source is safer than attacking the service from an unknown address.

2. Protect yourself from lockout

Keep an existing authorized session open, and make sure your administrative address is covered by the jail’s ignoreip policy where appropriate. Never use an untrusted test host for an SSH attack simulation if losing that address would remove your only access path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC

3. Confirm the action ran

When the threshold is reached, Fail2ban should record the ban and the action invocation. If the log shows only a ban-only action, inspect the effective jail configuration: an override may have replaced the global setting with action = %(action_)s.

4. Follow the MTA logs

Check the MTA’s own log for queueing, relay rejection, DNS errors, sender-policy failures, or delivery completion. A successful Fail2ban action means the command was invoked; it does not prove that the destination mailbox accepted or displayed the message.

5. Check the mailbox and filtering

Look in the destination inbox and spam or quarantine folders. If the MTA accepted the message but the mailbox did not display it, investigate recipient-side filtering separately from Fail2ban.

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

Troubleshoot the most common failures

No email action appears in the configuration

Inspect the effective jail and the [DEFAULT] section. The jail must inherit or explicitly set action = %(action_mw)s or action = %(action_mwl)s. The ban-only action = %(action_)s cannot send a notification.

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

The jail never triggers

  • Confirm enabled = true.
  • Verify that filter matches the service’s log format.
  • Check logpath or the journal matching settings.
  • Use a backend that can read the actual source: journal-oriented for journal-only services, file monitoring for file logs.
  • Review the current failure count with fail2ban-client status <jail>.

Fail2ban rejects the file or will not restart

Run sudo fail2ban-client -d and inspect interpolation, quoting, section names, and expanded paths. A syntax or expansion error must be fixed before any notification test can be meaningful.

The mail command fails immediately

Check that the binary expected by the selected action exists and that the MTA can deliver an independent test message. Verify the configured mta, sender identity, destination address, and relay permissions. Fail2ban is only the caller; it does not replace the MTA’s queue, DNS, or relay logic.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

The message leaves the host but never arrives

Read the MTA log for upstream rejection or deferred delivery. Investigate DNS, sender policy, relay authentication or authorization, firewall egress rules, recipient spam filtering, and any mailbox quarantine. Keep these checks separate from filter tuning so a mail-delivery problem is not mistaken for a detection problem.

The wrong address is banned

Review ignoreip and hostname resolution. The Fail2ban manpage warns that reverse and forward DNS can disagree, so a hostname may resolve to an address different from the one you intended to exempt. Prefer carefully verified addresses for critical administrators and confirm the effective ignore list before testing.

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

There are too many or too few alerts

Tune maxretry, findtime, and bantime against the service’s normal traffic and threat level. Lower thresholds produce quicker bans but can punish mistyped credentials or shared networks. Longer bans reduce repeated noise but make an accidental ban harder to recover from. Change one value at a time and observe both the ban rate and the usefulness of the resulting messages.

Use an external notification service instead of email

Fail2ban’s upstream configuration also documents Apprise actions for external notification services. This route requires separate Apprise configuration and credentials for the service you select. It is an alternative notification path, not a replacement for a functioning MTA when the jail uses action_mw or action_mwl.

Choose the path based on your operational dependency:

Requirement Email action Apprise action
Delivery component Sendmail or another configured MTA Apprise configuration and credentials for the selected service
Message detail action_mw or action_mwl controls Whois and log-line content Depends on the configured Apprise action
Failure investigation Inspect Fail2ban and MTA logs separately Inspect Fail2ban and the external service’s delivery status separately

Do not configure both paths casually: every additional destination increases alert volume and creates another credential and delivery policy to maintain.

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

Operational checklist

  • Store changes in jail.local, jail.d/, or an action-local override rather than modifying packaged defaults.
  • Set destemail, sender, mta, and an email action in [DEFAULT].
  • Choose action_mw for Whois-only context or action_mwl when matching log lines are needed.
  • Enable the intended jail and verify its filter, source, backend, and thresholds.
  • Run sudo fail2ban-client -d after substantial edits or whenever startup fails.
  • Restart the service and inspect both overall and jail-specific status.
  • Test from a controlled, allowed source while preserving an administrative session.
  • Trace the event through Fail2ban’s log, the action, the MTA log, and the destination mailbox.
  • Review ignoreip and DNS behavior before exposing a jail to real traffic.
  • Retune maxretry, findtime, and bantime when alert volume or lockout risk changes.

Bottom line

Reliable Fail2ban alerts come from a complete chain: a jail that reads the right events, an email action that includes the detail you need, and an MTA that can deliver the message. Keep local overrides separate, validate the parsed configuration, and diagnose Fail2ban detection and mail delivery as independent stages.

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.

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.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

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.