Skip to content

Instantly share code, notes, and snippets.

@jeop10
Created May 31, 2020 19:11
Show Gist options
  • Save jeop10/756977e5387793e0852df78d1178db94 to your computer and use it in GitHub Desktop.
Save jeop10/756977e5387793e0852df78d1178db94 to your computer and use it in GitHub Desktop.
Use dnsmasq instead of /etc/hosts [macports edition]

Original work of Steven Rombauts

Steve did great job creating this guide but he uses brew, so I just decided to created 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 of 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 that tld.

Activate dnsmasq

sudo port load dnsmasq

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

NOTES:

As Steven stated on 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment