Setup A Local DNS Server For Development

1 minute read

When you develop a web site or when you want to address multiple virtual machines by name on your local machine, you need to find a solution to implement this.

You can either input all your host names into your local /etc/resolv.conf which may not result in a managable scenario after some time, or you can just install Dnsmasq which is a local DNS responder that allows you to manage your own custom domain or extend the dns domain name space of another service.

You can install Dnsmasq from ports or probably homebrew if you’re on a Mac or get it from your local packet manager on your favourite Linux distribution.

After the installation just make sure that you are pointing you operating systems DNS resolution to your local host instance.

To resolve the usual internet domains via dnsmasq as well be sure to include your official DNS server in the configration.

The Dnsmasq configuration file can be found at /opt/local/etc/dnsmasq.conf if you installed from ports. My configuration file is somewhat along these lines.

You probably want to sudo to change this file for editing like for example so sudo vim /opt/local/etc/dnsmasq.conf.

# My local IP address
# Both are googles DNS servers

# here go the IP addresses you want to remap or setup as new

After you have changed the configuration you probably want to flush the DNS cache and reload the service by issuing the following commands:

sudo port unload dnsmasq && \
sudo killall -HUP mDNSResponder && \
sudo port load dnsmasq