CentOS
yum -y install epel-release
yum install fail2ban fail2ban-systemd -y
Ubuntu
apt-get update && apt-get upgrade -y
apt-get install fail2ban
ufw allow ssh
ufw enable
Se habilita el servicio para que levante al reboot
systemctl enable fail2ban
Se inicia el servicio
systemctl start fail2ban
Configuracion
No usar el archivo de configuracion default /etc/fail2ban/jail.conf se debe hacer una copia
cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
nano /etc/fail2ban/jail.local
modificar los parametros ignoreip = 127.0.0.1,ipnueva,ipueva,etc
Modificar la linea backend = auto por backend = systemd
Agregar ssh a fail2ban
nano /etc/fail2ban/jail.d/sshd.local
[sshd]
enabled = true
port = ssh
action = iptables-multiport
logpath = /var/log/secure
maxretry = 5
bantime = 600
Si se desea mandar las notificaciones por email modificar:
destemail = cesar.vazquez@kpt.com.mx
sender = root@mxserver3.kpt.com.mx
mta = mail (este parametro cambia si se usa sendmail o mail(o mailx))
En los jails hay que modificar los actions a alguno de estos 2:
action = %(action_mw)s action = %(action_mwl)s action_mwl = %(banaction)s[name=%(name)s, port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"] %(mta)s-whois-lines[name=%(name)s, dest="%(destemail)s", logpath=%(logpath)s, chain="%(chain)s", sendername="%(sendername)s"]
Reiniciar fail2ban
- systemctl restart fail2ban
Checar que agrego las reglas
- iptables -L –line-numbers -n -v
Checar status de fail2ban
- fail2ban-client status
- fail2ban-client status sshd
Si se quiere desbanear
- fail2ban-client set JAIL unbanip IPADDRESS
Ejemplo
- fail2ban-client set sshd unbanip 192.168.1.101