Skip to content

Instantly share code, notes, and snippets.

@EddiG
Last active March 4, 2019 12:16
Show Gist options
  • Save EddiG/6b7202ba280168fc8835e381747bf2f0 to your computer and use it in GitHub Desktop.
Save EddiG/6b7202ba280168fc8835e381747bf2f0 to your computer and use it in GitHub Desktop.
This is instruction of how to have the arbitrary domain names locally for development purpose (MacOS)

How to setup local DNS server on MacOS

  1. brew install dnsmasq - install dnsmasq, a lightweight DNS server
  2. edit /usr/local/etc/dnsmasq.conf
  • uncomment no-resolv for prevent looking in /etc/resolv.conf
  • add server=8.8.8.8 and server=8.8.4.4 for addining Google's public DNS as a fallback
  • add address address=/my-custom-domain.com/127.0.0.1 so all requests to the my-custom-domain.com and its subdomains will be forwarded to the 127.0.0.1
  1. sudo brew services start dnsmasq - run dnsmasq as a service, so that it will work after restarting OS
  2. change the settings of your current connection to use the local DNS server
  • open Network Preferences
  • select your current internet connection, for example Wi-Fi
  • open Advanced... settings
  • at the DNS tab add the 127.0.0.1 as a first DNS server

Now all your DNS requests will go through the local DNS server dnsmasq and then asked from the Google's public DNS servers 8.8.8.8 or 8.8.4.4

Why not to use the /etc/hosts

The /etc/hosts doesn't allow us to use a wildcard DNS rule. For example I want to forward requests from all subdomains of my-custom-domain.com to the 127.0.0.1. I can't do this, the *.my-custom-domain.com 127.0.0.1 doesn't work.

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