/etc/resolv.conf
包含一个活着的名称服务器(如ping
命令所报告的那样)host
或者nslookup
能够解决google.com
$ host google.com
google.com has address 74.125.228.3
google.com has address 74.125.228.4
...
$ nslookup google.com
...
Non-authorative answer:
Name: google.com
Address: 74.125.228.0
Name: google.com
Address: 74.125.228.1
..
Run Code Online (Sandbox Code Playgroud)ping
或telnet
无法解决google.com
$ ping google.com
ping: unknown host google.com
$ telnet google.com
google.com: node name or service name not known
Run Code Online (Sandbox Code Playgroud)Ada*_*ion 10
似乎ping
并且telnet
无法解析主机名,因为它们没有查询配置的 DNS 服务器(host
并且nslookup
似乎使用了不同的 DNS 查询代码),解决方案是:
覆盖/etc/nsswitch.conf
有/etc/nsswitch.dns
:
cp /etc/nsswitch.dns /etc/nsswitch.conf
Run Code Online (Sandbox Code Playgroud)