在Mac OS X上安裝 dnsmasq 來搭建DNS伺服器
阿新 • • 發佈:2019-02-01
使用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