Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a website that needs to block a particular country based on IP address. I am more than aware that IP-based blocking is not a foolproof method for blocking visitors, but it is a necessary step in the right direction.

Since I'm using PHP, what I would do is use a GeoIP database like geoplugin.net. However, I'm curious to know if there's a better way of doing this.

The website is on a shared webserver (I don't have root access) and it is running Apache on centOS. I guess my question is "can an .htaccess file be configured to block by IP using an external source to lookup IP addresses."

share|improve this question
1  
The accepted answer is no longer valid as of 8/9/12 with blockacountry being offline. –  George W Bush Aug 9 '12 at 23:15
add comment

3 Answers 3

up vote 4 down vote accepted

http://www.blockacountry.com

Use cautiously...I'm sure there are plenty of people on here that think you are doing the wrong thing by blocking whole countries.

share|improve this answer
1  
Hmm, not always. Sometimes you're mandated by law to deny access to countries. Like Pandora, for example. –  Mark Henderson Aug 3 '10 at 21:37
    
P.S. With the script that they generate, you should really get rid of the ErrorDocument 403 directive, or replace it with your own, becuase it redirects you to their own website and then launches popups. –  Mark Henderson Aug 3 '10 at 21:38
    
I wrote this with this answer in mind: serverfault.com/questions/163502/… –  Jason Berg Aug 3 '10 at 21:40
    
Yes. This works quite well - and yes, I'm aware that blocking countries this way is not recommended, but it's a requirement and there's not much I can do about it. Good answer, by the way. –  Nathan Osman Aug 4 '10 at 22:20
    
This is a great example of a non future-proof answer. meta.stackexchange.com/questions/8231/… –  George W Bush Aug 9 '12 at 23:14
add comment

There seems to be a geoip module for apache, but the server admin might have reasons against installing it.

share|improve this answer
    
Ya, this would only be useful in a VPS or dedicated server setup. –  Nathan Osman Oct 22 '10 at 0:13
add comment

If you find the additional rules causing CPU overhead and latency issues, TechGuard makes an in-line appliance for IP address blocking of inbound and outbound traffic, including commercial block lists of millions of IP addresses tied to malicious activity in countries allowed by your policy. It does all this without impacting network latency or TCP connections, while automatically updating what is equivalent to 12,000 IP ranges a day.

share|improve this answer
2  
Welcome to Server Fault! Please read our faq in particular May I promote products or websites I am affiliated with here?. Two answers and two recs for the same website is close to the line. –  Iain Sep 7 '12 at 21:05
    
I'm with @Iain: possibly useful answer, but phrasing sounds an awful lot more like marketing copy than the voice of bitter experience. –  pjmorse Sep 23 '12 at 17:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.