BuycPanel Blog

BuycPanel Blog

Latest news and updates

12/08/2014 – Blocking IP Addresses with cPanel

Posted by Jamison on 08 12 2014.

You want a lot of people to visit your website, but for one reason or another you don’t want just everyone to be able to do that, do you?

 

You reasons may be varied; you might have content that is off-limits to those below 18 years old, you might have material that is considered illegal when viewed in another country, or perhaps you might want to limit access to paying subscribers.

 

Whatever your reason is, with cPanel you can block any IP address from accessing your site.

 

How to find out a visitor’s IP address

 

First things first, you can use the web statistics tools to find more information on your visitors. Go to cPanel and click on the Latest Visitors icon. Look for the Host information; it could be either an IP or a domain name.

 

How to block the IP address

 

  1. Login to cPanel.
  2. Go to the Security section and click IP Deny Manager.
  3. Under “Add an IP to deny”, enter IP address or domain name that needs to be blocked.

 

You can put as many as you want, although it is suggested you limit the number of IP addresses blocked. If you want to block a considerable number of IP addresses you might need the help of your webhost server.

 

  1. Click the Add button.

 

How to unblock the IP address

 

  1. Login to cPanel.
  2. Go to the Security section and click IP Deny Manager.
  3. Scroll down to the bottom, under “Current IP addresses being blocked”, click Remove.

 

If you want to deny everyone from accessing your site it gets a little more complicated because this must be done by coding your .htaccess file as follows:

 

deny from all

allow from (server IP address)

allow from (your IP address) #my house

 

Remember that it is possible to block access to yourself accidentally by doing this, so be sure to allow access via your IP otherwise you will be blocked as well.

 

You can find out your current IP address by visiting www.whatismyip.org. If you find you have accidentally blocked yourself, contact you webhost server immediately. As a safeguard they will require you to confirm your identity and verify your account before they can unblock your IP.

 

Can you block an entire region or country from seeing your site? With cPanel’s mod-geoip you can. Just follow the steps below:

 

  1. SSH to your server as root
  2. Get the latest mod-geoip version from cPanel
  3. Unpack it into cPanel’s easyapache directory
  4. Run easyapache in choose the mod_geoip option
  5. Save and build your easyapache choices
  6. Tell apache about the GeoIP .dat file using:

 

Edit /usr/local/apache/conf/includes/pre_main_global.conf

 

Add the following lines:

 

  • GeoIPEnable On
  • GeoIPDBFile /opt/geoip/share/GeoIP/GeoIP.dat

 

  1. Restart apache
  2. Now you can start blocking

 

For servers

 

We have nothing against Russia, but say for example you don’t want your site to be accessed from there. Go back to the GeoIP .dat file:

 

Edit /usr/local/apache/conf/includes/pre_main_global.conf again and make it look like this:

 

  1. GeoIPEnable On
  2. GeoIPDBFile /opt/geoip/share/GeoIP/GeoIP.dat
  3. RewriteEngine on
  4. RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(RU)$
  5. RewriteRule ^(.*)$ http://www.linuxbrigade.com$1 [L]

 

Russia will now be blocked.