Created
July 25, 2013 02:38
-
-
Save user454322/6076479 to your computer and use it in GitHub Desktop.
iptables chain to restrict SSH login attempts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#-- Creates a SSH-fal chain | |
/sbin/iptables -N SSH-fal | |
#-- Only 3 login attempts can be done from the same IP whithin a minute | |
/sbin/iptables -A SSH-fal -p tcp --dport 22 -m state --state NEW -m recent --set --name SSH | |
/sbin/iptables -A SSH-fal -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 60 --hitcount 2 --rttl --name SSH -j LOG --log-prefix "IPTABLES: failed login attempt" | |
/sbin/iptables -A SSH-fal -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 60 --hitcount 3 --rttl --name SSH -j DROP | |
#-- Load rules definided in SSH-fal | |
/sbin/iptables -A INPUT -j SSH-fal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment