It always slightly niggled that I couldn’t just stick a *.localhost
entry in /etc/hosts
and have all subdomains of localhost resolve to 127.0.0.1. But setting up a local nameserver, and making sure external domains still got resolved properly, always seemed like too much faff. It turns out though, thanks to dnsmasq, that it’s actually very straightforward. (Instructions are for Ubuntu but dnsmasq runs on most *nix systems.)
-
Install dnsmasq, a DNS forwarder which you can configure to reply to certain queries locally and forward all others on to your external nameservers:
sudo aptitude install dnsmasq
-
Configure it to resolve all localhost domains to 127.0.0.1. By default, dnsmasq will include all files in /etc/dnsmasq.d/
so create a new file here with a sensible name like /etc/dnsmasq.d/localhost.conf
and add the following line: