I have a single server (single ip) running apache, bind and a mailserver. This serves a single domain (mydomain.com) and I would like to associate www.mydomain.com and mydomain.com with my website, mail.mydomain.com with the mailserver (both incoming and outgoing) and ns.mydomain.com with the DNS.

Everything works fine, but I don't like that pointing a browser at mail.mydomain.com (or at ns.mydomain.com) takes me to my website (i.e. the same as www.mydomain.com). As far as I understand, this cannot be fixed in the DNS, correct? I could create virtual hosts in apache for mail.mydomain.com and either show a blank page or an error message? Which is preferable, and is there a common/recommended error message to show?

Are there any other places where those names overlap: e.g. ns.mydomain.com affecting the mail system?

2 Answers 2


The problem seems to be that your webserver is configured to listen on the (numerical) IP address. (Otherwise you would already get an error on arbitrary subdomains.) So stop it from listening on the IP address. A vhost just and only for domain.net and www.domain.net to serve the webpage should be your way to go.

Now, if browser-requesting the IP address results in the browsers' well known "cannot connect to server" error, it will be there on ns. and mail. too while not affecting regular mail or DNS service.

  • You could also probably set up appropriate .htaccess rules to control access that way - might be useful if there's going to be webmail, etc. running on a separate vhost entry so that mail.domain.net goes to the webmail interface.
    – fencepost
    Jan 25, 2013 at 21:21
  • @KarmaFusebox: I only have "Listen 80", so I guess it is not listening on the (numerical) IP address. I do get errors on arbitrary subdomains, just not on ns. and mail. On the other hand ns. and mail. point to the same ip address via my DNS settings, so would end up at the webserver, no? Jan 25, 2013 at 22:30
  • Listening for anything on port 80 does not even respect different subdomain requests. Because, as you said, all your subdomains resolve to the same IP address, where you are listening generally. So you have to define vhosts here to distinguish the subdomains. I'm sorry that I can't give you any more hints about how to configure the webserver exactly, but generally I still suppose that this is outlining the problem. Jan 26, 2013 at 19:08
  • Thanks. I created a default vhost for ns. and mail. and made it create a 403 error by denying access. Jan 27, 2013 at 22:41

this is called the_default_vhost in apache and it is actually well documented. If there is no hostname then it serves the_default_host that is the first one that your apache has on the list, in your case it happens to be mail.yourdomain.com and so on. I figured it out earlier myself by testing it around and creating a hostname (document root) for every single A record I had. It helped. Then a little later I found out that it was called the_default_host.

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.