Schlagworte: subdomains


Easy DNS wildcard setup for local domains using dnsmasq

When doing web development you'll often have domains/hostnames like hahler.local (instead of

Having a separate hostname for a lot of projects will result in some inconvenience though: you have to setup those.
Until recently, I was adding them to /etc/hosts (or the counterpart on Windows), like so: hahler.local whissip.local

This however does not allow wildcards (like *.hahler.local), and having something like *.local would be much easier to maintain (no adding to this file for a new setup/project).

dnsmasq to the rescue!

dnsmasq is a lightweight DNS forwarder and I was using it already to cache DNS queries locally, for faster browsing etc. Since it answers my DNS lookups already, it should be able to make *.local work for me.

I've created a simple file /etc/dnsmasq.d/my-local with just a single line:



And after restarting dnsmasq, *.local gets resolved to

Instead of "local" you can (and should probably) use another domain, like "dev" instead, because using "local" conflicts with Avahi/mdns, but this can get solved as follows:
Avahi/mdns defaults to ".local" as its TLD and therefore you have to adjust the "hosts" line in /etc/nsswitch.conf and put "dns" (which is dnsmasq in this case) before mdns4_minimal (which is avahi in this case), or remove the NOTFOUND=return, so that "dns" would get used even when mdns4_minimal returns NOTFOUND (which it apparently does for requests in its domain (typically ".local") it does not know anything about):


hosts:          files dns mdns4_minimal [NOTFOUND=return] mdns4
By Daniel in Ubuntu, Snippets04/13/10 English (US) Email