Created
August 9, 2017 17:26
-
-
Save tcely/293d250449ac59119a9e0f3cedc7f607 to your computer and use it in GitHub Desktop.
SSH brute-force limiting using 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/sh | |
iptables -F SSH_PORT_LIMIT || iptables -N SSH_PORT_LIMIT | |
iptables -A SSH_PORT_LIMIT -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT | |
iptables -A SSH_PORT_LIMIT -p tcp -m state --state NEW -m hashlimit --hashlimit-mode srcip --hashlimit-upto 10/hour --hashlimit-burst 15 --hashlimit-name ssh -j ACCEPT | |
iptables -A SSH_PORT_LIMIT -j LOG --log-level info --log-prefix 'ssh-port-limit: ' | |
iptables -A SSH_PORT_LIMIT -p tcp -j REJECT --reject-with tcp-reset | |
iptables -A SSH_PORT_LIMIT -j DROP | |
iptables -C INPUT ! -i eth1 -p tcp --dport 22 -j SSH_PORT_LIMIT || iptables -A INPUT ! -i eth1 -p tcp --dport 22 -j SSH_PORT_LIMIT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment