Skip to content

Instantly share code, notes, and snippets.

@ogrrd
Last active April 30, 2024 12:23
Show Gist options
  • Save ogrrd/28410badb66e326eec90894a6d4e3789 to your computer and use it in GitHub Desktop.
Save ogrrd/28410badb66e326eec90894a6d4e3789 to your computer and use it in GitHub Desktop.
Setup dnsmasq on macOS for developer DNS

Taken from: https://www.stevenrombauts.be/2018/01/use-dnsmasq-instead-of-etc-hosts/ just in case it ever goes away.

brew update
brew install dnsmasq

Auto start with brew

sudo brew services start dnsmasq

Modify /usr/local/etc/dnsmasq.conf and set/add the line:

conf-dir=/usr/local/etc/dnsmasq.d,*.conf

This will instruct dnsmasq to include all files that end with .conf in the /usr/local/etc/dnsmasq.d directory as additional configuration files.

mkdir -p /usr/local/etc/dnsmasq.d
pico /usr/local/etc/dnsmasq.d/development.conf

To get *.test and *.ukwm166 add to /usr/local/etc/dnsmasq.d/development.conf:

address=/test/127.0.0.1 
address=/ukwm166/127.0.0.1
sudo brew services restart dnsmasq
dig foobar.test @127.0.0.1
sudo mkdir /etc/resolver

Create the file /etc/resolver/test for .test domains, and /etc/resolver/ukwm166 for .ukwm166 domains, and add this line:

nameserver 127.0.0.1

Run this command to show your resolvers listed near the end:

scutil --dns
ping -c 1 google.com # Make sure you can still access the outside world! 
ping -c 1 mysite.test
ping -c 1 stuff.things.ukwm166
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment