Enable wildcard subdomains on localhost on MacOS

Usually you can use http://localhost:3000 to visit your app, but not http://x.localhost:3000. There are ways to configure specific domains to work this way, but that isn't enouh when you need arbitrary subdomains to all point to your same server.

This gist explains how to do it on MacOS. It was written in 2013, so here are the shortened instructions.

First install dnsmasq with brew:

$ brew update
$ brew install dnsmasq

Then initialize the configuration and start it up:

$ echo "address=/localhost/" > /usr/local/etc/dnsmasq.conf
$ brew services start dnsmasq

Not only will this start dnsmasq, but brew will also ensure it starts when your computer restarts.

And that's it! Urls such as http://x.localhost:3000 and http://x.y.localhost:3000 will all point to your server listening on port 3000.


Welcome to DevLog

The open thought platform for developers.

Share your work as you work on it. Easier than a blog, handier than Twitter.

Sign in and write down valuable thoughts that would otherwise be forgotten.