Block Countries using mod_geoip in cPanel

Rob —  June 27, 2013 — 2 Comments

Yesterday, I wrote an article on how to block certain countries from your server using csf. This will block them from accessing your server on any port. You can, however use mod_geoip if you’d like to block them from accessing your web site(s). You might want to do this if the csf approach creates too many iptables rules for your server to handle.

This is an article on how to install and use mod_geoip2 in cpanel.  The short version is that you download it, extract it into the easyapache custom modules directory, then run easyapache to enable it.

Here’s the detailed version.

1. SSH to your server as root.

2. Grab the lastest version from cPanel:

(If that link does not work, view the cPanel custom modules page to get the correct link)

3. Unpack it into cPanel’s easyapache dir:

4. Run easyapache in choose the mod_geoip option

easyapache

5. Save and build your easyapache choices

6. Tell apache about the GeoIP dat file:

Edit /usr/local/apache/conf/includes/pre_main_global.conf and add the following into it:

Restart apache:

7. Start blocking!

Server wide:

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

This will block Russia, China and Thailand access globally to all websites on the server.

Restart apache:

Site by site:

Add the following into an .htaccess file for your website in its DocumentRoot

This will block Russia, China and Thailand access to that website.

If you’d rather only allow certain countries, use something like this:

You can view a full list of countries here: http://dev.maxmind.com/geoip/legacy/codes/iso3166/

More mod_geoip2 information: http://dev.maxmind.com/geoip/legacy/mod_geoip2/

If you need assistance with this, I’d be more than happy to set this up for you.  You can contact me through my Linux support site.

Related posts from Linux Brigade!

  • Globally disable directory listing on WHM/cPanelGlobally disable directory listing on WHM/cPanel One of the things that WHM/cPanel servers have on by default is directory listing. This is something you don’t want – but it’s easy to fix!

    1. Log into WHM
    2. Apache Configuration […]

  • Block account from sending mail WHM/cPanelBlock account from sending mail WHM/cPanel There may come a time when you’d like to block an account / domain on your WHM/cPanel server from being able to send mail. Here’s how you’d get it done!

    We’re going to set up a […]

  • Manually run ClamAV on cPanel and check every userManually run ClamAV on cPanel and check every user If you’re running WHM/cpanel and want to run a scan on every user manually, perhaps when first installing ClamAV, you’ll want to run this command which is endorsed by cPanel […]
  • Lock down your phpMyAdmin access!Lock down your phpMyAdmin access! There are a couple of ways that I lock it down.. I won’t get into specifics because I don’t want you (or you!) trying to find it, but I can’t count the number of times I’ve seen an old […]
  • Patch your WHM/cPanel machine for heartbleedPatch your WHM/cPanel machine for heartbleed You’ve certainly heard about Heartbleed by now. If not, you can read more about this vulnerability at Heartbleed.com. Continue reading this post to find out if you’re vulnerable, and how […]

2 responses to Block Countries using mod_geoip in cPanel

  1. Users from certain countries are up to no good a lot of the time. Blocking them will come in very handy. Thank you for your offer of assistance as well, very kind of you.

  2. yaa thats true thanks

Leave a Reply

*

Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">