Allow and Deny by IP Address

From Lunarpages Web Hosting Wiki

Having issues with somebody at a particular IP address that is giving you problems? Are they bugging your users or poking you with the proverbial stick of annoyance? There are two ways to block an IP, first through the IP Deny Manager in cPanel, and the other by manually editing your .htaccess file.

cPanel IP Deny Manager

Log into your cPanel and scroll down to the Security section and click the icon for IP Deny Manager.

Cpanel ip deny.png

Enter the IP address, or range, and click the Add button. Acceptable entries are:

  • (Single IP Address)
  • (Range)
  • (Implied Range)
  • (CIDR Format)
  • 10. (Implies 10.*.*.*)

At the bottom of the page you will find a list of the current IP addresses being blocked. If you need to remove an IP address, click on the red X under the Remove column.

Editing your .htaccess file

To get this done, all you need to do is add this to your .htaccess file:

   order allow,deny
   deny from XXX.XXX.XXX
   allow from all

Just replace the “XXX.XXX.XXX” with the IP address you wish to block. You can also add a second line like this if you wish to block multiple IP addresses:

   order allow,deny
   deny from XXX.XXX.XXX
   deny from MMM.MMM.MMM
   allow from all

One last tip. If you want to block everybody from seeing your web site, just put in deny from all.

   order deny,allow
   allow from QQQ.QQQ.QQQ
   allow from LLL.LLL.LLL
   deny from all

This would turn everybody away except for the people who have the IP address QQQ.QQQ.QQQ and LLL.LLL.LLL.

For more help with getting this done, check out the official Apache page on the process: