How to Block Countries Using CSF : Easy Steps

Block countries using CSF
This article will help you to block countries using CSF Firewall. We can do this from CSF configuration file.

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.

Share this post

Services to Explore

Stay up to date!

Stay up to date with the Web Hosting, Cloud and Server Management Industry News and Tutorials!

We will send you only the relevant emails, and we respect your privacy. Please review our privacy policy for more info.

Linux Management Services

Focus on your business, and let us take care of your Linux Servers!
From what you are reading, it seems you are interested in Linux and related technologies. If you have a moment to spare, please take a look at our Linux Management Services plan, which might interest you even more!
Linux Management Plan

Value-Added Services

We have services that can help you run a successful business. With us, you don't have to worry about these areas because our experts will take care of it for you.

Introducing - WPHealers!

Complete WordPress Management, 24x7 Support & White Label Agency Plans!

WordPress migration service, security, white-label reseller services and lot more! Grab the introductory deals now!

WPHealers

ServerHealers uses cookies.