- install dnsmasq
$ brew install dnsmasq
...
$ cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf
- edit
/usr/local/etc/dnsmasq.conf
address=/local/127.0.0.1
- start dnsmasq
$ sudo brew services start dnsmasq
- any time we change
dnsmasq.conf
we have to re-start dnsmasq:
$ sudo launchctl stop homebrew.mxcl.dnsmasq
$ sudo launchctl start homebrew.mxcl.dnsmasq
- For OS X to resolve requests from
*.local
to localhost we need to add a resolver:
$ sudo mkdir /etc/resolver
$ sudo touch /etc/resolver/local
- edit
/etc/resolver/local
nameserver 127.0.0.1
- re-start the computer to enable the resolver
=== REFERENCES
- Using Dnsmasq for local development on OS X - Passing Curiosity
- Using Dnsmasq Configure Wildcard DNS Record on Mac | Ri Xu Online
- unix - In my /etc/hosts/ file on Linux/OSX, how do I do a wildcard subdomain? - Server Fault
- hostname - Wildcard in /etc/hosts file - Unix & Linux Stack Exchange
- Mac OS Lion - Wildcard subdomain virtual host - Stack Overflow
- How to put wildcard entry into /etc/hosts? - Stack Overflow
As @TheM1984 stated,
*.localhost
does work, but only in browsers like Chrome and Firefox. This is because the browser itself makes the domain resolution to127.0.0.1
.Outside of browsers it might not work without a DNS server.