我在用CentOS 6.2安装的新机器上遇到一些DNS问题。
我可以使用nslookup,dig或host查找名称。我可以按名称或IP地址ping计算机。但是,当我尝试使用其他工具(例如ssh,wget或yum)时,它们无法解析名称。例如:
# wget http://www.google.com
--2012-03-08 14:48:06-- http://www.google.com/
Resolving www.google.com... failed: Name or service not known.
wget: unable to resolve host address `www.google.com'
# ssh www.google.com
ssh: Could not resolve hostname www.google.com: Name or service not known
# ping -c 1 www.google.com
PING www.l.google.com (74.125.113.106) 56(84) bytes of data.
64 bytes from vw-in-f106.1e100.net (74.125.113.106): icmp_seq=1 ttl=46 time=43.6 ms
--- www.l.google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 59ms
rtt min/avg/max/mdev = 43.665/43.665/43.665/0.000 ms
# host www.google.com
www.google.com is an alias for www.l.google.com.
www.l.google.com has address 74.125.113.99
www.l.google.com has address 74.125.113.103
www.l.google.com has address 74.125.113.104
www.l.google.com has address 74.125.113.105
www.l.google.com has address 74.125.113.106
www.l.google.com has address 74.125.113.147
我的/etc/nsswitch.conf文件是默认文件,包括以下(标准)行:
hosts: files dns
/etc/resolv.conf由DHCP设置:
; generated by /sbin/dhclient-script
nameserver 192.168.1.254
192.168.1.254是可正常使用的DNS服务器(我的DSL调制解调器,可与其他计算机一起使用多年)
任何人都知道为什么ping会起作用,但是ssh / wget会失败吗?
根据NcA的建议,我尝试将/etc/resolv.conf更改为指向8.8.8.8。奇怪的是,这确实使它起作用。显然,我的DSL调制解调器以某种Linux解析系统不喜欢的方式响应DNS请求。看着tcpdump,我看不出有什么区别。当然,两个服务器都发送相同的地址。
这是tcpdump -nn -X
服务器设置为DSL调制解调器上的DNS服务器时的输出。显然,它用正确的地址答复,但是ssh / wget出于某种原因似乎不满意:
15:53:52.133580 IP 192.168.1.254.53 > 192.168.1.2.54836: 33157 7/0/0 CNAME www.l.google.com., A 74.125.115.105, A 74.125.115.106, A 74.125.115.147, A 74.125.115.99, A 74.125.115.103, A 74.125.115.104 (148)
0x0000: 4500 00b0 e33a 0000 ff11 53b1 c0a8 01fe E....:....S.....
0x0010: c0a8 0102 0035 d634 009c 7528 8185 8180 .....5.4..u(....
0x0020: 0001 0007 0000 0000 0377 7777 0667 6f6f .........www.goo
0x0030: 676c 6503 636f 6d00 0001 0001 c00c 0005 gle.com.........
0x0040: 0001 0007 acd0 0008 0377 7777 016c c010 .........www.l..
0x0050: c02c 0001 0001 0000 0001 0004 4a7d 7369 .,..........J}si
0x0060: c02c 0001 0001 0000 0001 0004 4a7d 736a .,..........J}sj
0x0070: c02c 0001 0001 0000 0001 0004 4a7d 7393 .,..........J}s.
0x0080: c02c 0001 0001 0000 0001 0004 4a7d 7363 .,..........J}sc
0x0090: c02c 0001 0001 0000 0001 0004 4a7d 7367 .,..........J}sg
0x00a0: c02c 0001 0001 0000 0001 0004 4a7d 7368 .,..........J}sh
15:53:52.135669 IP 192.168.1.254.53 > 192.168.1.2.54836: 65062- 0/0/0 (32)
0x0000: 4500 003c e33b 0000 ff11 5424 c0a8 01fe E..<.;....T$....
0x0010: c0a8 0102 0035 d634 0028 98f9 fe26 8000 .....5.4.(...&..
0x0020: 0001 0000 0000 0000 0377 7777 0667 6f6f .........www.goo
0x0030: 676c 6503 636f 6d00 001c 0001 gle.com.....
我还没有足够的专家来知道这是否在某种程度上不正确,但是ping似乎可以对付它。
为了进行比较,在查询8.8.8.8时,这是相同的:
15:57:27.990270 IP 8.8.8.8.53 > 192.168.1.2.49028: 59114 7/0/0 CNAME www.l.google.com., A 74.125.113.105, A 74.125.113.103, A 74.125.113.106, A 74.125.113.147, A 74.125.113.104, A 74.125.113.99 (148)
0x0000: 4500 00b0 5530 0000 2f11 6453 0808 0808 E...U0../.dS....
0x0010: c0a8 0102 0035 bf84 009c 39f8 e6ea 8180 .....5....9.....
0x0020: 0001 0007 0000 0000 0377 7777 0667 6f6f .........www.goo
0x0030: 676c 6503 636f 6d00 0001 0001 c00c 0005 gle.com.........
0x0040: 0001 0001 516a 0008 0377 7777 016c c010 ....Qj...www.l..
0x0050: c02c 0001 0001 0000 0116 0004 4a7d 7169 .,..........J}qi
0x0060: c02c 0001 0001 0000 0116 0004 4a7d 7167 .,..........J}qg
0x0070: c02c 0001 0001 0000 0116 0004 4a7d 716a .,..........J}qj
0x0080: c02c 0001 0001 0000 0116 0004 4a7d 7193 .,..........J}q.
0x0090: c02c 0001 0001 0000 0116 0004 4a7d 7168 .,..........J}qh
0x00a0: c02c 0001 0001 0000 0116 0004 4a7d 7163 .,..........J}qc
15:57:28.018909 IP 8.8.8.8.53 > 192.168.1.2.49028: 31984 1/1/0 CNAME www.l.google.com. (102)
0x0000: 4500 0082 7b1b 0000 2f11 3e96 0808 0808 E...{.../.>.....
0x0010: c0a8 0102 0035 bf84 006e c67e 7cf0 8180 .....5...n.~|...
0x0020: 0001 0001 0001 0000 0377 7777 0667 6f6f .........www.goo
0x0030: 676c 6503 636f 6d00 001c 0001 c00c 0005 gle.com.........
0x0040: 0001 0001 517f 0008 0377 7777 016c c010 ....Q....www.l..
0x0050: c030 0006 0001 0000 0258 0026 036e 7334 .0.......X.&.ns4
0x0060: c010 0964 6e73 2d61 646d 696e c010 0016 ...dns-admin....
0x0070: 91f3 0000 0384 0000 0384 0000 0708 0000 ................
0x0080: 003c .<
我仍然不知道为什么服务器的回复足以进行ping操作,但不足以用于ssh / wget。
如果有人有想法,我很乐意听到。不过,到目前为止,我可以引用外部DNS服务器,也可以在新框中设置自己的服务器。这是一种变通方法,似乎应该没有必要,但可以让我继续。