Skip to content

Instantly share code, notes, and snippets.

@garryyao
Forked from ogrrd/dnsmasq OS X.md
Last active January 31, 2018 16:00
Show Gist options
  • Save garryyao/5a624847386ea9f0d2582d0570a91e85 to your computer and use it in GitHub Desktop.
Save garryyao/5a624847386ea9f0d2582d0570a91e85 to your computer and use it in GitHub Desktop.
Setup dnsmasq on OS X

Make a local DNS server for copilot dev

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

Requirements

Install

brew install dnsmasq

Setup

Create config directory if it doesn't exist

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

Setup *.local

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

You should probably add strict-order to dnsmasq.conf to keep nameserver order of resolv.conf (see here).

Autostart

Work after reboot

sudo cp -v $(brew --prefix dnsmasq)/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons

Get it going right now

sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist

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/copilot.local'

Add local DNS to search order in System Preferences

System Preferences > Network > Wi-Fi (or whatever you use) > Advanced... > DNS > add 127.0.0.1 to top of the list.

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

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