Skip to content

Instantly share code, notes, and snippets.

@terion-name
Forked from ogrrd/dnsmasq OS X.md
Last active June 22, 2022 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terion-name/64d1848eb1d8aa47af4f227f515beec5 to your computer and use it in GitHub Desktop.
Save terion-name/64d1848eb1d8aa47af4f227f515beec5 to your computer and use it in GitHub Desktop.
Setup dnsmasq on OS X

Never touch your local /etc/hosts file in OS X again

To setup your computer to work with *.local domains, e.g. project.local, awesome.local and so on, without having to add to your hosts file each time.

Requirements

Install

brew install dnsmasq

Setup

Create config directory

mkdir -pv $(brew --prefix)/etc/

Setup *.local

echo 'address=/.local/127.0.0.1' >> $(brew --prefix)/etc/dnsmasq.conf

Setup *.cluster.local for local kubernetes (example ip for rancher desktop)

echo 'address=/.cluster.local/192.168.205.1' >> $(brew --prefix)/etc/dnsmasq.conf

Change port for High Sierra (was in original gist, but in os x 12+ this works without port change so can be skipped)

echo 'port=53' >> $(brew --prefix)/etc/dnsmasq.conf

Autostart - now and after reboot

sudo brew services start dnsmasq

Add to resolvers

Create resolver directory

sudo mkdir -v /etc/resolver

Add your nameserver to resolvers

sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/local'

Finished

That's it! You can run scutil --dns to show all of your current resolvers, and you should see that all requests for a domain ending in .local will go to the DNS server at 127.0.0.1

N.B. never use .dev as a TLD for local dev work — chrome will enforce https over it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment