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 (usually public_html or www) and add the following configuration in the file:

    order allow,deny
    deny from 127.0.0.1
    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 127.0.0.1. 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 127.0.0.1
    deny from 127.0.0.1
    deny from 127.0.0.1
    deny from 127.0.0.1
    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 127.0.0.0 through to 127.0.0.255. 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 Deny Manager in cPanel control panel

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
  • 44 کاربر این را مفید یافتند
آیا این پاسخ به شما کمک کرد؟

مقالات مربوطه

Can I use my domain name or must I use my IP address as the hostname for FTP?

Using your IP address (192.168.22.22  is an example IP address) is the preferred entry for...

Can you transfer my sites from my current host to my new VPS?

Yes. We will transfer all of your sites free* of charge and will assure that you experience no or...

Do you allow MP3 files? Do you allow streaming of videos?

Yes we do with our special plans at http://hostripples.in/avs-hosting.php

Do you support Cold Fusion?

We do not support or Cold Fusion on our shared hosting servers, however you are more than welcome...