GrepBoard/Manuals
605 manuals ·

dig +short shows a CNAME but status is NXDOMAIN (dangling CNAME)

·Tested on Ubuntu 24.04 · BIND 9.18.39 · Unbound 1.19.2 · DiG 9.18.39 (Docker) · 2026-10·Test scope ↓·5 steps

dig +short prints only a CNAME? Drop +short and read status. NXDOMAIN: the target is missing, so create it or fix the CNAME. NOERROR: NODATA.

output
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 4777;; flags: qr rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1…;; ANSWER SECTION:dangling.lab.test.	3600	IN	CNAME	gone.lab.test.

A CNAME in the answer (ANSWER: 1) with status: NXDOMAIN means the name you asked for exists, but the name it points to (gone.lab.test.) does not. The response code describes the last name in the chain. Create a record at the target or point the CNAME at a name that exists. With dig +short alone, none of this shows up on screen.

To decode a full dig output line by line (status, flags, SOA), paste it into the dig output explainer.

[1] Run the query again without +short. Both commands below ask the same Unbound resolver for the same name.

console
$ dig @127.0.0.3 dangling.lab.test +shortgone.lab.test.

+short prints only the answer data. With no status line, the single CNAME value looks like a successful lookup. The exit code won't help either: the dig manual lists return code 0 as "DNS response received, including NXDOMAIN status". A script that treats non-empty dig +short output as success counts this case as a success.

A lone CNAME line doesn't always mean a missing target, either. If the target name exists but has no record of the type you asked for (A here), the status is NOERROR and the answer section holds only the CNAME: that is NODATA, RFC 2308 §2.2. Both look identical under +short, so drop +short and read status: as below.

console
$ dig @127.0.0.3 dangling.lab.test ; <<>> DiG 9.18.39-0ubuntu0.24.04.8-Ubuntu <<>> @127.0.0.3 dangling.lab.test…;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 4777;; flags: qr rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1…;; ANSWER SECTION:dangling.lab.test.	3600	IN	CNAME	gone.lab.test. ;; AUTHORITY SECTION:lab.test.		232	IN	SOA	ns1.test. hostmaster.lab.test. 2026102701 7200 900 1209600 300

Compare a working CNAME in the same zone. alias.lab.test points to www, which exists, so the CNAME and the target's A record come back together:

console
$ dig @127.0.0.3 alias.lab.test…;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43216;; flags: qr rd ra ad; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1…alias.lab.test.		3600	IN	CNAME	www.lab.test.www.lab.test.		3532	IN	A	192.0.2.20

The table puts the two A queries from this test side by side. (NODATA, where the target exists but has no A record, is NOERROR with a single CNAME line, so it matches neither column.)

Target existsTarget missing
statusNOERRORNXDOMAIN
ANSWER2 (CNAME + A)1 (CNAME only)
AUTHORITY01 (the zone's SOA)
+shorttwo lines: www.lab.test., 192.0.2.20one line: gone.lab.test.

[2] Ask the authoritative server directly to rule out the resolver cache. An answer with aa is what the zone says right now.

console
$ dig @127.0.0.2 dangling.lab.test…;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 4230;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1;; WARNING: recursion requested but not available…;; ANSWER SECTION:dangling.lab.test.	3600	IN	CNAME	gone.lab.test. ;; AUTHORITY SECTION:lab.test.		300	IN	SOA	ns1.test. hostmaster.lab.test. 2026102701 7200 900 1209600 300

If the authoritative server says the same, fix the zone. If the target lives in another zone (a third-party service hostname, for example), ask that zone's own name server: dig @<that zone's NS> <target name> +norecurse. An NXDOMAIN with an SOA in the same shape means the target is gone.

[3] Check the end of the CNAME value. The zone file above contained:

lab.test.db
$TTL 3600@       IN SOA ns1.test. hostmaster.lab.test. 2026102701 7200 900 1209600 300…alias   IN CNAME wwwdangling IN CNAME gone

A name without a trailing dot is relative, and the zone origin ($ORIGIN) is appended (RFC 1035 §5.1). That is how gone became gone.lab.test.. Drop the trailing dot from a line meant to point at another domain and the value shows up as app.example.net.lab.test.; that name usually does not exist, so you get NXDOMAIN. If you see the zone name glued on, write app.example.net. with the dot. Many DNS provider dashboards add the dot for you, so compare the value exactly as dig prints it.

[4] Fix the target side. Pick one:

  • Create A/AAAA records at the target name (including when you deleted and recreated the service behind it).
  • Point the CNAME at a name that exists.
  • Delete the CNAME if the name is no longer used. Left alone, it stays in this state.

[5] If the resolver keeps answering NXDOMAIN after the fix, read the TTL on the SOA line. A "does not exist" answer stays cached for that many seconds (RFC 2308 §5). In this zone it was 300. Asking for the SOA directly returns 3600, but in negative answers the SOA TTL is cut to the smaller of its TTL and the MINIMUM field.

console
$ dig @127.0.0.2 lab.test SOA +multi…lab.test.		3600 IN	SOA ns1.test. hostmaster.lab.test. (				2026102701 ; serial…				300        ; minimum (5 minutes)				)

On the resolver the value counts down. Two queries for the missing name nope.lab.test, two seconds apart, showed 297 and then 295:

output
lab.test.		297	IN	SOA	ns1.test. hostmaster.lab.test. 2026102701 7200 900 1209600 300lab.test.		295	IN	SOA	ns1.test. hostmaster.lab.test. 2026102701 7200 900 1209600 300

If you can't wait, the cache to clear is the one on the resolver that answered, and only its administrator can do that. The answers above came from Unbound (127.0.0.3). On Unbound, the administrator runs unbound-control flush <name> (removes that name's A, AAAA, CNAME, SOA and other types) or unbound-control flush_negative (removes all NXDOMAIN, NODATA and SERVFAIL answers); control-enable must be on in unbound.conf. For a resolver you don't run (corporate, ISP, public), wait out the TTL above. If this machine also runs its own local cache (systemd-resolved, dnsmasq, nscd), clear that one with Flush the DNS cache on Linux. For a new record that keeps returning NXDOMAIN in general, see New DNS record not resolving. If the status is SERVFAIL instead, go to dig status: SERVFAIL; for REFUSED, dig status: REFUSED.

Sources: RFC 2308 §2.1, §2.2, §5 · RFC 6604 · RFC 1035 §5.1 · BIND 9.18 dig manual · Unbound unbound-control manual (flush, flush_negative)

Check it with the dig output explainer tool ↗ — calculated in your browser.

#dns#dig#cname#nxdomain#dangling-cname#soa