Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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

# Install dnsmasq
brew install dnsmasq
sudo brew services start dnsmasq

# Configure
emacs /usr/local/etc/dnsmasq.conf
# Add something like `address=/localhost/` 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

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.


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