转自:https://blog.netsh.org/posts/mac-os-x-dnsmasq_1762.netsh.html
使用homebrew 安装dnsmasq
brew install dnsmasq
复制示例配置文件
cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf
设置上游DNS服务器(DNS的IP根据自己需要进行设置)
echo "nameserver 8.8.8.8" > /usr/local/etc/resolv.dnsmasq.conf
将以下配置添加到 resolv.dnsmasq.conf 中(有些已经有了,只需要解开注释)
resolv-file=/usr/local/etc/resolv.dnsmasq.conf
strict-order
no-hosts
cache-size=32768
//192.168.1.103 改为你自己的机器IP,
//这样其他机器可以通过此IP使用你的DNS服务
listen-address=127.0.0.1,192.168.1.103
复制启动服务配置文件并载入
sudo cp -fv /usr/local/opt/dnsmasq/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons/
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
增加DNS解析记录
//testxxx.com为你的DNS服务所能解析的域名
//192.168.1.112 为你的域名指向的IP
echo 'address=/testxxx.com/192.168.1.112' >> /usr/local/etc/dnsmasq.conf
修改配置后,需要重启dnsmasq
sudo launchctl stop homebrew.mxcl.dnsmasq
sudo launchctl start homebrew.mxcl.dnsmasq
sudo killall -HUP mDNSResponder