Created
March 1, 2012 17:46
-
-
Save n8foo/1951639 to your computer and use it in GitHub Desktop.
ssh limit with iptables
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/bash | |
# this iptables rules sets an ssh limit of 4 per 60 seconds | |
IPT=`which iptables` | |
$IPT -A ssh_limit -p tcp -m recent --set --name ssh --rsource | |
$IPT -A ssh_limit -p tcp -m recent ! --rcheck --seconds 60 --hitcount 4 --name ssh --rsource -j ACCEPT | |
$IPT -A ssh_limit -j LOG --log-level info --log-prefix "SSH_LIMIT: " | |
$IPT -A ssh_limit -j DROP | |
# jump to the above chain inside the INPUT chain | |
$IPT -A INPUT -i eth0 -p tcp -s 0/0 --dport 22 -j ssh_limit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment