I have a question.

If I make an A record pointing to an Apache2 server, and make some virtualhosts with subdomains. Can I then access the subdomain without making another record?


You seem to be confusing DNS A records and Apache VirtualHosts. They operate on entirely different levels and aren't really interchangeable.

For Apache, when you designate a <VirtualHost> stanza, you tell apache what to do when it receives requests for any of the ServerNames in that stanza. However, until and unless those names point to your server in DNS, no one from the outside world will ever ask your server for them, so you need both.

(Yes, I know I'm skipping wildcards here, I'm trying to keep it straightforward for someone who's clearly new at DNS and webhosting)

Let's give an example: Say, you have an A record pointing www.foo.com to your server at . And you have the following VirtualHost stanza:

<VirtualHost *:80>
    ServerName www.foo.com
    DocumentRoot /var/www/html
    -- etcetera ---

This tells your apache server that any contacts on port 80 asking for www.foo.com should be handled according to the instructions in that stanza.

Now suppose you add a subdomain:

<VirtualHost *:80>
    ServerName sub.foo.com
    ServerAlias sub2.foo.com

    DocumentRoot /var/www/subdomain/html
    --- etc ---

You've now told your apache server how to respond to requests for sub.foo.com and sub2.foo.com. However, until and unless you add an A record pointing sub.foo.com to no one will know to ask your server for that domain.


No. You need another A record pointing to the same (or a different) ip address or a CNAME record pointing to your existing domain.

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.