Home > Back-end >  Why Net::DNS::Resolver does not return IP for localhost?
Why Net::DNS::Resolver does not return IP for localhost?

Time:05-16

I am inside docker container. When I run: perl -Ilocal/lib/perl5 -MNet::DNS::Resolver -e 'print Net::DNS::Resolver->new()->query( "999781edb101" )' it returns nothing.
But nslookup does:

# nslookup 999781edb101
Server:     127.0.0.11
Address:    127.0.0.11#53

Non-authoritative answer:
Name:   999781edb101
Address: 172.16.16.7

Why Net::DNS::Resolver does not resolve hostname to IP?
What I should configure to make it work?
Thank you

UPD
If I use debug project I can see that it queries domain from search xxx.com, from /etc/resolv.conf:

# perl -Ilocal/lib/perl5 -MNet::DNS::Resolver -e '$r = Net::DNS::Resolver->new(); $r->debug(1); print $r->query( "999781edb101" )'

;; query( 999781edb101.xxx.com )

;; udp send [127.0.0.11]:53

;; reply from [127.0.0.11] 121 bytes
;; HEADER SECTION
;;  id = 26399
;;  qr = 1  aa = 0  tc = 0  rd = 1  opcode = QUERY
;;  ra = 1  z  = 0  ad = 0  cd = 0  rcode  = NXDOMAIN
;;  qdcount = 1 ancount = 0 nscount = 1 arcount = 0
;;  do = 0

;; QUESTION SECTION (1 record)
;; 999781edb101.xxx.com.    IN  A

;; ANSWER SECTION (0 records)

;; AUTHORITY SECTION (1 record)
xxx.com.    1800    IN  SOA ( xxx.com. zzzzzzzzzzzzzz.
                2021070806  ;serial
                43200       ;refresh
                3600        ;retry
                604800      ;expire
                86400       ;minimum
    )

;; ADDITIONAL SECTION (0 records)


;; errorstring: NXDOMAIN
# cat /etc/resolv.conf 
nameserver 127.0.0.11
search xxx.com
options ndots:0

CodePudding user response:

Judging from the docs and your debug output, you want Net::DNS::Resolver->new(defnames => 0) to pass unqualified names (with no dots) directly to the server, instead of always appending the default domain.

  • Related