Skip to content

Instantly share code, notes, and snippets.

@alexhwoods
Created May 26, 2023 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexhwoods/3dac8c772516cf30bd079c9f4b6208ab to your computer and use it in GitHub Desktop.
Save alexhwoods/3dac8c772516cf30bd079c9f4b6208ab to your computer and use it in GitHub Desktop.
Route *.localhost traffic to localhost

Route *.localhost traffic to localhost

Inspired and adjusted from this gist.

  1. Install dnsmasq
brew install dnsmasq
  1. Setup
mkdir -pv $(brew --prefix)/etc/
echo 'port=53' >> $(brew --prefix)/etc/dnsmasq.conf

# setup *.localhost
echo 'address=/.localhost/127.0.0.1' >> $(brew --prefix)/etc/dnsmasq.conf
  1. Restart dnsmasq,
sudo brew services start dnsmasq
  1. Add to resolvers
sudo mkdir -v /etc/resolver
sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/localhost'
  1. Verify
scutil --dns

You should see a resolver like this:


resolver #9
  domain   : localhost
  nameserver[0] : 127.0.0.1
  flags    : Request A records, Request AAAA records
  reach    : 0x00030002 (Reachable,Local Address,Directly Reachable Address)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment