在Mac上配置DNS服务器很好用的工具是dnsmasq,用过的都知道^^。
步骤如下:
一、安装Brew(本机已有的直接略过这一步,用命令行 brew -v试一下便知)
sudo su curl -L http://github.com/mxcl/homebrew/tarball/master | tar xz --strip 1 -C /usr/local
二、安装dnsmasq
brew install dnsmasq
三、配置conf文件
把/usr/local/opt/dnsmasq/dnsmasq.conf.example文件拷贝至并重命名为/usr/local/etc/dnsmasq.conf。
四、编辑 dnsmasq.conf 内容
resolv-file=/etc/resolv.conf
(配置上行DNS,对应no-resolv)
strict-order (resolv.conf内的DNS寻址严格按照从上到下顺序执行,直到成功为止)
addn-hosts=/etc/hosts (DNS解析hosts时对应的hosts文件,对应no-hosts)
cache-size=1024
listen-address=192.168.x.x,127.0.0.1 (多个ip用逗号分隔,192.168.x.x表示本机的ip地址,只有127.0.0.1的时候表示只有本机可以访问。通过这个设置就可以实现同一局域网内的设备,通过把网络DNS设置为本机ip从而实现局域网范围内的DNS泛解析,注:无效ip有可能导至服务无法启动)
五、运行(开机自动运行,注经测试,如果不执行这一步只执行第六步是没有效果的)
sudo cp -fv /usr/local/opt/dnsmasq/*.plist /Library/LaunchDaemons
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
六、如果修改了配置文件,用以下命令重启
sudo launchctl stop homebrew.mxcl.dnsmasq
sudo launchctl start homebrew.mxcl.dnsmasq
sudo killall -HUP mDNSResponder (清除DNS缓存)
七、 最后,使用终端连接和本机同一局域网的网络,同时设置dns为本机IP地址,即192.168.x.x。就成功了,手机上可以安装iNetTools Ping一下试试。
参考:
http://blog.youkuaiyun.com/rui574081323/article/details/50070467
http://chblog.iteye.com/blog/2030797