Install the dnsmasq package:
$ brew install dnsmasqCopy the example configuration file:
$ cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.confOpen up the dnsmasq configuration file with your favorite editor:
$ vim /usr/local/etc/dnsmasq.confRight below the domain-ip mapping, add a configuration to map any .dev domain to our own localhost address 127.0.01.
# Add domains which you want to force to an IP address here.# The example below send any host in double-click.net to a local# web-server.#address=/double-click.net/127.0.0.1address=/dev/127.0.0.1Next, we need to create an additional DNS query resolver. Create a /etc/resolver directory if it’s not already exists and create a dev file within it
sudo mkdir /etc/resolversudo vim /etc/resolver/devNow paste the following configuration within the new /etc/resolver/dev file:
nameserver 127.0.0.1domain devsearch_order 1Finally we need to restart the dnsmasq service like so:
$ sudo brew services start dnsmasqRegister dnsmasq to launch agent:
$ sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plistClear DNS cache:
$ dscacheutil -flushcacheTesting Your Installation
Testing DNS query with dig:
$ dig testing.testing.one.two.three.dev @127.0.0.1
# The result will look like this:;; ANSWER SECTION:testing.testing.one.two.three.dev. 0 IN A 127.0.0.1Testing the additional DNS query resolver with ping:
# Make sure you haven't broken your DNS.ping -c 1 www.google.com# Check that .dev names workping -c 1 this.is.a.test.devping -c 1 iam.the.walrus.dev
# The result should look like this:1 packets transmitted, 1 packets received, 0.0% packet loss