brew install dnsmasq- installdnsmasq, a lightweight DNS server- edit
/usr/local/etc/dnsmasq.conf
- uncomment
no-resolvfor prevent looking in/etc/resolv.conf - add
server=8.8.8.8andserver=8.8.4.4for addining Google's public DNS as a fallback - add address
address=/my-custom-domain.com/127.0.0.1so all requests to themy-custom-domain.comand its subdomains will be forwarded to the127.0.0.1
sudo brew services start dnsmasq- rundnsmasqas a service, so that it will work after restarting OS- change the settings of your current connection to use the local DNS server
- open
Network Preferences - select your current internet connection, for example
Wi-Fi - open
Advanced...settings - at the DNS tab add the
127.0.0.1as a first DNS server
Now all your DNS requests will go through the local DNS server dnsmasq and then asked from the Google's public DNS servers 8.8.8.8 or 8.8.4.4
The /etc/hosts doesn't allow us to use a wildcard DNS rule. For example I want to forward requests from all subdomains of my-custom-domain.com to the 127.0.0.1. I can't do this, the *.my-custom-domain.com 127.0.0.1 doesn't work.