host
通常返回0
现有主机
$ host www.google.com ; echo $?
www.google.com has address 172.217.16.132
www.google.com has IPv6 address 2a00:1450:400a:805::2004
0
如果1
出现错误
$ host does.not.exist ; echo $?
Host does.not.exist not found: 3(NXDOMAIN)
1
我现在有一个不存在的主机,它host
返回 0 而没有任何输出
$ host red3.ethz.ch; echo $?
0
nslookup
生成错误(如预期):
$ nslookup red3.ethz.ch
Server: 129.132.98.12
Address: 129.132.98.12#53
Non-authoritative answer:
*** Can't find red3.ethz.ch: No answer
并且我在输出中看不到任何-d
部分-v
ANSWER
$ host -v -d red3.ethz.ch
Trying "red3.ethz.ch"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 55752
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;red3.ethz.ch. IN A
;; AUTHORITY SECTION:
ethz.ch. 246 IN SOA dummy-ns.ethz.ch. hostmaster.ethz.ch. 2008016728 10800 3600 1814400 600
Received 86 bytes from 129.132.98.12#53 in 30 ms
Trying "red3.ethz.ch"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 31530
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;red3.ethz.ch. IN AAAA
;; AUTHORITY SECTION:
ethz.ch. 246 IN SOA dummy-ns.ethz.ch. hostmaster.ethz.ch. 2008016728 10800 3600 1814400 600
Received 86 bytes from 129.132.98.12#53 in 0 ms
Trying "red3.ethz.ch"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43023
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;red3.ethz.ch. IN MX
;; AUTHORITY SECTION:
ethz.ch. 246 IN SOA dummy-ns.ethz.ch. hostmaster.ethz.ch. 2008016728 10800 3600 1814400 600
Received 86 bytes from 129.132.98.12#53 in 0 ms
为什么host
返回0?
编辑
看看评论,我们似乎可以将范围缩小到 DNS 上的不同配置。
在同一域上 ( ethz.ch
)
$ host doesnotexist.ethz.ch; echo $?
Host doesnotexist.ethz.ch not found: 3(NXDOMAIN)
1
$ host red3.ethz.ch; echo $?
0
$ host www.ethz.ch; echo $?
www.ethz.ch has address 129.132.19.216
www.ethz.ch has IPv6 address 2001:67c:10ec:4380::216
0
看起来没有 IP 的响应被“hosts”认为是可以的,但被“nslookup”认为不行。
答案1
看,根据tshark
,DNS 服务器返回不同的协议消息为您的域名。为does.not.exist
您收到DNS 149 Standard query response 0x0d51 No such name
。为red3.ethz.ch
您收到Standard query response 0xe4db
0 个答案。主机返回不同代码的原因是什么。
至于解析 does.not.exist,DNS 服务器响应是:
DNS 149 Standard query response 0x0d51 No such name
至于red3.ethz.ch
tshark
显示 DNS 服务器在 Answer 部分仅响应 0 条记录:
这是tshark:
DNS 128 Standard query response 0xe4db
这是楼主的回复:
Trying "red3.ethz.ch"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 1542
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0