[RndTbl] programatically determine if DNS is down or blocked?

Trevor Cordes trevor at tecnopolis.ca
Wed Apr 6 14:43:11 CDT 2016


I have a program that needs to do DNS lookups, etc.  Things will go Really 
Wonky if there's a problem with DNS (from a client perspective).  Thus, 
I'd like the program to be able to check if DNS isn't working.  In this 
particular setup, the box runs its own named with a view setup for 
resolution/caching.

In particular, I want to test that:
1. named is running and answering calls to its port
2. named is getting real answers from the net (i.e. doing its recursive 
resolution properly; and port 53 to outside NS's isn't being blocked)
3. (rare) root NS's aren't getting DDoS'd / whole world's DNS is down

I want to do this inside a perl or php program, but any language 
pseudo-code will be fine as a template.  I don't want to run a full-blown 
monitoring program separately.

Ideally, I'll have some php like:
function IsDnsOk() {
  check named
  check resolution ok
}

To be used possibly like:
while (!IsDnsOk()) {
  sleep 10;
}
$important_dns_result=gethostbyname($host);


But I want any check to be fairly lightweight.  I don't want to fire off 
useless DNS lookups to root name servers at a potential rate of thousands 
a minute.  Plus, I guess I have to worry about cached results making 
things look ok when they are really not.  Any solution I implement will 
probably be designed to only run these tests once a minute or something, 
which won't catch the instant DNS goes down, but will mitigate the damage 
caused.

I can think of a number of fairly simple tests I can try, but they feel 
kind of kludgy.  Is there a better way?

Ideally, the PHP calls, like gethostbyname would be able to return a 
"down" status, but they decided to lump in to the same return value 
failure due to no dns record and failure due to any other reason.

Thanks!


More information about the Roundtable mailing list