4

For my task, I need to block some hostnames, but since some websites may reply with different IP addresses to different DNS queries (for example, Google DNS and any other DNS server), I'd like to resolve same hostname using different DNS servers to get as many possible IP addresses as possible.

Can I solve this task using command line utilities on Ubuntu 16+? Are there any alternative solutions?

In short: I'd like to resolve "example.com" to IP using DNS #A and resolve "example.com" to IP using DNS #B without making any serious changes to my network configuration.

  • 2
    man host, man nslookup or man dig - any of those should help – pawel7318 Dec 21 '17 at 14:15
  • Have you considered how the client subnet DNS option can interfere with your results? – kasperd Dec 21 '17 at 18:58
  • While this is not what you asked about, still it might be useful in the context. There are online services which query different DNS worldwide and give you a list of the answers - e.g. whatsmydns.net (I am not affiliated) – Grzegorz Oledzki Dec 21 '17 at 20:53
  • 1
    If you need to block a hostname, it may be easiest to set up your own DNS resolver and have it return a "NXDOMAIN" error whenever someone tries to look up the hostname in question. I do this to reduce Facebook's tracking abilities. – Mark Dec 21 '17 at 23:49
7

Yes you can with the tools @pawel7318 mentioned.

dig

dig @nameserver hostname

nslookup

nslookup hostname nameserver

host

host hostname nameserver
  • Just use dig and you can forget all the others. – Patrick Mevzek Dec 23 '17 at 3:32
3

I believe

nslookup -q= < record type > < host > < DNS server >

will make the trick for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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