Skip to content

Stop Using Hosts

This article show the configuration of dnsmasq using macports. So all your .test domains are resolved locally

Inspired by the work of Steven Rombauts

Steve did a great job creating this guide but he uses brew, so I just decided to create the same guide but for macports.

Install dnsmasq with macports

sudo port install dnsmasq

Edit dnsmasq.conf

On /opt/local/etc we should edit the dnsmasq.conf file and add the following line at the very end of the document

#custom conf
conf-dir=/opt/local/etc/dnsmasq.d,*.conf

This line will load all the files that end on .conf extension from the /opt/local/etc/dnsmasq.d directory

Create dnsmasq.d directory

Inside the folder /opt/local/etc/ execute the following command:

mkdir dnsmasq.d

Inside the dnsmasq.d folder create the development.conf file

touch development.conf

Inside the development.conf file add the following line

address=/.test/127.0.0.1

This will make that every domain that ends on .test will resolve to the local IP address 127.0.0.1

Only send .test queries to dnsmasq

To make this we need to create a folder on the /etc/ directory

mkdir resolver

Inside the resolver directory execute the following command:

touch test

Now inside the test file add the following content:

nameserver 127.0.0.1

This will create a resolver for the .test tld.

Activate dnsmasq

And that it’s all, you should be able to resolve any domains that ends on .test to your local machine.

sudo port load dnsmasq

Notes

As Steven stated in the original document:

“Sometimes it can take a little while before the new configuration is applied. We can check that our new resolvers are registered with the scutil --dns command.”

If all goes well you should see something like this:

resolver #9
  domain : test
  nameserver[0] : 127.0.0.1

You can also test to see if everything is still well as Steven says:

ping -c 1 google.com # Make sure you can still access the outside world! 
ping -c 1 mysite.test

mysite.test results should be like this

PING mysite.test (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.040 ms

That is all