1、brew install dnsmasq
2、cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf
3、新建/usr/local/etc/resolv.dnsmasq.conf 內容為DNS列表

4、修改dnsmasq.conf文件
//配置上行DNS,對應no-resolv
resolv-file=/usr/local/etc/resolv.dnsmasq.conf
//resolv.dnsmasq.conf內的DNS尋址嚴格按照從上到下順序執行,直到成功為止
strict-order
//緩沖大小
cache-size=1024
//192.168.x.x表示本機的ip地址,只有127.0.0.1的時候表示只有本機可以訪問
listen-address=127.0.0.1,192.168.x.x
//DNS解析hosts時對應的hosts文件,對應no-hosts
addn-hosts=/etc/hosts
//表示不使用本機的hosts文件
no-hosts
//需要被解析的域名/期望解析結果
address=/example.com/10.11.33.55
5、brew services restart dnsmasq 重啟dnsmasq服務(start啟動)
6、sudo killall -HUP mDNSResponder 刷新緩沖DNS
說明:把本機DNS配置成127.0.0.1即可讓本機也走此DNS服務器。
第五步brew操作可以分解為:
1、開機自運行
sudo cp -fv /usr/local/opt/dnsmasq/*.plist /Library/LaunchDaemons
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
2、命令重啟
sudo launchctl stop homebrew.mxcl.dnsmasq
sudo launchctl start homebrew.mxcl.dnsmasq
