Skip to content

Instantly share code, notes, and snippets.

Last active September 6, 2023 10:31
  • Star 76 You must be signed in to star a gist
  • Fork 18 You must be signed in to fork a gist
Star You must be signed in to star a gist
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

slavikme commented May 8, 2022

As @TheM1984 stated, *.localhost does work, but only in browsers like Chrome and Firefox. This is because the browser itself makes the domain resolution to
Outside of browsers it might not work without a DNS server.

Copy link

slavikme commented May 8, 2022

By the way, *.test TLD is the best choice for local apps and services, as this TLD is specifically reserved for such cases, as stated here.

Copy link

hauleth commented May 8, 2022

@slavikme by what metric it would be the "best"? Because .localhost is also reserved for exactly that purpose (it is literally in the same article you have posted).

Copy link

Using *.localhost or *.test is nearly the same, with few small differences:

  1. test is a bit shorter - so it's somewhat a plus.
  2. When using localhost as TLD, and accessing it from other machine on the same network, it causes some conflicts with other local machines.

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