We want to develop websites or other internet services on our OSX computer. It’s convenient to point wildcard DNS for a whole (imaginary) top level domain to localhost, so we can invent as many domains as we want without having to edit any config files or do any work.
I used Homebrew to install dnsmasq:
% brew install dnsmasq
And then set up the config file:
cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf
To the end of that file I simply added:
Which tells dnsmasq to resolve any hostname ending in .test to 127.0.0.1 (localhost).
Now we need to tell the OS to start dnsmasq automatically. Again, brew will do all the hard work for us:
sudo brew services start dnsmasq
Let’s test to see if it’s working:
dig foo.test @127.0.0.1
; <<>> DiG 9.8.3-P1 <<>> foo.test @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER< ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;foo.test. IN A
;; ANSWER SECTION:
foo.test. 0 IN A 127.0.0.1
We asked the resolver running @127.0.0.1 (dnsmasq) the address for “foo.test” and it returned “127.0.0.1” which is just what we want.
Now we need to get OSX to use that resolver for DNS lookups on the .test TLD. OSX makes this pretty easy:
sudo mkdir -p /etc/resolver
sudo vi /etc/resolver/test
And insert a line in that file just like you might in /etc/resolv.conf:
That’s it. Anything ending with .test will point to localhost. So our next step is to run a server there.
This article previously used the “.dev” top level domain. However, Google has bought and deployed .dev. So .dev is dead and all references have been changed to .test.
You have a typo:
sudo vi /etc/resolved/dev
sudo vi /etc/resolver/dev
Fixed! Thanks for pointing it out.