Script iptables SSHlimit.sh

From campisano.org
Jump to navigation Jump to search
#!/bin/sh
#
# Network firewall config

PATH=/sbin:/bin:/usr/sbin:/usr/bin;

RET_CODE=0

case "$1" in
    start)
        iptables -I INPUT 1 -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 60 --hitcount 2 --name SSH_LIST -j DROP;
        iptables -I INPUT 2 -p tcp --dport 22 -m state --state NEW -m recent --set --name SSH_LIST;
        ;;
    stop)
        iptables -D INPUT -p tcp --dport 22 -m state --state NEW -m recent --set --name SSH_LIST;
        iptables -D INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 60 --hitcount 2 --name SSH_LIST -j DROP;
        ;;
    status)
        iptables -L -n -v;
        ;;
    restart|reload|force-reload)
        echo "Error: argument '$1' not supported" >&2;
        RET_CODE=1;
        ;;
    *)
        echo "Usage: $0 {start|stop|status}";
        RET_CODE=1;
        ;;
esac;

exit "${RET_CODE}";

# End