basforge

Search titles, text and the “If it doesn’t work” cases.

    RU

    DNS: query path from root to IP, record types, NXDOMAIN vs SERVFAIL, and dig

    DNS translates a domain name into an IP address and service records through a tree of servers — from the root . through the top-level domain to the domain's authoritative server. Covers the query path in dig +trace, A/AAAA/CNAME/TXT/PTR records, NXDOMAIN vs SERVFAIL, and Ubuntu's system resolver.

    What you’ll get

    Query an A record from the public resolver 1.1.1.1 to see what comes back in a DNS response:

    dig @1.1.1.1 example.org A +noall +answer +comments
    # ;; Got answer:
    # ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 20121
    # ;; flags: qr rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
    #
    # ;; ANSWER SECTION:
    # example.org.        300    IN    A    203.0.113.10

    A single line in ANSWER packs the name, cache lifetime, class, record type, and address:

    dig @1.1.1.1 example.org A · Pick a segment
    In the header, status: NOERROR means the query succeeded, and the ad flag confirms DNSSEC validation passed.

    Query path: from the local host to the authoritative NS

    Domain names read right to left: api.example.org. is subdomain api inside zone example, which sits under top-level domain .org, which sits under the root zone (.).

    Before sending a single packet over the network, Linux checks /etc/nsswitch.conf (hosts: files dns): it looks in /etc/hosts first and only then asks DNS. When /etc/hosts has no match, the lookup follows this chain:

    app · example.org

    1. Stub resolver127.0.0.53On Ubuntu 24.04, /etc/resolv.conf points to local systemd-resolved. On a cache miss, it forwards the query to the configured upstream resolver (9.9.9.9 or 1.1.1.1).
    2. Root .root-servers.netThe recursive resolver asks one of the 13 root server clusters: “who handles .org?” The root does not know the site’s IP — it returns the NS servers for .org.
    3. .org zone (TLD)NS delegationThe .org server does not store the IP of example.org either — it returns the domain’s authoritative NS servers (ns1.example.org).
    4. Authoritative NSANSWER + TTLns1.example.org hosts the domain zone itself and returns the final A 203.0.113.10 record with its TTL. The recursive resolver caches the answer and sends it back to the client.

    A 203.0.113.10 (cached for TTL)

    Walk that chain yourself from the root, bypassing caches, with +trace:

    dig +trace +nodnssec example.org A
    # .                     518400  IN  NS  a.root-servers.net.
    # ;; Received ... from 127.0.0.53#53
    # org.                  172800  IN  NS  a0.org.afilias-nst.info.
    # ;; Received ... from a.root-servers.net#53
    # example.org.          3600    IN  NS  ns1.example.org.
    # ;; Received ... from a0.org.afilias-nst.info#53
    # example.org.          300     IN  A   203.0.113.10
    # ;; Received ... from ns1.example.org#53

    If a transparent DNS interceptor sits on your path (such as a home router or ISP proxy), dig +trace exposes it immediately: instead of step-by-step delegation, an A record with a short TTL comes back on the first hop.

    DNS record types

    Type Stores Example Purpose
    A IPv4 address 203.0.113.10 Primary mapping from hostname to an IPv4 server
    AAAA IPv6 address 2001:db8::10 Mapping from hostname to an IPv6 server (IPv6 in practice)
    CNAME Alias to another name www.example.org. -> example.org. Points a subdomain to a canonical name; the resolver runs a second lookup
    MX Mail server + priority 10 mail.example.org. Where to deliver email for the domain
    TXT Arbitrary text "v=spf1 -all" Domain ownership verification, SPF, DKIM, DMARC, ACME DNS-01
    NS Authoritative DNS servers ns1.example.org. Delegates a zone to specific DNS servers
    PTR Reverse record (IP to name) 1.1.1.1 -> one.one.one.one. Mail server reputation checks (dig -x 1.1.1.1 +short)
    SOA Zone metadata serial number, timers NS synchronization timers and negative-response cache lifetime

    By default, DNS runs over UDP :53 (one request, one reply, UDP and QUIC). Clients switch to TCP :53 when an answer exceeds the UDP packet size (large TXT/DNSSEC responses set the TC — Truncated — flag) or during zone transfers between DNS servers (AXFR).

    Response codes: NOERROR, NXDOMAIN, and SERVFAIL

    The status field in dig’s header separates a typo, a missing record type, and broken DNS infrastructure:

    1. Client✓ dig example.org A
    2. Resolver 1.1.1.1✓ queried NS
    3. Authoritative NS✓ A 203.0.113.10
    4. Cache✓ stored for 300 s
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR
    ;; ANSWER SECTION:
    example.org.        300    IN    A    203.0.113.10
    What happened

    The record exists. If status: NOERROR appears with ANSWER: 0, the name exists but has no record of the requested type (for example AAAA).

    Check with

    dig @1.1.1.1 example.org A and dig @1.1.1.1 example.org AAAA

    1. Client✓ dig typo.example.org
    2. Resolver 1.1.1.1✓ asked zone NS
    3. Authoritative NS✕ name does not exist
    4. Reply✕ NXDOMAIN + SOA
    ;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1
    ;; AUTHORITY SECTION:
    example.org.        60     IN    SOA   ns1.example.org. dns.example.org. ...
    Cause

    The authoritative server confirmed that typo.example.org does not exist (a typo, deleted record, or wrong zone).

    Check with

    Check the name in your DNS panel and run dig @ns1.example.org typo.example.org

    1. Client✓ dig broken.example
    2. Resolver 1.1.1.1✕ NS silent / bad DNSSEC
    3. Reply✕ status: SERVFAIL
    ;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0
    Cause

    The resolver could not obtain a valid answer: the authoritative NS servers are down, registrar delegation is broken, or DNSSEC validation failed.

    Check with

    dig +trace broken.example and dig @1.1.1.1 +cd broken.example

    How DNS works on Ubuntu (systemd-resolved)

    On Ubuntu 24.04, local applications query the 127.0.0.53 stub managed by systemd-resolved:

    grep -v '^#' /etc/resolv.conf | grep -v '^$'
    # nameserver 127.0.0.53
    # options edns0 trust-ad
    
    resolvectl status
    # Link 2 (eth0)
    #     Current Scopes: DNS
    # Current DNS Server: 9.9.9.9
    #        DNS Servers: 9.9.9.9

    Clear the local DNS cache after an urgent record change with sudo resolvectl flush-caches.

    You changed a site's IP in the DNS panel, and `dig @ns1.example.org example.org +short` already returns the new IP `203.0.113.20`. Yet `dig @1.1.1.1 example.org +short` still returns the old `203.0.113.10`. Why?
    dig @1.1.1.1 example.org A +noall +answer
    # example.org.    1420    IN    A    203.0.113.10
    You changed a site's IP in the DNS panel, and `dig @ns1.example.org example.org +short` already returns the new IP `203.0.113.20`. Yet `dig @1.1.1.1 example.org +short` still returns the old `203.0.113.10`. Why?
    Answer:
    Authoritative NS updated already, while 1.1.1.1 waits out the remaining TTL

    DNS is pull-based with caching: authoritative servers do not push change notifications to resolvers. Recursive resolvers hold the old entry for however many seconds its TTL specified when they fetched it (Lower DNS TTL a day before migrating).

    After moving a zone to a new DNS provider, `dig @1.1.1.1 example.org` returns `SERVFAIL`, while adding `+cd` (disable DNSSEC checks) returns the right IP. What broke?
    dig @1.1.1.1 example.org +noall +comments        # status: SERVFAIL
    dig @1.1.1.1 +cd example.org +noall +answer      # 203.0.113.10
    After moving a zone to a new DNS provider, `dig @1.1.1.1 example.org` returns `SERVFAIL`, while adding `+cd` (disable DNSSEC checks) returns the right IP. What broke?
    Answer:
    Answer succeeds with +cd -> servers are up, the DNSSEC signature chain is broken

    The +cd (Checking Disabled) flag tells the resolver to skip DNSSEC validation. When +cd works and a normal lookup returns SERVFAIL, the registrar's DS record does not match the signing keys on the new NS servers.

    If it doesn’t work

    curl: (6) Could not resolve host or Temporary failure in name resolution, while ping 1.1.1.1 succeeds

    Cause
    Internet routing works, but the system resolver is not answering or /etc/resolv.conf points to an unreachable DNS server.
    Fix
    Compare the system resolver against a public one: dig example.org vs dig @1.1.1.1 example.org. On Ubuntu, check the local DNS status with resolvectl status.

    You moved a site to a new server and updated its A record, yet browsers keep hitting the old IP for half an hour

    Cause
    Intermediate resolvers and OS caches keep serving the old answer until its previous TTL expires (for example, 3600 seconds).
    Fix
    Lower TTL to 60–300 seconds ahead of a migration (Lower DNS TTL a day before migrating). To verify the live record bypassing caches, query the authoritative NS directly: dig @ns1.example.org example.org A.

    dig returns status: NOERROR, but the ANSWER section is empty

    Cause
    The domain exists, but has no record of the requested type — for example, it has AAAA (IPv6) or TXT records, with no A (IPv4) record.
    Fix
    Query other types (dig example.org AAAA, dig example.org CNAME, dig example.org TXT) and inspect your DNS panel.

    Other domains resolve fine, while one specific domain suddenly returns status: SERVFAIL

    Cause
    The domain's authoritative NS servers are unreachable, the domain registration expired, or its DNSSEC signature chain is broken.
    Fix
    Trace the chain with dig +trace example.org and compare answers with and without DNSSEC validation: dig @1.1.1.1 +cd example.org (+cd disables signature checking for diagnosis).

    You edited /etc/resolv.conf manually, and the changes vanished after a reboot or network reload

    Cause
    On Ubuntu 24.04, /etc/resolv.conf is a symlink managed by systemd-resolved pointing to its 127.0.0.53 stub.
    Fix
    Configure DNS servers in the network config (netplan under /etc/netplan/*.yaml or /etc/systemd/resolved.conf.d/) and apply with sudo netplan apply.