-1

I want to verify in my application if given domain has proper DNS records, without having to wait for a new configuration to propagate. I want to lookup the domain at the primary nameserver to obtain the freshest results, but I've found that simple SOA lookups can fail for subdomains.

> resolveSoa('subdomain.example.com')
Error: ENOTFOUND

Also mode of failure for subdomains with defined CNAME is different (that probably depends on the dns server software):

> resolveSoa('cnamed-subdomain.example.com')
Error: EBADRESP

What is the proper way of fiding the primary nameserver for any (valid) domain?

OhJeez
  • 2,774
  • 2
  • 14
  • 18
  • "I want to lookup the domain at the primary nameserver to obtain the freshest results," Not a good idea. First "primary" nameserver is kind of undefined (the NS set is a set, and the name in the SOA field may not be a reachable nameserver anyway), then if you really want to check if the zone is correctly configured, you need to test all nameservers holding it, not just one. See for example the Zonemaster software and website. – Patrick Mevzek Jun 28 '19 at 20:12

1 Answers1

0

So far the solution I found is:

findPrimaryNameServer(domain):
  do {
    if cname := lookupCName(domain)
       domain := cname

    soa := lookupSoa(domain)
    domain := domain.slice(domain.find(".") + 1)
  } while (!soa)

  return soa.primaryNameServer

This seems to handle both CNAME records and subdomains.

OhJeez
  • 2,774
  • 2
  • 14
  • 18