3

I have lots of clients need to check if the port is opened on remote server. I use nc command to do this job, however it always give out DNS lookup failure, but I can successfully find the DNS record by using the dig or nslookup.

Anyone knows the reason? Thanks!

[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

File info on 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

File info on resolv.conf

[root@client ~]# cat /etc/resolv.conf
nameserver 192.168.1.155
options timeout:1

Trying other commands:

[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.
9
  • What does stat /etc/hosts say? The "no such file..." leads me to believe your local name resolution may have trouble. Commented Jul 22, 2015 at 6:31
  • -rw-r--r-- 1 root root 138 Mar 24 2013 /etc/resolv.conf
    – NeilWang
    Commented Jul 22, 2015 at 6:41
  • Please add that information to your question so everyone can see it easily Commented Jul 23, 2015 at 6:44
  • Can you ping -c1 d1.myserver.com? (I'm more interested in name resolution than the ping itself.) Please update your question with this information. Commented Jul 23, 2015 at 6:47
  • 1
    Can you try removing the options timeout:1 line from resolv.conf and see if it makes a difference? As the issue seems intermittent I can only thing that as some points the name resolution takes longer than 1 second, causing your problems.
    – mjturner
    Commented Jul 23, 2015 at 9:16

1 Answer 1

2

Look at the contents of /etc/nsswitch.conf. You probably have not configured the system to use DNS to resolve host names. nslookup and dig don't bother looking to see if the system is configured to use DNS to resolve hostnames. They use DNS regardless. (Though if you don't specify a server, they will use /etc/resolv.conf to find a DNS server to use.)

You want to see DNS in the hosts line, something like hosts: files dns

3
  • Hi @tim-b The dns has configured in nsswitch.config. [root@client ~]# cat /etc/nsswitch.conf |grep dns hosts: files dns [root@client ~]# ll /etc/nsswitch.conf -rw-r--r-- 1 root root 1658 Apr 1 2008 /etc/nsswitch.conf
    – NeilWang
    Commented Jul 23, 2015 at 4:23
  • @NeilWang please add that information to your question so everyone can see it easily. Commented Jul 23, 2015 at 6:43
  • 1
    I think some glitches happened on this serer, I replace "hosts: files dns" to "hosts: dns" in nsswitch.conf and then flush the DNS cache, it is working property, and then change back to "hosts: files dns", everything goes smoothly again.
    – NeilWang
    Commented Jul 29, 2015 at 8:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .