14 domain-name-system linux debian wget resolve
我在运行 Debian 5.0 的同一个子网上有 2 台机器。它们使用相同的 DNS (/etc/resolv.conf),它们路由到相同的网关 (#route) 并且它们具有相同的 iptables 设置 (#iptables -L)。我可以从它们两个 ping 到 IP 地址和主机名。我可以运行 #host www.google.com 并在两者上获得相同的结果。但问题是,在其中之一上,我无法 wget 或 curl。
所以在机器 1 上一切正常,但在机器 2 上(与机器 1 具有相同的设置)我无法 wget 或 curl。
我得到的错误是:
# wget google.com
--2009-10-20 16:38:36-- http://google.com/
Resolving google.com... failed: Name or service not known.
wget: unable to resolve host address `google.com'
Run Code Online (Sandbox Code Playgroud)
但是在机器 1 上,wget 或 curl 没有问题并返回:
# wget google.com
--2009-10-20 16:43:55-- http://google.com/
Resolving google.com... 74.125.53.100, 74.125.45.100, 74.125.67.100
Connecting to google.com|74.125.53.100|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
...
Saving to: `index.html.3'
Run Code Online (Sandbox Code Playgroud)
等等。
我希望这里有人能指出我正确的方向,以便我可以解决这个问题:)
Aln*_*tak 20
检查您的/etc/nsswitch.conf文件(如果不是,则检查Debian 上的任何等效文件)。
host并nslookup 始终进行 DNS 查找。
然而,其他应用程序将首先在 NSS 中查找其他命名系统(例如/etc/hosts,NIS 等)。如果配置了其他内容但无法正常工作,则可能会阻止应用程序尝试 DNS。
小智 12
谢谢各位的回答!
它是 nsswitch.conf 文件。我从一个教程中设置了 LDAP,该教程告诉我在主机中使用这一行:
hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4
Run Code Online (Sandbox Code Playgroud)
当我把它改成这样:
hosts: files dns mdns4_minimal [NOTFOUND=return] mdns4
Run Code Online (Sandbox Code Playgroud)
它可以毫无问题地工作。所以我猜如果在文件或 mdns4_minimal 中找不到,nsswitch 配置文件使它返回 null,对吗?
谢谢你的帮助!