|
|
Ligne 31 : |
Ligne 31 : |
| Si vous souhaitez modifier d'autres fichiers de configuration de fail2ban, copiez le fichier en question en changeant l'extension de <code>.conf</code> à <code>.local</code>. Vous pourrez ensuite modifier le fichier .local et éviter de toucher à la configuration par défaut de fail2ban. | | Si vous souhaitez modifier d'autres fichiers de configuration de fail2ban, copiez le fichier en question en changeant l'extension de <code>.conf</code> à <code>.local</code>. Vous pourrez ensuite modifier le fichier .local et éviter de toucher à la configuration par défaut de fail2ban. |
|
| |
|
| =Compléments= | | =Faire tourner fail2ban en tant qu'utilisateur plutot que root= |
| | |
| Si une ip vous harcèle, vous pouvez la bannir définitivement avec iptables. Pour simplifier les opérations, j'ai créé un petit script bash :
| |
| <pre>
| |
| #! /bin/sh
| |
| #conf
| |
| banned_file=/srv/link/banned.list
| |
| | |
| #script
| |
| me=`dirname $0`/
| |
| | |
| if [ "$2" = "quiet" ]; then quiet=1; else quiet=0; fi
| |
| | |
| case "$1" in
| |
| start)
| |
| /sbin/iptables -N morales
| |
| /sbin/iptables -A INPUT -p tcp -m multiport --dports ssh,telnet,ftp,ftp-data,ftps,ftps-data,http,https,pop3,pop3s,imap,imaps,submission -j morales
| |
| if [ -f "$banned_file" ]; then
| |
| for ligne in `cat "$banned_file"`; do
| |
| /sbin/iptables -A morales -s $ligne -j DROP
| |
| done
| |
| else
| |
| touch "$banned_file"
| |
| fi
| |
| if [ $quiet = 0 ]; then echo "Started"; fi
| |
| exit 0
| |
| ;;
| |
| stop)
| |
| /sbin/iptables -F morales
| |
| /sbin/iptables -D INPUT -p tcp -m multiport --dports ssh,telnet,ftp,ftp-data,ftps,ftps-data,http,https,pop3,pop3s,imap,imaps,submission -j morales
| |
| /sbin/iptables -X morales
| |
| if [ $quiet = 0 ]; then echo "Stoped"; fi
| |
| exit 0
| |
| ;;
| |
| restart)
| |
| $0 stop $2
| |
| $0 start $2
| |
| exit 0
| |
| ;;
| |
| add)
| |
| if [ "$2" = "" ]; then
| |
| echo "Usage: $0 add <ip>"
| |
| exit 1
| |
| fi
| |
| /sbin/iptables -A morales -s $2 -j DROP
| |
| if [ "$?" = "0" ]; then
| |
| echo "$2" >> "$banned_file"
| |
| echo "Added $2"
| |
| exit 0
| |
| else
| |
| echo "Error"
| |
| exit 1
| |
| fi
| |
| exit 0
| |
| ;;
| |
| del)
| |
| if [ "$2" = "" ]; then
| |
| echo "Usage: $0 del <ip>"
| |
| exit 1
| |
| fi
| |
| /sbin/iptables -D morales -s $2 -j DROP
| |
| if [ "$?" = "0" ]; then
| |
| sed /$2/d "$banned_file" > "$banned_file".tmp
| |
| mv "$banned_file".tmp "$banned_file"
| |
| echo "Removed $2"
| |
| exit 0
| |
| else
| |
| echo "Error"
| |
| exit 1
| |
| fi
| |
| exit 0
| |
| ;;
| |
| flush)
| |
| /sbin/iptables -F morales
| |
| rm -f "$banned_file"
| |
| touch "$banned_file"
| |
| echo "ok"
| |
| exit 0
| |
| ;;
| |
| list)
| |
| echo "Currently banned ips :"
| |
| /sbin/iptables -L morales
| |
| exit 0
| |
| ;;
| |
| *)
| |
| echo "Usage: $0 {start|stop|restart|add|del|flush|list} [quiet]"
| |
| exit 1
| |
| ;;
| |
| esac
| |
| </pre>
| |