12

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.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Groosha
  • 285
  • 1
  • 2
  • 9
  • 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. https://www.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

2 Answers2

15

Yes you can with the tools @pawel7318 mentioned.

dig

dig @nameserver hostname

nslookup

nslookup hostname nameserver

host

host hostname nameserver
baselab
  • 621
  • 4
  • 14
3

I believe

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

will make the trick for you.

GAD3R
  • 63,407
  • 31
  • 131
  • 192
vfbsilva
  • 3,657
  • 3
  • 28
  • 42