我有很多客户需要检查端口是否在远程服务器上打开。我使用nc命令来完成这项工作,但是它总是会导致DNS查找失败,但是我可以使用dig或nslookup成功地找到DNS记录。
有人知道原因吗?谢谢!
[root@client ~]# nc -vzw5 d1.myserver.com 443
d1.myserver.com: forward host lookup failed: Unknown host : No such file or directory
[root@ndc-nz1-1 ~]# nslookup d1.myserver.com
Server: 192.168.1.155
Address: 192.168.1.155#53
Name: d1.myserver.com
Address: 192.168.2.25
[root@client ~]# dig d1.myserver.com
; <<>> DiG 9.2.4 <<>> d1.myserver.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 11270
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;d1.myserver.com. IN A
;; ANSWER SECTION:
d1.myserver.com. 7200 IN A 192.168.2.25
;; Query time: 1 msec
;; SERVER: 192.168.1.155#53(192.168.1.155)
;; WHEN: Tue Jul 21 21:13:21 2015
;; MSG SIZE rcvd: 67关于nsswitch.conf的文件信息
[root@client ~]# cat /etc/nsswitch.conf |grep
hosts: files dns
[root@client ~]# ll /etc/nsswitch.conf
-rw-r--r-- 1 root root 1658 Apr 1 2008 /etc/nsswitch.conf关于resolv.conf的文件信息
[root@client ~]# cat /etc/resolv.conf
nameserver 192.168.1.155
options timeout:1尝试其他命令:
[root@client ~]# ping d1.myserver.com
ping: unknown host d1.myserver.com
[root@client ~]# wget d1.myserver.com
--01:47:57-- http://d1.myserver.com/
=> `index.html'
Resolving d1.myserver.com... 192.168.2.25
Connecting to d1.myserver.com|192.168.2.25|:80... connected.发布于 2015-07-23 03:53:27
查看/etc/nsswitch.conf的内容。您可能还没有将系统配置为使用DNS解析主机名。nslookup和dig不用费心查看系统是否配置为使用DNS解析主机名。不管怎么说他们都使用DNS。(虽然您没有指定服务器,但它们将使用/etc/ find查找要使用的DNS服务器。)
您希望看到主机行中的DNS,类似于hosts: files dns。
https://unix.stackexchange.com/questions/217518
复制相似问题