brew install dnsmasq
- installdnsmasq
, a lightweight DNS server- edit
/usr/local/etc/dnsmasq.conf
- uncomment
no-resolv
for prevent looking in/etc/resolv.conf
- add
server=8.8.8.8
andserver=8.8.4.4
for addining Google's public DNS as a fallback - add address
address=/my-custom-domain.com/127.0.0.1
so all requests to themy-custom-domain.com
and its subdomains will be forwarded to the127.0.0.1
sudo brew services start dnsmasq
- rundnsmasq
as 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.1
as 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.