Fail2ban not sending email notifications

GreenTeaTech picture GreenTeaTech · Sep 17, 2014 · Viewed 24.7k times · Source

My CentOS server has postfix as MTA and it’s working. When I type the command mail -s "testing" <my gmail address>, I receive the email.

However, Fail2ban is unable to send emails to my gmail address when an IP gets banned. I’m probably missing some configuration in jail.conf.

Here is part of my jail.conf file:

destemail = [email protected]
sendername = fail2ban
mta = sendmail
protocol = tcp
action = %(action_mwl)s

I already tried mta = postfix and it didn’t work.

Thanks in advance for your help.

EDIT: I was able to make it work. None of the configuration above is correct for my fail2ban v0.8.10 and my linux CentOS 6. In fact, I removed all the lines above (garbage).

I found a pre-defined action in /etc/fail2ban/action.d/mail.conf file. I noticed this action uses "mail -s" command which works on my server. So, I decided to use this action in my jail.conf file as such:

[ssh-iptables]
enabled  = true
filter   = sshd
action   = iptables[name=SSH, port=ssh, protocol=tcp]
           mail[name=ssh, [email protected]]
logpath  = /var/log/secure
maxretry = 5

The only thing that needs to be change to get an email from fail2ban is to add that line below “action” that starts with “mail.” Very simple and easy.

Answer

Tom picture Tom · Feb 1, 2016

You should change mta = sendmail to:

mta = mail