Setup Wildcard DNS on macOS

Setting up wildcard DNS records in your local development environment doesn’t come out of the box with macOS. But don’t you worry! With Dnsmasq and Homebrew you can have it up and running within minutes.

Getting Started

Dnsmasq is available within Homebrew. First make sure you have the latest version of brew and then install Dnsmasq.

brew update
brew install dnsmasq

The next step is to set up your dnsmasq.conf. To configure Dnsmasq, copy the example configuration to /usr/local/etc/dnsmasq.conf and edit to taste.

cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf

Now let’s edit /usr/local/etc/dnsmasq.conf to include our custom DNS routing rules. Add your rules just below the example line.


I’m using Laravel Homestead in example above. The IP should be connected to your local development environment and the address should be the same as specified in your /etc/hosts file.

Copy the LaunchDaemons to have Dnsmasq launched on system startup.

sudo cp -fv /usr/local/opt/dnsmasq/*.plist /Library/LaunchDaemons

Then load Dnsmasq.

sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist

The next step is to make sure outbound requests check Dnsmasq before any remote DNS servers. Open up System Preferences and visit the network pane. Click on the Advanced button and then select the DNS tab.

Setup Wildcard DNS on macOS

Add the following three IP addresses to make sure the requests goes through Dnsmasq before any thing else. The latter two are Google’s DNS servers. They should work in most cases. If you ever run into any problems, these addresses can easily be changed.

Thats about it. Easy huh! Now you should be able to visit your domain with any subdomain.

Please note that when you edit the dnsmasq.conf configuration file you’ll have to kill the process and reload it. Use the command below.

sudo kill $(ps aux | grep '[d]nsmasq' | awk '{print $2}')

If something went south, please visit the official documentation.

Like this article? Reach out to me and say hi on Twitter! :wave:
All articles written with ♥ by Vincent Klaiber