Setup Local DNS Server on Macbook

Zhimin Wen
2 min readSep 14, 2019

When testing cloud technologies, frequently we are required to point to some DNS entries or even some wildcard DNS names. We commonly see these in Cloudfoundry, Openshift and so on.

On the server-side, we can set up the DNS server to resolve the requirement. On the client-side, the DevOps’ laptop, a short-term solution is to add those wildcard entries into the /etc/hosts. However, probably a better approach is to set up a local DNS server to address the issue.

Thanks to the Linux flavor of Mac OS, the once looks like daunting work is actually pretty straight-forward. We will use the lightweight dnsmasq, which provides a lightweight local DNS server and a DNS forwarder among many other features. This paper just documents the steps to set up a local DNS server based on the well-spread information and testing.

First, install dnsmasq with brew

brew install dnsmasq

Secondly, update the configuration file to enable the configuration from the specified directory

cp /usr/local/etc/dnsmasq.conf /usr/local/etc/dnsmasq.conf.orig
echo "conf-dir=/usr/local/etc/dnsmasq.d/,*.conf" | tee /usr/local/etc/dnsmasq.conf

Create a “conf” file for the required domain resolving in the defined directory, for an example in the case of OpenShift,

cat /usr/local/etc/dnsmasq.d/ocp.poc.confaddress=/master.poc.ocp.io.local/192.168.20.21…

--

--

Responses (2)