This guide illustrates how to block traffic by country using the CSF firewall. The ability to control and filter traffic at the country level is one of the most frequently requested capabilities for cPanel servers that you can carry out using the Webhost Manager Plugin for ConfigServer Firewall (CSF).
The most frequent reasons for a server administrator to block traffic from a certain country include:
- Lowering bandwidth usage.
- Reduced security threats.
- Confirm that a site’s content may be viewed in areas where it is permissible.
Furthermore, while selecting to filter traffic at the national level, there are several important factors to consider:
- Some web services and ISPs assign non-geographic IP addresses to their customers.
- For country-level blocks, the CIDR range lists are not always accurate.
- The true location of a visitor can be concealed via proxy services and virtual private networks.
- Filtering at the country level only affects inbound connections. Traffic heading out is unaffected.
- The performance of your websites will suffer if you use country-level filtering, and you will notice slower response times.
Here we are assuming that you already have CSF installed on your cPanel server, so let us follow the steps to block traffic by country using the CSF firewall:
- Log in to WHM.
- Find and select the “Plugins” option.
- Click on the “ConfigServer Security & Firewall” sub-option.
- You will enter the the “ConfigServer security & firewall” page.
- Scroll down and choose the “csf – ConfigServer Firewall” option, then click on the “Firewall configuration” option.
- You will find two options:
a) Two-letter country codes, such as “US” for the United States of America, “GB” for Great Britain, and “DE” for Germany, are accepted in the CC DENY field.
b) You can block access to multiple nations by separating them with commas and leaving no spaces, for example, “US, GB, DE” to block access to the US, Great Britain, and Germany.
a) The CC ALLOW field should NOT be used to enable traffic by country code. CC ALLOW overrides any port and protocol rules in place and opens the firewall to all traffic on all ports coming from the countries indicated.
- Scroll down and click on the “Change” button as shown in the image given below.
- You will get a message that the changes have been saved and that you should restart csf and lfd.
- Click on the “Restart csf+lfd” button.
Note- You may find a list of ISO 3166-1 alpha-2 codes at https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
This way you can deny or block traffic by country using the CSF Firewall in WHM. If you have any query, please, contact our support team they will surely help you out.