How to ban or block an IP address from visiting my website?

You can make use of .htaccess files in order to block an IP address from accessing your website. A .htaccess is a kind of configuration file that can be used from things like setting password-protected directories, preventing the display of file extensions to, of course, restricting access based on IP.

To ban an IP address from accessing your website, create a .htaccess file within your root directory (usuallypublic_html or www) and add the following configuration in the file:

order allow,deny
deny from
allow from all

It’s pretty simple to understand what’s going on here. “order allow,deny” is specifically in this order so that the allow rules are checked first, and if someone matches a deny rule, their server request is refused (i.e. they’re blacklisted). If you have the order as “deny,allow”, the deny rules are checked first and the allow rules after. If you had it ordered “deny,allow”, the allow rule is evaluated last, so you can imagine what would happen – hence, “order allow,deny” evaluates deny rules last.

In the example above, we’re blacklisting In real use, you’ll need to change this to the IP address in which you want to blacklist. You can, of course, blacklist multiple IP addresses by listing multiple deny rules on a separate line. For example:

order allow,deny
deny from
deny from
deny from
deny from
allow from all

If you want to block an entire IP range, you simply exclude a specific octet in the .htaccess rule:

order allow,deny
deny from 127.0.0
allow from all

This will blacklist IP addresses in the range through to An octet is each part of the IP address (i.e. 127, 0, 0, 1).

Note: If you can’t see your .htaccess file listed in your FTP client it may be hidden depending on the file manager you are using, because the file starts with a period character. If this is the case, you’ll need to find the option in the menu of the FTP client you are using to show hidden files.

IP Ban Deny Image

In most control panels for Linux- and Windows-based hosting, you can blacklist IPs using a graphical user interface instead of having to do so via a .htaccess text file. In cPanel, go to the IP Deny Manager (in the Security category) to blacklist IPs from accessing your website. Just like doing so directly within a .htaccess file, you can specify a complete IP address or a specific range.

Note: Be careful when you are blacklisting an IP range. Don’t blacklist an IP range too broadly if you are concerned of blacklisting genuine visitors.

  • 14 Users Found This Useful
Was this answer helpful?

Related Articles

Ho do I Enable TUN/TAP in Solus VM

TUN (namely network TUNnel) simulates a network layer device and it operates with layer 3 packets...

How to Change A Records in cPanel

The article defines steps for Updating an A record in cPanel for a particular domain...

How to install Fantastico on cPanel/WHM

You don't need to download any files in order to install Fantastico! Just SSH to your server and...

How do I connect to my VPS? (SSH)

We recommend the program PuTTY for SSH. You can download it...

How to redirect domain to subdirectory without redirecting url

If you want to redirect your domain name to sub-directory but the url shows only domain name For...

Powered by WHMCompleteSolution