Skip to content

Instantly share code, notes, and snippets.

@ogrrd
Last active September 30, 2024 03:25
Show Gist options
  • Save ogrrd/5831371 to your computer and use it in GitHub Desktop.
Save ogrrd/5831371 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 *.test domains, e.g. project.test, awesome.test 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 *.test

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

Change port for High Sierra

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/test'

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 .test will go to the DNS server at 127.0.0.1

N.B. never use .dev as a TLD for local dev work. .test is fine though.

@brablc
Copy link

brablc commented Dec 12, 2023

For my personal project I solved this by making my LAN IP static in DHCP server and adding *.lan.mydomain.com wildcard A record to this IP. The advantage is that I can test on mobile devices easily - livereload working like magic on multiple devices. When on the road I use *.lh.mydomain.com A 127.0.0.1 instead.

@datlife
Copy link

datlife commented Jan 10, 2024

If you are running into issue why dig or nslookup still doesn't work with your domain. It turns out they don't use the official system resolver on Mac OS (ref: https://stackoverflow.com/questions/50914268/os-x-etc-resolver-dev-isnt-working-why-not )

Therefore, to test a domain . Use this

dscacheutil -q host -a name argocd.ml-dev.test

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