Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Net::DNS failure on RHEL6

by neilwatson (Curate)
on Aug 26, 2013 at 13:11 UTC ( #1050960=perlquestion: print w/ replies, xml ) Need Help??
neilwatson has asked for the wisdom of the Perl Monks concerning the following question:

UPDATE: Fixed. Problem was not Perl. Permissions were incorrect on /etc/nsswitch.conf which prevented Perl from using it.

Grettings,

Some code that uses Net::DNS works on RHEL5 hosts, (Net::DNS 0.59), but fails (query is undef) on RHEL6 (Net::DNS 0.65). What might the problem be?

Code sample:

#!/tool/pandora64/bin/perl5.8.8 use Net::DNS; use Data::Dumper; use strict; use warnings; my $host = $ARGV[0]; my @domains; open(RESOLV, "/etc/resolv.conf") or die("couldn't open /etc/resolv.con +f for reading!"); while(<RESOLV>) { next unless /^search\s+(.*)/; my $str = $1; @domains = split(/\s+/, $str); } close RESOLV; my $res = new Net::DNS::Resolver; $res->debug(1); # Remove all subdomain stuff $host =~ s/\..*//g; # Now figure out the FQDN by choosing from the entries in resolv.conf. my ( $fqhost, $query ); foreach(@domains) { print "query -> $host.$_\n"; $query = $res->query("$host.$_"); if($query) { $fqhost = $host . "." . $_; last; } } unless(defined $fqhost) { print Dumper( \@domains ); print Dumper( \$query ); # If we can't resolve the IP for a given hostname, # we skip that host completely. die "WARNING: Skipping host: $host, query: $query -- no DNS entry! +"; }

RHEL5 output:

$ dnscheck.pl atlrhel5cs query -> atlrhel5cs.example.com ;; query(atlrhel5cs.example.com) ;; setting up an AF_INET() family type UDP socket ;; send_udp(127.0.0.1:53) ;; answer from 127.0.0.1:53 : 52 bytes ;; HEADER SECTION ;; id = 32277 ;; qr = 1 opcode = QUERY aa = 0 tc = 0 rd = 1 ;; ra = 1 ad = 0 cd = 0 rcode = NOERROR ;; qdcount = 1 ancount = 1 nscount = 0 arcount = 0 ;; QUESTION SECTION (1 record) ;; atlrhel5cs.example.com. IN A ;; ANSWER SECTION (1 record) atlrhel5cs.example.com. 9270 IN A 10.180.10.46 ;; AUTHORITY SECTION (0 records) ;; ADDITIONAL SECTION (0 records) $VAR1 = \bless( { 'answer' => [ bless( { 'rdlength' => 4, 'ttl' => 9270, 'name' => 'atlrhel5cs.exampl +e.com', 'address' => '10.180.10.46', 'class' => 'IN', 'type' => 'A', 'rdata' => ' &#65533; .' }, 'Net::DNS::RR::A' ) ], 'buffer' => undef, 'question' => [ bless( { 'qclass' => 'IN', 'qname' => 'atlrhel5cs.exa +mple.com', 'qtype' => 'A' }, 'Net::DNS::Question' ) ], 'answerfrom' => '127.0.0.1', 'answersize' => 52, 'additional' => [], 'authority' => [], 'header' => bless( { 'nscount' => 0, 'cd' => 0, 'qdcount' => 1, 'ancount' => 1, 'rcode' => 'NOERROR', 'tc' => 0, 'opcode' => 'QUERY', 'ad' => 0, 'ra' => 1, 'qr' => 1, 'arcount' => 0, 'id' => 32277, 'aa' => 0, 'rd' => 1 }, 'Net::DNS::Header' ), 'offset' => undef }, 'Net::DNS::Packet' );

RHEL6 output:

~$ dnscheck.pl atlrhel5cs query -> atlrhel5cs.example.com ;; query(atlrhel5cs.example.com) ;; setting up an AF_INET() family type UDP socket query -> atlrhel5cs.to.example2.com ;; query(atlrhel5cs.to.example2.com) ;; setting up an AF_INET() family type UDP socket query -> atlrhel5cs.example2.com ;; query(atlrhel5cs.example2.com) ;; setting up an AF_INET() family type UDP socket $VAR1 = [ 'example.com', 'to.example2.com', 'example2.com' ]; $VAR1 = \undef; Use of uninitialized value in concatenation (.) or string at /home/new +atson/bin/dnscheck.pl line 39. WARNING: Skipping host: atlrhel5cs, query: -- no DNS entry! at /home/ +newatson/bin/dnscheck.pl line 39.
<

Neil Watson
watson-wilson.ca

Comment on Net::DNS failure on RHEL6
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1050960]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2015-07-08 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls