4

I'd like to query the DNS records until get the right domain name.

For instance, given www.subdomain.site.com.br, be able to dig from .br until site.com.br.

Which is the most (protocol-speaking) way to achieve that? An recipe using dig/nslookup would be best.

Thanks.

aldrinleal
  • 3,559
  • 26
  • 33
  • I ended up looking for the leftmost SOA record match (i.e., from www.subdomain.site.com.br until it finds the SOA for site.com.br). – aldrinleal Apr 01 '09 at 17:41
  • Calling that "the right domain name" is very... wrong. All domain names are right. What are you really after? When we changed the management of the zone files in ".fr", martin.nom.fr was in the zone nom.fr, now, it is in the zone fr. Did "the right domain" changed? – bortzmeyer Apr 03 '09 at 06:53
  • @bortzmeyer, you're right. However, I want to, say, given a hostname, like www.stackoverflow.com, get just stackoverflow.com, keeping the tld and any n-ary-lds but removing any element which does not belong to the zone in itself – aldrinleal Apr 07 '09 at 10:56

2 Answers2

6
dig +trace www.subdomain.site.com.br

will show you exactly what happens.

David Schmitt
  • 58,259
  • 26
  • 121
  • 165
  • This just times out for me (using a real domain name). Does this depend on your machine's DNS server being configured a certain way? Or does dig do all the work itself? – Clyde Apr 01 '09 at 15:43
  • dig should do all the work itself, there's no special configuration required for the DNS server. – David Z Apr 01 '09 at 15:51
3
dig www.mysite.domain.com @a.root-servers.net

you'll get the next level from there. Just replace the portion after the '@' and keep recursing until you query a server that gives an answer rather than additional information

Clyde
  • 8,017
  • 11
  • 56
  • 87