#Country ban with UFW#
Grab your different country ip addresses and save as Linux IPTables
http://www.ip2location.com/free/visitor-blocker
##Add country## Run the following command
while read line; do sudo ufw deny from $line; done < all.txt
Where the filename is the country.
##Remove country## To remove or revert these rules, keep that list of IPs! Then run a command like so to remove the rules:
while read line; do sudo ufw delete deny from $line; done < all.txt
##Suggestion## What I did was exported each individual country as their own country.txt file. But then realized that I wanted to run this thing one time, so I ran the following command:
cat *.txt >> all.txt
Then you can run your rule against all of the files.
Yes, that looks sensible. The main point is to use ipset(s) to hold the big list of IPs and do the testing in the firewall rules.
One point, however: you are using an ipset of type "hash:ip". I don't know what you are using for the list of addresses. Most come as a list of IP ranges, so I would guess that "hash:net" would be more appropriate. You also might want to set the size of the table when you create it, but that will only speed up the inital load (I would guess; not an expert on it).