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

I've got a VirtualBox VM running with host-only networking. This VM is running Apache, and I want to setup a bunch of name-based virtual hosts in it that can be accessed from the web browser on the host machine.

The thing is, every time I add a new sub-domain for a virtual host, I have to add it to the hosts-file. Right now I have something like this: vm site1.vm site2.vm site3.vm site4.vm ...

I want to achieve the same effect as this vm *.vm

I know that * doesn't work as a wildcard in a hosts file. Is there another way to achieve the desired result short of running an actual DNS server? Should I just suck it up and keep adding to my hosts file manually?

share|improve this question
up vote 7 down vote accepted

There is no wildcard way of doing this - you need to either implement a DNS server, or keep adding entries to your hosts file.

If you do go with installing a DNS server, you don't need to install bind - you can install a simple caching DNS server like totd, dnsmasq, or maradns.

Regardless of what you do, you'll need to make sure that resolv.conf contains the new DNS server, and the following entry must appear in there (in this example, the DNS server is installed on localhost)...

share|improve this answer
This is something interesting. At the present time, this does seem to be the correct answer, so I will mark it as such. However, it doesn't actually solve my problem, perhaps because it is not solve-able. Just something to think about. – Apreche May 31 '09 at 20:20
Another note. I was able to use dnsmasq to make this work. However, on Ubuntu I had to modify the dhcp client configuration of the host machine to prepend to the resolv.conf. – Apreche Jun 1 '09 at 13:29
Yes - resolv.conf is the only way to define DNS servers, I'll add that to the post to be complete. – Xerxes Jun 1 '09 at 13:49

You can use dnsmasq for that, just add in the config file:

share|improve this answer

This is an interesting question. The host file itself doesn't support wildcards, as you mentioned. It would be pretty easy to setup bind on the apache machine and get that to be the auth dns server and point *.vm correctly, but that's a workaround (even if it's the "correct" solution).

There's got to be a way to trick nscd into it, but I haven't figured it out yet. Give me more time, and I'll update this answer


Alright, your best bet, without resorting to the simple task of filling your host file with an immense number of virtual hosts, or the slightly more complex task of configuring bind to auth for that domain, is to use this vulnerability to poison the nscd cache:

At least, that's as far as I'm going to go today. Maybe if I get bored later I'll check the source to nscd and figure out how to directly inject the info.

share|improve this answer
I seriously would not recommend exploiting a vulnerability in order to achieve a goal. I mean, what if you depend on it, and the vulnerability gets... er fixed? ...amongst another 100 things I can see that's just wrong with that. But aside from that - it does look like fun to play with for kicks :). – Xerxes May 31 '09 at 15:27
hehe " favorite feature in the software got fixed in the last revision..." ;-) – Matt Simmons May 31 '09 at 15:37

Your Answer


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.