Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
wildcard DNS record on OS X in localhost development with dnsmasq

wildcard DNS in localhost development

$ brew install dnsmasq
$ cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf
  • edit /usr/local/etc/dnsmasq.conf
  • 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
  • re-start the computer to enable the resolver


Copy link

anurag commented Jul 16, 2017

I believe you can now do sudo brew services restart dnsmasq instead of using launchctl.

Copy link

jkuri commented Nov 15, 2017

in High Sierra you cannot use local but still works using different domain.

Copy link

jdouglas71 commented Jan 10, 2018

I second jkuri's comment re: High Sierra. I've been fighting this for a couple of weeks. You definitely cannot use local. I had to use test as my domain name and restarting the computer after making changes to the resolver settings is vital.

Copy link

dewey4iv commented May 22, 2018

*.local is caught and handled by Apple but *.*.local does work. So, if you happen to use something like sub.test.local -- then it does work. My guess is it has something to do with how apple handles sharing/local networking.

Copy link

hauleth commented Sep 20, 2018

You should use .localhost as .local is reserved by IANA for local (within LAN fr example) traffic.

Copy link

ManAnRuck commented Aug 29, 2019

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

is not needed anymore

Copy link

airtonix commented Dec 10, 2019

@hauleth the point of even using avahi/bonjour in the first place is so your team mates on the same network can also access this. localhost implies that you wish to not work in a team.

Copy link

hauleth commented Dec 11, 2019

@airtonix yes, what I meant is that you should use .localhost which is reserved for unspecified use for now instead of .local TLD which is reserved for specific use, so you should use:



sudo touch /etc/resolver/localhost

Instead for locally hosted wildcard domains to avoid problems like one pointed by @dewey4iv.

Copy link

TheM1984 commented Dec 20, 2019

This is an old thread but since it has a recent reply, here a my 2 cents:

For *.localhost you do not need dnsmasq!

Should you want a shorter url, use *.test, since that is a reserved tld:

Copy link

hauleth commented Dec 20, 2019

@TheM1984 last time I have checked it didn't worked on my macOS Mojave, maybe in Catalina they changed it. For sure you do not need additional resolver on systemd enabled Linux, but Let's localhost be localhost RFC wasn't accepted and it is still not standardised solution.

Copy link

TheM1984 commented Dec 20, 2019

@hauleth I recently downgraded to Mojave 10.14.6 (18G103) so I can tell you that it works.

The .localhost is already accepted in the old
That said the .test is off course a lot shorter.

Copy link

hauleth commented Dec 20, 2019

It was reserved there as:

The ".localhost" TLD has traditionally been statically defined in host DNS implementations as having an A record pointing to the loop back IP address and is reserved for such use. Any other use would conflict with widely deployed code which assumes this use.

But it do not requires it to be defined as such. I am on Mojave 10.14.6 (18G1012) and this is not available:

$ ping foo.localhost
ping: cannot resolve foo.localhost: Unknown host

If I setup the dnsmasq though it will work.

$ cat /etc/resolver/localhost
$ ping -c1 foo.localhost
PING foo.localhost ( 56 data bytes
64 bytes from icmp_seq=0 ttl=64 time=0.021 ms
--- foo.localhost ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.021/0.021/0.021/0.000 ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment