I'm trying to implement fail2ban
on a Ubuntu 12.04 x64 server. I've done the following:
apt-get install fail2ban
Made a copy of jail.conf
in /etc/fail2ban/jail.conf.local
here's an excerpt:
[DEFAULT]
# "ignoreip" can be an IP address, a CIDR mask or a DNS host
ignoreip = 127.0.0.1/8
bantime = 600
maxretry = 3
[ssh]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 3
bantime = 600
Then I ran service fail2ban restart
and I do see it running. Now I try to login as a user (root, random user, etc) multiple times in a row and it does not block my IP address. I have iptables
installed and it working with rules I have setup and I do have a INPUT
chain in place of course.
When I cat /var/log/auth.log
this is what I see
Oct 26 08:55:21 prod sshd[10935]: reverse mapping checking getaddrinfo for firewall.jaincpa.com [75.89.97.25] failed - POSSIBLE BREAK-IN ATTEMPT!
Oct 26 08:55:23 prod sshd[10935]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=75.89.97.25 user=root
Oct 26 08:55:25 prod sshd[10935]: Failed password for root from 75.89.97.25 port 61449 ssh2
Oct 26 08:55:32 sshd[10935]: last message repeated 2 times
Oct 26 08:55:32 prod sshd[10935]: Connection closed by 75.89.97.25 [preauth]
Oct 26 08:55:32 prod sshd[10935]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=75.89.97.25 user=root
Oct 26 08:55:34 prod sshd[10944]: reverse mapping checking getaddrinfo for firewall.jaincpa.com [75.89.97.25] failed - POSSIBLE BREAK-IN ATTEMPT!
Oct 26 08:55:35 prod sshd[10944]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=75.89.97.25 user=root
Oct 26 08:55:37 prod sshd[10944]: Failed password for root from 75.89.97.25 port 61452 ssh2
Oct 26 08:55:44 sshd[10944]: last message repeated 2 times
Oct 26 08:55:44 prod sshd[10944]: Connection closed by 75.89.97.25 [preauth]
Oct 26 08:55:44 prod sshd[10944]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=75.89.97.25 user=root
Oct 26 08:55:47 prod sshd[10951]: reverse mapping checking getaddrinfo for firewall.jaincpa.com [75.89.97.25] failed - POSSIBLE BREAK-IN ATTEMPT!
Oct 26 08:55:51 prod sshd[10951]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=75.89.97.25 user=root
Oct 26 08:55:52 prod sshd[10951]: Failed password for root from 75.89.97.25 port 61455 ssh2
Oct 26 08:56:00 sshd[10951]: last message repeated 2 times
Oct 26 08:56:00 prod sshd[10951]: Connection closed by 75.89.97.25 [preauth]
Oct 26 08:56:00 prod sshd[10951]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=75.89.97.25 user=root
Oct 26 08:56:13 prod sshd[10971]: reverse mapping checking getaddrinfo for firewall.jaincpa.com [75.89.97.25] failed - POSSIBLE BREAK-IN ATTEMPT!
Oct 26 08:56:15 prod sshd[10971]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=75.89.97.25 user=root
Oct 26 08:56:16 prod sshd[10971]: Failed password for root from 75.89.97.25 port 61459 ssh2
Oct 26 08:56:22 sshd[10971]: last message repeated 2 times
Oct 26 08:56:22 prod sshd[10971]: Connection closed by 75.89.97.25 [preauth]
Oct 26 08:56:22 prod sshd[10971]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=75.89.97.25 user=root
Oct 26 08:57:18 prod sshd[11002]: Connection closed by 50.116.16.93 [preauth]
Oct 26 09:00:01 prod CRON[11099]: pam_unix(cron:session): session opened for user deploy by (uid=0)
Oct 26 09:00:02 prod CRON[11099]: pam_unix(cron:session): session closed for user deploy
Oct 26 09:02:18 prod sshd[11186]: Connection closed by 50.116.16.93 [preauth]
root@prod:/etc/fail2ban#
So it looks like I'm authenticating with PAM
via sshd
but fail2ban
is not blocking my IP address and I can still attempt login and login when supplying the proper credentials.
I'd like to get this working as I've seen a lot of brute force attacks on my server lately. Any help would be greatly appreciated.
It looks like I needed to specify the backend to get this to working. It was defaulting to
gamin
whih wasn't working. I changed the configuration tobackend = polling
and got fail2ban working properly. Haven't received any email notifications of blocking, but I'm close to figuring that out too.