Fail2ban Email Configuration – Fix Emails Sent to Root Instead of Custom Email

fail2ban

I have fail2ban setup and working on my system. In /etc/fail2ban/jail.local, I have the following for my destination email:

destemail = me@address.com

Yet, looking through my /var/log/mail.log file, I keep seeing:

Jul 23 21:19:04 picus sendmail[21205]: x6O1J489021205: from=fail2ban, size=210, class=0, nrcpts=1, msgid=<201907240119.x6O1J489021205@major-productions.com>, relay=root@localhost
Jul 23 21:19:04 picus sm-mta[21207]: x6O1J4vh021207: from=<fail2ban@major-productions.com>, size=461, class=0, nrcpts=1, msgid=<201907240119.x6O1J489021205@major-productions.com>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Jul 23 21:19:04 picus sendmail[21205]: x6O1J489021205: to=root, delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30210, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (x6O1J4vh021207 Message accepted for delivery)
Jul 23 21:19:04 picus sm-mta[21208]: x6O1J4vh021207: to=linode, ctladdr=<root@major-productions.com> (8/0), delay=00:00:00, mailer=local, pri=120461, dsn=5.1.1, stat=User unknown
Jul 23 21:19:04 picus sm-mta[21208]: x6O1J4vh021207: to=<fail2ban@major-productions.com>, delay=00:00:00, mailer=local, pri=30680, dsn=5.1.1, stat=User unknown
Jul 23 21:19:04 picus sm-mta[21208]: x6O1J4vh021207: to=linode, ctladdr=root (8/0), delay=00:00:00, mailer=local, pri=30680, dsn=5.1.1, stat=User unknown
Jul 23 21:19:04 picus sm-mta[21208]: x6O1J4vh021207: x6O1J4vh021208: postmaster notify: User unknown
Jul 23 21:19:04 picus sm-mta[21208]: x6O1J4vh021208: to=linode, ctladdr=root (8/0), delay=00:00:00, mailer=local, pri=0, dsn=5.1.1, stat=User unknown
Jul 23 21:19:04 picus sm-mta[21208]: x6O1J4vh021208: to=linode, ctladdr=root (8/0), delay=00:00:00, mailer=local, pri=0, dsn=5.1.1, stat=User unknown
Jul 23 21:19:04 picus sm-mta[21208]: x6O1J4vh021208: x6O1J4vi021208: return to sender: User unknown
Jul 23 21:19:04 picus sm-mta[21208]: x6O1J4vi021208: to=linode, ctladdr=root (8/0), delay=00:00:00, mailer=local, pri=0, dsn=5.1.1, stat=User unknown
Jul 23 21:19:04 picus sm-mta[21208]: x6O1J4vh021208: Saved message in /var/lib/sendmail/dead.letter

It keeps trying to send it to the root account on my machine rather than my email address. Am I missing some configuration option somewhere?

EDIT: after a bit of tinkering, I've been able to somewhat correct the problem. I changed:

dest = root

to

dest = me@address.com

in /etc/fail2ban/action.d/mail.conf. With that change, I'm now receiving emails that pertain to my ssh/ssh-ddos jails. However, I'm still not receiving emails from my recidive jail. Looking at /etc/fail2ban/jail.local, I see that it invokes something that collates/formats various WHOIS data for banned accounts in that particular jail.

More digging in the various configuration files led me to /etc/fail2ban/action.d/sendmail-common.conf which, like the other various configuration files I looked at, has dest = root.

Now, I could tweak these various configuration files to all use my email address as the destination, but I'm getting the feeling that's more or less the equivalent of hammering a round peg into a square hole. Is there a better way to force fail2ban to just default to using my email as the destination address? Is there a potential configuration problem with my sendmail installation (I can receive emails from OSSEC and my web app with no issue)?

Best Answer

I have the exact same problem on my Debian 10 server. That one is a nasty one as it doesn't really give error messages where you could track it down as there is no real error...

Up there Michael Hampton was giving the right hint. Thank you.

SOLUTION:

Set your 2 emails in every rule where you use it, then it suddenly worked.

Like so:

[sshd]  
enabled   = true
port      = 22
filter    = sshd
logpath   = /var/log/auth.log
sender    = sender@example.com
destemail = me@address.com
action    = %(action_mwl)s

It turns out that although I had it in the default declarations , invisibly it didn't get accepted... without giving an error... some random formatting error like an empty line or a comment or so....

Related Topic