Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

testing a DNS server

by jimbus (Friar)
on Feb 24, 2006 at 17:00 UTC ( #532599=perlquestion: print w/ replies, xml ) Need Help??
jimbus has asked for the wisdom of the Perl Monks concerning the following question:

I'm not the networking guru... nor even a programming guru for that matter, but I have to pass as one here... so forgive my ignorance. Pointers are appreciated, too.

I need to write a script to test that a local DNS is working and not be fooled by its cache. I went to CPAN and found a bunch of packages related to DNS and all of them are quite involved, so a little guidence would be appreciated.

This DNS is on a dedicated machine that provides its service to the cell phones on our data core. We occasionally run into a situation where the server thinks it is running just fine, but it's lost it's lookup table... so we don't get any warning or alarms until the CSRs start getting complaints.

The idea is to set up an hourly script to basically, do an nslookup and alarm us if it fails. But the problem is nslookup gives cached information and we lose the length of the cache age as a buffer to customer service. Is there a good way to do this?

Again, please forgive my ignorance and point me at any information you think I should have... just remember, while I'm interested in learning new things, I have to balance that with other time contraints :)


--Jimbus aka Jim Babcock
Wireless Data Engineer and Geek Wannabe
jim-dot-babcock-at-usa-dot-com

Comment on testing a DNS server
Re: testing a DNS server
by tirwhan (Abbot) on Feb 24, 2006 at 17:30 UTC

    A simple example using Net::DNS:

    use strict; use warnings; use Net::DNS; my $server = '127.0.0.1'; # adjust as appropriate my $resolver = Net::DNS::Resolver->new(nameserver => $server); my $reply = $resolver->query("google.com","A"); if ($reply) { for my $answer ($reply->answer) { print $answer->address()."\n"; } }

    You should be able to add tests as you see appropriate.

    To be honest though, if you've got problems with your DNS server I'd suggest exchanging the server software. DNS should be a dead reliable service, and there are servers out there which you can just forget about once they're set up properly (my personal favourite is still djbdns, but there are others as well).


    All dogma is stupid.
Re: testing a DNS server
by atcroft (Monsignor) on Feb 24, 2006 at 17:31 UTC

    One thing to look at would be to see if your current monitoring software can monitor that kind of thing. That having been said, a quick-and-dirty way to check might be to do something along the following lines in a script using Net::DNS:

    1. Maintain a list of a few dozen hosts, including a mix of frequently-visited and not-so-frequently-visited ones.
    2. At intervals, select a subset of this list to check. For each host selected, do the following:
      1. Query against the DNS server in question, for NS and A values.
      2. Query against the NS server for the host in question for the same information
      3. Compare the results. Issue a warning if the mismatch is above some percentage of those checked, or possibly if mismatches occur above some number of consecutive checks.

    Things to remember would include: a) a hostname may resolve to multiple addresses, so you may have to check two answers of multiple results against each other; b) a hostname may just be an alias for another name, which would involve another set of lookups; c) if a DNS update occurs for that host it may take time for it to propagate to your host; and d) things do happen which could cause time-outs in queries, so build your script to be accordingly robust.

    Hope the idea helps, at least.

Re: testing a DNS server
by blue_cowdawg (Monsignor) on Feb 24, 2006 at 18:28 UTC
        I need to write a script to test that a local DNS is working and not be fooled by its cache.

    To add to what everybody else has said, let me just mention nagios as a potential solution if you don't have a monitoring package already. You can set it up to query specific DNS hosts and AFAIK it is not fooled by cache, unless of course you are querying a cacheing DNS server in the first place! :-D

    Where I work we use Netsaint, which is the predecessor to Nagios to keep track of not only the status of our DNS servers but all of our servers across multiple campuses and against a lot of different application types.

    One caveat: I have seen failure modes where a bind server can actually be down but pass a cursory DNS check. Make sure whatever check you come up with does a query against a known and unchanging "A" record. For instance I would advise against querying against Yahoo, or Microsoft, or Hotmail since those can change at any time without warning and may result in false triggers. However if my DNS server has a fixed entry in it that I can rely on I write my check to check that one and make sure the answer I get back is what I expected.


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (14)
As of 2014-10-30 13:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (208 votes), past polls