Join to Get Free Linux Server Hacks & cPanel Tips

How can I block IP ranges using CSF Firewall?

How can I block IP ranges using CSF Firewall?
5 (100%) 10 votes

CSF Firewall is one of the most complete server security suites around. It can help you to harden the security of your cPanel server up to the max. CSF is an iptables based firewall, and as such, it allows the server administrator to block offending incoming connections.

One of the advanced things it allows is the ability to block IP ranges. Days ago we published a post where we learned how to calculate IP address on Specific CDIR Subnet Ranges, and today we will show you how to block IP ranges using CSF firewall.

How to Block IP Ranges in CSF Firewall?

If you want to block a complete IP range in CSF firewall, please follow these steps:

Let’s say you want to block following IP range:

1.- Login as root into the WHM panel

2.- Search forWHM >> Plugins >> ConfigServer Security & Firewall

3.- Find the “Quick Deny” box and add the following:

That’s all.

In order for CSF to pick up the changes, you need to restart the firewall.

This kind of IP block can be done from the linux terminal using the ‘csf -d’ command, as you see below

csf -d

Then csf -r to apply changes:

csf -r

How can I block a /8 range?

To block range use this:

To block range use this:

How can I check the range was blocked proplery?

You can run this command to check if your blocking is active and working as expected:

[]iptables -L -n | grep 188.143.232
DROP all --

Just replace “188.143.232” with the IP number in your blocked range, that should do the trick.

How can I Block Country IP Ranges in CSF Firewall?

CSF allows you to block an entire country if you want, just edit csf.conf file from terminal.

nano -w /etc/csf/csf.conf

find this variable:

CC_DENY = ""

and set the country codes you want to block separated with a comma.

Example if you want to block UK and Russia:


Restart CSF to apply changes

csf -r


As you see, if you need to block ip ranges in CSF Firewall you can do it from the command line using ‘csf -d’ or from the ConfigServer Security & Firewall interface in WHM control panel.

You can even block country IP ranges if you want, just make sure you or your users don’t receive any traffic from there, otherwise none will be able to reach your server.