Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I check if all of dns resolvers are working under linux console?

share|improve this question

closed as unclear what you're asking by Zelda, Graeme, slm, jasonwryan, vonbrand Mar 18 at 19:16

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Try to add a bit more detail to your question, does something not work ? How many have you configured ? Internal domains ? The two usual utilities are dig and nslookup –  X Tian Mar 18 at 11:53
    
You should try nslookup –  user3184706 Mar 18 at 12:33

1 Answer 1

You can get a list of DNS resolvers from /etc/resolv.conf. Here's a function to do that:

# print the IP addresses of all configured nameservers
resolvers() {
    awk '$1 == "nameserver" { print $2 }' /etc/resolv.conf
}

And usually you'd use dig or host to query a DNS resolver to see if it's working. In this example, I'm testing whether we can resolve NS (nameserver) for google.com. If you're relying on a specific host being resolvable, change google.com in ns to that hostname.

# given a nameserver IP address, exit successfully if it's responding, false otherwise
is_resolver_responding() {
    dig +short google.com in ns @$1 >/dev/null
}

Here's one way to put the functions together. It prints the IP address of each nameserver, followed by OK or BAD. You could easily change this to exit if one of them isn't working, or do whatever you need.

# print whether each configured resolver is responding (<ip> <"OK" or "BAD">)
for resolver in $(resolvers); do
    printf '%s is %s\n' "$resolver" $(is_resolver_responding $resolver && echo OK || echo BAD)
done
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.