1

I have a Debian Wheezy server with a domain name and a static ip address. The domain name's "A" record set to my server's ip address. Everything works fine. The problem started when another guy set my server's ip address under his own domain name as an "A" record, so when I put his domain name, my server appears. My question is how to prevent this, how to limit the server to one domain name? The dns server is not on the Debian server.

Thank you for your help!

  • I found this: RewriteEngine on RewriteCond %{SERVER_NAME} !^(www\.)?example.com$ RewriteCond %{SERVER_NAME} !^(www\.)?example.com$ RewriteRule ^ - [F] I placed it in the .htaccess file and works like a charm! – debianlike Apr 27 '15 at 23:36
  • If that's your solution please post it as an answer rather than a comment (you can Answer your own questions). For starters you get better formatting options – roaima Apr 28 '15 at 8:59
6

Short answer: you can't.

Anyone can set their DNS to any IP, if I wanted to point my domain name to Google now I could. You don't manage the nameservers somebody uses, so there's no way to prevent it. If someone wants their domain name to point to your server, they can and there's nothing you can do about it...

2

Alright, so as I commented multiple times, I found a solution. You can tell apache2 to serve only your domain's requests and deny everything else. Here is the code:

RewriteEngine on

RewriteCond %{SERVER_NAME} !^(www\.)?example.com$

RewriteRule ^ - [F]

Put this code into your .htaccess file in the /var/www folder. It will drop a 403 error by default if you don't use the defined domain.

1

If this is for a website, you could create a virtual host for the incorrect domain name that puts up a (polite!) message explaining that the website is misconfigured.

Someone's DNS is pointing to my IP. What are my options?

  • I found this: RewriteEngine on RewriteCond %{SERVER_NAME} !^(www\.)?example.com$ RewriteCond %{SERVER_NAME} !^(www\.)?example.com$ RewriteRule ^ - [F] I placed it in the .htaccess file and works like a charm! – debianlike Apr 27 '15 at 23:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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