All sub-domains to one IP in hosts file

domain-name-systemvirtual-machines

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?

Best Answer

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
Related Topic