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