Skip to content

Instantly share code, notes, and snippets.

@Justintime50
Last active July 6, 2022 21:34
Show Gist options
  • Save Justintime50/882403451e3231a6c088743e0e66acb5 to your computer and use it in GitHub Desktop.
Save Justintime50/882403451e3231a6c088743e0e66acb5 to your computer and use it in GitHub Desktop.
Guide on setting up dnsmasq for localhost development

Setup DNSMasq for Localhost Development

Local development requires you to edit your /etc/hosts file constantly to add custom local domains. Maintaining this file across machines and projects can become taxing. Let's use a service like dnsmasq to dynamically set any .localhost domain to point to 127.0.0.1

# Install dnsmasq
brew install dnsmasq
sudo brew services start dnsmasq

# Configure
emacs /usr/local/etc/dnsmasq.conf
# M1 mac: /opt/homebrew/etc/dnsmasq.conf
# Add something like `address=/localhost/127.0.0.1` to the file

# Restart the service
sudo launchctl stop homebrew.mxcl.dnsmasq
sudo launchctl start homebrew.mxcl.dnsmasq

# Setup the resolver
sudo mkdir -p /etc/resolver

sudo tee /etc/resolver/localhost >/dev/null <<EOF
nameserver 127.0.0.1
EOF

Now you can make new DNS names under the .localhost domain at your leisure! Try ping lala.localhost now and you should get valid responses.

Attribution

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