#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.
Note that you can only look up one country at a time with IP2Location unless you sign up for a "free" account, but if you read the license terms that you must agree to, this practice is banned. They do have a lite version available of the database for download (licensed CC BY-SA 4.0), which they claim is >98.0% accurate, versus the >99.5% that they claim for their commercial product with Draconian terms and hidden fees.
You can also install CSR, which uses MaxMind's secretive GeoLite database (also licensed CC BY-SA 4.0).
With GDPR on the horizon, we need a new option that doesn't break the bank. Quickly.