7

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:

192.168.56.3 vm site1.vm site2.vm site3.vm site4.vm ...

I want to achieve the same effect as this

192.168.56.3 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?

3 Answers 3

7

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)...

nameserver 127.0.0.1
3
  • 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, 2009 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 127.0.0.1 to the resolv.conf.
    – Apreche
    Jun 1, 2009 at 13:29
  • Yes - resolv.conf is the only way to define DNS servers, I'll add that to the post to be complete.
    – khosrow
    Jun 1, 2009 at 13:49
2

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

address=/.vm/192.168.56.3
0

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

Edit

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: http://linuxgazette.net/154/misc/lg/conspire_dns_vulnerability_details.html

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.

2
  • 4
    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 :).
    – khosrow
    May 31, 2009 at 15:27
  • 3
    hehe "...my favorite feature in the software got fixed in the last revision..." ;-) May 31, 2009 at 15:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .