# 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
- https://gist.github.com/eloypnd/5efc3b590e7c738630fdcf0c10b68072
- https://zhimin-wen.medium.com/setup-local-dns-server-on-macbook-82ad22e76f2a
REFERENCES
- Using Dnsmasq for local development on OS X - Passing Curiosity
- Using Dnsmasq Configure Wildcard DNS Record on Mac | Ri Xu Online
- unix - In my /etc/hosts/ file on Linux/OSX, how do I do a wildcard subdomain? - Server Fault
- hostname - Wildcard in /etc/hosts file - Unix & Linux Stack Exchange
- Mac OS Lion - Wildcard subdomain virtual host - Stack Overflow
- How to put wildcard entry into /etc/hosts? - Stack Overflow