This is the second part of setting up a local DNS server for testing and development purposes. The first part was about configuring the DNS resolver so that it will use the locally running DNS server for the .test domain. This part is about setting up dnsmasq as a small local DNS server.

Installing dnsmasq

There are plenty of approaches, I am using Nix for this:

# As root, since I want to run it as a system service
nix-env -iA nixpkgs.dnsmasq

Configuring it

An example configuration could look as follows:

# Only for local use
listen-address=127.0.0.1

# *.lab.test resolves to 192.0.2.1
address=/lab.test/192.0.2.1

# All others in *.test resolve to 192.0.2.2
address=/test/192.0.2.2

# Don't forward queries regarding the test domain
local=/test/

Register it with launchctl

To run it as a system daemon the following steps were necessary:

cd /Library/LaunchDaemons
ln -s /var/root/.nix-profile/Library/LaunchDaemons/uk.org.thekelleys.dnsmasq.plist .
launchctl load uk.org.thekelleys.dnsmasq.plist

Testing

The easiest is to run dig:

dig @localhost example.test

Use ping, curl or your Web Browser to check if the whole setup together with the DNS resolver configuration is working.


Comments

comments powered by Disqus