So earlier I posted about my decision to Dockerize my entire development environment. In that post I mentioned that you can either manually edit your /etc/hosts file or install a dns server to point domains to your local web server.

Disclaimer: this nothing to do with Docker, this steps are can be used even if you are running your own instance of web server directly on your machine.

dnsmasq is a simple DNS server that does a lot but it is not as complicated and full featured as stuff like BIND. In this article I will be using dnsmasq to spoof all the DNS requests to “.test” domain to my own local machine. Having my web server running (nginx) and listening for domains set on the virtualhost configurations I will then be able to serve my apps locally.

I’ll be using homebrew on my machine, lets get it installed on our machine:

If you install dnsmasq manually the configuration file would be at /etc/dnsmasq but if you used homebrew to install it then it is located at /usr/local/etc/dnsmasq.conf

In my case I want to redirect all the DNS requests to .test domain to my machine, so we need to add the following to the dnsmasq.conf

Now we start the dnsmasq service using brew services. make sure you run this with sudo.

running dnsmasq via brew services will also make sure dnsmasq service runs on the start up.

Now lets add a specific resolver for .test domain.

that should be it, lets test it out.

Leave a comment

Leave a Reply