Skip to content

Instantly share code, notes, and snippets.

@dgoguerra
Last active June 27, 2019 20:42
Show Gist options
  • Save dgoguerra/5cee807df6a1348c890b71e5a16ee9da to your computer and use it in GitHub Desktop.
Save dgoguerra/5cee807df6a1348c890b71e5a16ee9da to your computer and use it in GitHub Desktop.
Setup automatic forwarding of .app and .test domains to Homestead through dnsmasq in OSX

Configure DNSmasq on OSX

Steps extracted from this guide. To see how to set up DNSmasq on Ubuntu, see this guide.

First update brew and install dnsmasq:

brew update
brew install dnsmasq

Copy dnsmasq's example configuration. If brew's installation process outputs different commands to set a default configuration, use them instead.

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

Add the following to dnsmasq's config:

rules="
# resolve all .app and .test domains to Homestead:
address=/app/192.168.10.10
address=/test/192.168.10.10
"

cat "$rules" >> /usr/local/etc/dnsmasq.conf

Have brew configure launchd to start dnsmasq now and restart it at startup.

sudo brew services start dnsmasq

Finally, tell your system to use your local DNS server for .app and .test domains:

sudo mkdir -p /etc/resolver
sudo bash -c "echo nameserver 127.0.0.1 > /etc/resolver/app"
sudo bash -c "echo nameserver 127.0.0.1 > /etc/resolver/test"

❗ Problems with other TLDs

Other domains may fail for different reasons:

  • Chrome forces using HTTPS for .dev domains since Chrome 63.
  • .local may be in use by the Bonjour service (check by running scutil --dns).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment