Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hi I want to black my server from any contact with a black list of ips and I would also like to block any domain names if possible, and have it only send http headers back and forth between ip addresses!

I would like to pretty much block any dataleaks to outside except serving the users that have a valid php session! I'm using a lot of code I download just to learn and I dont know where the people who post these have got them from or what kinda backdoors they have put in there so I would like to make sure I'm not gonna get in trouble for using anything I wasn't supposed to because of license and copyright issues!

share|improve this question

migrated from Jul 28 '10 at 1:46

This question came from our site for professional and enthusiast programmers.

To block certain IP addresses (or hostnames) from accessing your website, you could use Apache's Allow and Deny directives, something like what sukru said. But it's often considered more secure to completely block any communication (not just website access) between the selected IPs and your server - after all, if you have reason enough to keep them from accessing your website, you probably don't want them accessing other stuff on your server either. To enforce that kind of access, you'll have to use IPtables. There are many IPtables references online; I happen to have written one which might be of some use to you. The relevant commands would be

iptables -I INPUT --source -j DROP
iptables -I OUTPUT --destination -j DROP

where is the IP address you want to block. Run both these commands for each such address.

share|improve this answer

You need to update httpd.conf (or .htaccess if sufficient options are enabled)

<Location /url>
  Order allow,deny
  Allow from all
  Deny from host1
  Deny from host2
  Deny from *.domain

From documentation: link

Allow,Deny First, all Allow directives are evaluated; at least one must match, or the request is rejected. Next, all Deny directives are evaluated. If any matches, the request is rejected. Last, any requests which do not match an Allow or a Deny directive are denied by default.

share|improve this answer
Um... don't you mean Order deny,allow? Because what you have would enable communication with all hosts. – David Z Jul 27 '10 at 4:29
Nope, the documentation specifically says it's the opposite, there is even a table in the linked page which shows the results when both a deny and allow rule matches. – sukru Jul 27 '10 at 5:53
Huh, I thought I remembered reading otherwise. You're right though. – David Z Jul 28 '10 at 5:51

Your Answer


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