dns.iter.trace

dns.iter

trace(qname, qtype, opts) -> steps, err

Trace iterative DNS resolution from root servers to authoritative answer

Walks the DNS hierarchy starting from root servers, following referrals through TLD and authoritative nameservers until an answer (or terminal error) is reached. Each step in the resolution chain is recorded and returned.

Returns a list of step tables on success:

{
    server = "198.41.0.4",              -- IP address queried
    server_name = "a.root-servers.net.",-- name if known, nil otherwise
    zone = ".",                         -- zone this server is authoritative for
    qname = "example.com.",            -- domain queried
    qtype = "A",                       -- record type queried (string)
    kind = "referral",                 -- classification (see classify())
    info = { ... },                    -- info table from classify()
    response = <decoded msg>,          -- full decoded DNS message
    rtt_ms = 12,                       -- round-trip time in milliseconds
}

The last step in the list contains the terminal result: "answer", "nxdomain", "nodata", or "error". Intermediate steps are typically "referral" or "cname".

Optional opts fields:

When a referral lacks glue records for all NS names, the trace resolves the glueless NS name by launching a recursive sub-trace for its A record. The sub-trace steps are stored on the referral step as info.glue_trace. Nesting depth is bounded by max_glue_depth to prevent infinite loops.

local iter = require("dns.iter")
local steps, err = iter.trace("example.com", "A")
if steps then
    for i, step in ipairs(steps) do
        print(i, step.server, step.kind, step.zone)
    end
end