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?
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 liketotd
,dnsmasq
, ormaradns
.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)...You can use
dnsmasq
for that, just add in the config file: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.