Skip to content

Instantly share code, notes, and snippets.

@n8foo
Created March 1, 2012 17:46
Show Gist options
  • Save n8foo/1951639 to your computer and use it in GitHub Desktop.
Save n8foo/1951639 to your computer and use it in GitHub Desktop.
ssh limit with iptables
#! /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