Do you know how easy it is to block countries using the CSF firewall?
If you haven’t done it yet and want to do it, follow the steps mentioned below.
Before we start
If you haven’t installed CSF yet, please follow my tutorial – How to install CSF ( Configure Config Server Firewall ) in Linux?
You will get the country codes from – CSF Country Code : Full List
1) Block only particular countries and allow access from all other countries.
For this, open CSF main configuration file “/etc/csf/csf.conf”, and you can see the below line
CC_DENY = ""
Enter the county codes that you want to block. ( Eg, US, GB, DE )
CC_DENY = "US,GB,DE"
Now restart CSF
csf -r
( Make sure to restart CSF using “csf- r” /etc/init.d/scf is just to start the process. It won’t reload the rules. )
That’s it! You have blocked access from the mentioned countries, and all other countries will have access.
2) Allow access from particular countries and block access from all other countries.
For this open CSF main configuration file “/etc/csf/csf.conf”, and you can see the below lines.
CC_ALLOW = "" CC_ALLOW_FILTER = ""
The method is the same here, and you can add the country code in either one of the lines. ( Don’t put the country codes in both of the lines. ) But there are some between “CC_ALLOW” and “CC_ALLOW_FILTER”.
CC_ALLOW: Block IPs and won’t bypass the existing firewall rules. ( Suppose you were having hack and spam issues, and you blocked these IPs using the firewall. If you allow countries using CC_ALLOW, it will bypass those firewall rules if those IPs are from these countries. )
CC_ALLOW_FILTER ( Recommended method ): This is the recommended method, and using this method, we can allow countries, and it won’t bypass the existing firewall rules.
So that’s how you do – CSF Country Block.