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.
sudo port install dnsmasq
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
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
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.
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.
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