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'm using Apache HTTPD Server under Debian Squeeze.

How can I prevent users to access my server by the server hostname(dummy.xxx.com) or ip address(xx.xx.xx.xx)?!

For example: I do not want them to use the hostname or ip address as url. I already thought about using mod_rewrite for this, but is there another alternative?

Thanks!

Update:

Let me explain my thoughts with an example: Normally you can access the apache webserver htdocs by typing the ip address of the server or the server hostname or an registered domain. But I want to allow only access with the domain.

share|improve this question
    
What type of system you are using? –  B14D3 May 29 '12 at 7:14
    
What is it you are trying to achieve? If you don't want people to access to access your site at all simply shut down the web server. But I guess that's not what you're after. Please explain. If you want to allow access to (a part of) a website only to specific address you can use the mod_access module. –  Bram May 29 '12 at 7:24
    
@B14D3 I'am using apache httpd server under Debian Squeeze –  Matthias Reisner May 29 '12 at 8:07
    
@Bram I have registered 2 domains which will be used to access my websites. So there is only the option to use the domains for the user but not the hostname or ip. –  Matthias Reisner May 29 '12 at 8:07
    
This question is substantially similar to How to block Spiders / Scrapers by REMOTE hostname / domain for all Virtual Hosts in Apache?, but I don't think close enough to be closed as a dupe. –  Chris S May 31 '12 at 19:54

3 Answers 3

How can I prevent users to access my server by the hostname or ip address?! Then you want to block completely your site for some hosts. (or am I missing something?)

Best way to block users from some hosts is to use iptables of course if you are using linux or pf on bsd.

For example: (iptables) BLOCK_THIS_IP="x.x.x.x"

iptables -A INPUT -s "$BLOCK_THIS_IP" -j DROP

EDIT:

After update your question (in comment, please correct that and update your question) we know that you dont want do block your site but only restrict access for some users.

You can still achive this by making iptables rule but simpler way will be to restrict access making proper .htaccess file. Here is nice guide how to use .htaccess and restrict access with it.

http://www.javascriptkit.com/howto/htaccess5.shtml

http://perishablepress.com/stupid-htaccess-tricks/#sec7

share|improve this answer
    
This presupposes that the OP is using a system that has iptabes which isn't obvious from the question. –  Iain May 29 '12 at 7:23
    
@lain thats why a asked about that in comment –  B14D3 May 29 '12 at 7:57
    
I have updated my first post! Let me explain my thoughts with an example: Normally you can access the apache webserver htdocs by typing the ip address of the server or the server hostname or an registered domain. But I want to allow only access with the domain. –  Matthias Reisner May 29 '12 at 8:15
    
@Matthias Reisner update your question not add comment. –  B14D3 May 29 '12 at 8:22

You can do this by implementing a firewall and adding rules, for *NIX check B14D3's answer. On windows you can use the Software Configuration Wizard.

share|improve this answer

Set up a specific VirtualHost for the hostname you don't want people to use, and make it the default (so it will also catch requests for the IP-address); then, point the DocumentRoot at an empty-directory, or just return a 404, or similar.

share|improve this answer
    
Hmm, good idea. I wish apache could just solve all of my network security problems. Like send all bogus VNC connections and ssh attacks to some lame webpage.. that'll fool them! –  mralexgray Jun 1 '12 at 9:46

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.