Skip to content

Instantly share code, notes, and snippets.

@yut304
Last active July 25, 2024 20:54
Show Gist options
  • Save yut304/97e7422ecfae37430cb355846816428d to your computer and use it in GitHub Desktop.
Save yut304/97e7422ecfae37430cb355846816428d to your computer and use it in GitHub Desktop.
Install dnsmasq on macos m1

Install dnsmasq with brew:

$ brew install dnsmasq

Setup *.test hosts with:

$ echo 'address=/.test/127.0.0.1' >> /opt/homebrew/etc/dnsmasq.conf

If want to use other device to resolv nameserver ( default only 127.0.0.1 )

$ echo 'listen-address=127.0.0.1,192.168.1.2' >> /opt/homebrew/etc/dnsmasq.conf

note:
- as dnsmasq configuration recommendation is to include 127.0.0.1
- 192.168.1.2 is ip of macos
- Change address above to macos IP 'address=/.test/192.168.1.2'
- For Macos WiFi sharing add more IP 'listen-address=127.0.0.1,192.168.1.2,192.168.2.1' the IP 192.168.2.1 is the gateway IP WiFi sharing

Start service:

$ sudo brew services start dnsmasq

If found Error like this:

$ Error: Failure while executing; /bin/launchctl bootstrap system /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist exited with 37.

Try to restart services:

$ sudo brew services restart dnsmasq

Should see:

$ Successfully started dnsmasq (label: homebrew.mxcl.dnsmasq)

Add resolver:

$ sudo mkdir /etc/resolver

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

Test:

$ ping abcd.ef.test

@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