Last active
May 4, 2020 11:07
-
-
Save rohan-molloy/ca5ce1907e61141a0906c465ad89cd7a to your computer and use it in GitHub Desktop.
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 | |
# Set the country code (in lower case) | |
cc=nz | |
# Create the ipset | |
ipset create allowed_country hash:net | |
# Load the country set | |
wget -qO- "https://iplists.firehol.org/files/geolite2_country/country_$cc.netset" | grep -v ^# | xargs -n1 ipset add allowed_country | |
# Create chain to restrict by country | |
iptables -N restrict_by_country | |
iptables -A restrict_by_country -m set --match-set allowed_country src -j ACCEPT | |
iptables -A restrict_by_country -j LOG | |
iptables -A restrict_by_country -j REJECT | |
# Replace ens32 with your interface | |
iptables -I INPUT -i ens32 -m conntrack --ctstate NEW,UNTRACKED -j restrict_by_country |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment