Skip to content

Instantly share code, notes, and snippets.

@tpoisseau
Created October 19, 2023 09:24
Show Gist options
  • Save tpoisseau/5abfacd8a8643a74bbdf02fd7f5ca886 to your computer and use it in GitHub Desktop.
Save tpoisseau/5abfacd8a8643a74bbdf02fd7f5ca886 to your computer and use it in GitHub Desktop.
dnsmasq wildcard localhost

dnsmasq wildcard localhost

# install dnsmasq
brew install dnsmasq

# edit configuration
echo "address=/.localhost/127.0.0.1" | tee /opt/homebrew/etc/dnsmasq.d/wildcard-localhost.conf

# start service
sudo brew services start dnsmasq

# config computer to resolve with dnsmasq
sudo mkdir /etc/resolver
sudo sh -c 'echo "nameserver 127.0.0.1" > /etc/resolver/localhost'

# refresh resolvers
sudo dscacheutil -flushcache  
sudo killall -HUP mDNSResponder

# check it's working
ping -c 1 foo.localhost
ping -c 1 foo.bar.localhost
dig foo.bar.localhost @localhost +short

If you change dnsmasq conf, you will have to restart service sudo brew services restart dnsmasq


Source

REFERENCES

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