Last active
December 10, 2019 20:47
-
-
Save adam12/0dd5835004fe018a503b4b39d29ea4e5 to your computer and use it in GitHub Desktop.
Block some countries from SSH-bruteforcing using ipset
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 | |
# vim:ts=2:sts=2:sw=2:et:ft=sh: | |
IPSET="ipset" | |
IPTABLES="iptables" | |
SETNAME="geoblock" | |
$IPSET create $SETNAME hash:net | |
for IP in $(curl -s http://www.ipdeny.com/ipblocks/data/countries/{cn,ru,kr,pk,tw,sg,hk,ar}.zone) | |
do | |
$IPSET add $SETNAME $IP | |
done | |
$IPTABLES -I INPUT -m set --match-set $SETNAME src -p tcp --dport 22 -j DROP |
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
5.8.88.0/24 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's the same for a later version:
ipset v7.1: Syntax error: Second element is missing from 185.197.32.0/22.
ipset v7.1: Syntax error: Second element is missing from 185.197.72.0/22.
ipset v7.1: Syntax error: Second element is missing from 185.197.232.0/22.