mac 10.9 无法解析hosts的问题解决

由于系统的dns服务器优先于hosts,导致无法解析部分hosts了,唯一的解决方式是安装dnsmasq域名解析服务

以下是亲自操作的步骤:

brew install -vd --use-gcc dnsmasq

cp /usr/local/Cellar/dnsmasq/2.68/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf // 复制配置文件到指定目录

cp /usr/local/Cellar/dnsmasq/2.68/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons // 配置dns的自启动

launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist // 开机自启动

vim /etc/resolv.dnsmasq.conf: // 默认的resolv.conf会被系统覆盖,所以创建一个新文件写入旧的dns

     nameserver 192.168.1.114
     nameserver 202.106.0.20

vim /usr/local/etc/dnsmasq.conf: resolv-file=/etc/resolv.dnsmasq.conf // 执行dns配置文件

launchctl start homebrew.mxcl.dnsmasq // 进程名称为plist中的label,手动启动,马上看到效果

然后用wget测试一下:

wget www.google.com
--2014-07-24 17:05:58--  http://www.google.com/
Resolving www.google.com... 173.194.121.48, 2404:6800:4005:804::1012
Connecting to www.google.com|173.194.121.48|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://www.google.com.hk/url?sa=p&hl=zh-CN&pref=hkredirect&pval=yes&q=http://www.google.com.hk/&ust=1406192609901954&usg=AFQjCNG6BLYsS9JUG91xjSd2VyWGdvFsTQ [following]
--2014-07-24 17:05:58--  http://www.google.com.hk/url?sa=p&hl=zh-CN&pref=hkredirect&pval=yes&q=http://www.google.com.hk/&ust=1406192609901954&usg=AFQjCNG6BLYsS9JUG91xjSd2VyWGdvFsTQ
Resolving www.google.com.hk... 173.194.72.199, 2404:6800:4008:c01::c7
Connecting to www.google.com.hk|173.194.72.199|:80... ^Z


你可能感兴趣的:(mac 10.9 无法解析hosts的问题解决)