macOS 上安装DNS服务 - dnsmasq

安装

brew install dnsmasq

配置

配置上游dns服务

新建/usr/local/etc/resolv.dnsmasq.conf, 添加dns 地址列表

nameserver 223.6.6.6
nameserver 223.5.5.5
nameserver 42.120.21.30 
nameserver 180.76.76.76
nameserver 8.8.8.8
nameserver 8.8.4.4

修改 /usr/local/etc/dnsmasq.conf 文件 "resolv-file=" 行

resolv-file=/usr/local/etc/resolv.dnsmasq.conf

配置dnsmasq

strict-order 
no-hosts
listen-address=127.0.0.1,192.168.11.2

address=/xxx.com/192.168.11.2
address=/code.xxx.com/192.168.11.2

listen-address=127.0.0.1,192.168.11.2
192.168.11.2表示本机的ip地址,只有127.0.0.1的时候表示只有本机可以访问

strict-order resolv.dnsmasq.conf内的DNS寻址严格按照从上到下顺序执行,直到成功为止, /usr/local/etc/resolv.dnsmasq.conf 文件dns列表可以按照优先级来 依次写入

no-hosts 表示不使用本机的/etc/hosts文件, 相反 addn-hosts=/etc/hosts

address=/xxx.com/192.168.11.2 被解析域名(xxx.com)=>解析结果(192.168.11.2)
address=/code.xxx.com/192.168.11.2 被解析二级域名(code.xxx.com)=>解析结果(192.168.11.2)

5、brew services restart dnsmasq 重启dnsmasq服务(start启动)

  • 配置开机自启动
sudo cp -fv /usr/local/opt/dnsmasq/*.plist /Library/LaunchDaemons
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
  • 重启
sudo brew services restart dnsmasq 
sudo launchctl stop homebrew.mxcl.dnsmasq
sudo launchctl start homebrew.mxcl.dnsmasq
  • 刷新缓冲DNS
sudo killall -HUP mDNSResponder

mac 折腾系列

你可能感兴趣的:(macOS 上安装DNS服务 - dnsmasq)