ping ping不正确127.0.0.1

我有一个奇怪的DNS问题。 我在Gentoo Linux上运行双ipv4 / ipv6环境。

ping一些网站导致ping ping 127.0.0.1。 例如

#> ping authserver.mojang.com PING authserver.mojang.com (127.0.0.1) 56(84) bytes of data. 64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=1 ttl=64 time=0.045 ms 64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=2 ttl=64 time=0.043 ms 64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=3 ttl=64 time=0.058 ms --- authserver.mojang.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2000ms rtt min/avg/max/mdev = 0.043/0.048/0.058/0.010 ms 

挖,但正确返回以下内容:

 # dig authserver.mojang.com ; <<>> DiG 9.9.3-P2 <<>> authserver.mojang.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 15800 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 512 ;; QUESTION SECTION: ;authserver.mojang.com. IN A ;; ANSWER SECTION: authserver.mojang.com. 5 IN A 54.235.119.47 ;; Query time: 14 msec ;; SERVER: 2001:4860:4860::8888#53(2001:4860:4860::8888) ;; WHEN: Sat Nov 09 15:34:40 GMT 2013 ;; MSG SIZE rcvd: 66 

我很困惑! 我的networking浏览器返回正确的网站,同一台计算机启动到Windows也正常工作。

我还没有改变/ etc / hosts(我已经改变了我的实际计算机名称在这里发表):127.0.0.1 localhost.localdomain localhost

 # IPv4 and IPv6 localhost aliases 127.0.0.1 my.computer.com my localhost ::1 my.computer.com my localhost 

我的resolv.conf:

 # Generated by dhcpcd from eth0 options inet6 # Google nameserver 2001:4860:4860::8888 nameserver 2001:4860:4860::8844 nameserver 8.8.8.8 nameserver 8.8.4.4 domain my.domain.com 

编辑:我的/etc/nsswitch.conf(未触及):

 # /etc/nsswitch.conf: # $Header: /var/cvsroot/gentoo/src/patchsets/glibc/extra/etc/nsswitch.conf,v 1.1 2006/09/29 23:52:23 vapier Exp $ passwd: compat shadow: compat group: compat # passwd: db files nis # shadow: db files nis # group: db files nis hosts: files dns networks: files dns services: db files protocols: db files rpc: db files ethers: db files netmasks: files netgroup: files bootparams: files automount: files aliases: files 

正如所build议的那样,我在ping上运行strace: strace log

这不是连接到ncsd:

 connect(4, {sa_family=AF_FILE, sun_path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory) 

然后它尝试连接到Google的DNS:

 connect(4, {sa_family=AF_INET6, sin6_port=htons(53), inet_pton(AF_INET6, "2001:4860:4860::8888", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28) = 0 poll([{fd=4, events=POLLOUT}], 1, 0) = 1 ([{fd=4, revents=POLLOUT}]) sendto(4, "\16\273\1\0\0\1\0\0\0\0\0\0\nauthserver\6mojang\3c"..., 39, MSG_NOSIGNAL, NULL, 0) = 39 poll([{fd=4, events=POLLIN}], 1, 5000) = 1 ([{fd=4, revents=POLLIN}]) ioctl(4, FIONREAD, [55]) = 0 recvfrom(4, "\16\273\201\200\0\1\0\1\0\0\0\0\nauthserver\6mojang\3c"..., 1024, 0, {sa_family=AF_INET6, sin6_port=htons(53), inet_pton(AF_INET6, "2001:4860:4860::8888", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [28]) = 55 close(4) = 0 

还是行不通!

如上所示,使用-e读取最后的dns查找如下:

 socket(PF_INET6, SOCK_DGRAM|SOCK_NONBLOCK, IPPROTO_IP) = 4 connect(4, {sa_family=AF_INET6, sin6_port=htons(53), inet_pton(AF_INET6, "2001:4860:4860::8888", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28) = 0 poll([{fd=4, events=POLLOUT}], 1, 0) = 1 ([{fd=4, revents=POLLOUT}]) sendto(4, "M\354\1\0\0\1\0\0\0\0\0\0\nauthserver\6mojang\3c"..., 39, MSG_NOSIGNAL, NULL, 0) = 39 poll([{fd=4, events=POLLIN}], 1, 5000) = 1 ([{fd=4, revents=POLLIN}]) ioctl(4, FIONREAD, [55]) = 0 recvfrom(4, "M\354\201\200\0\1\0\1\0\0\0\0\nauthserver\6mojang\3c"..., 1024, 0, {sa_family=AF_INET6, sin6_port=htons(53), inet_pton(AF_INET6, "2001:4860:4860::8888", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [28]) = 55 | 00000 4d ec 81 80 00 01 00 01 00 00 00 00 0a 61 75 74 M....... .....aut^? | | 00010 68 73 65 72 76 65 72 06 6d 6f 6a 61 6e 67 03 63 hserver. mojang.c^? | | 00020 6f 6d 00 00 01 00 01 c0 0c 00 01 00 01 00 00 00 om...... ........^? | | 00030 05 00 04 17 15 2d ec .....-. ^? | close(4) = 0 

恐怕我对DNS协议不够了解。 完整的痕迹在这里: 完整的strace

你描述的症状(挖掘给出正确的答案,gethostbyname不)意味着系统中的某个地方有一个caching不正确的答案。

运行

 strace ping authserver.mojang.com 

应该可以帮助您了解可以caching数据的位置。 nscd通常是这种情况下的罪魁祸首。 寻找连接呼叫,这是一个DNS服务器。

 connect(4, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("134.79.110.9")}, 28) = 0 

这是一个nscd套接字。

 connect(4, {sa_family=AF_FILE, path="/var/run/nscd/socket"...}, 110) = 0 

你会看到你正在尝试联系的DNS名称发送消息,一个会用本地主机IP地址进行响应。 这是一个成功的dns查找的例子。

 sendto(4, "@\330\1\0\0\1\0\0\0\0\0\0\3www\4slac\10stanford\3e"..., 39, MSG_NOSIGNAL, NULL, 0) = 39 recvfrom(4, "@\330\205\200\0\1\0\2\0\4\0\7\3www\4slac\10stanford\3e"..., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("134.79.110.9")}, [16]) = 309