Skip to content

Instantly share code, notes, and snippets.

@bryfox
Forked from nickcernis/dnsmasq.md
Created June 15, 2017 20:10
Show Gist options
  • Save bryfox/d2116e9b7d0ccb8ddbe46c73aaf09fb1 to your computer and use it in GitHub Desktop.
Save bryfox/d2116e9b7d0ccb8ddbe46c73aaf09fb1 to your computer and use it in GitHub Desktop.
dnsmasq

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

To setup your computer to work with *.dev domains, e.g. project.dev, awesome.dev 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 *.dev

echo 'address=/.dev/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

Start now and work 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/dev'

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

To configure dnsmasq, copy the example configuration to /usr/local/etc/dnsmasq.conf and edit to taste.

cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf

To have launchd start dnsmasq at startup: sudo cp -fv /usr/local/opt/dnsmasq/*.plist /Library/LaunchDaemons sudo chown root /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist Then to load dnsmasq now: sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist

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