<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Dns · Network Doodles</title><link>https://networkdoodles.com/tags/dns/</link><description>Network automation, from first playbook to agentic operations. Ansible, NetBox, MCP, Python and the occasional doodle.</description><language>en-us</language><managingEditor>David Henderson</managingEditor><lastBuildDate>Mon, 16 Nov 2026 09:00:00 -0500</lastBuildDate><atom:link href="https://networkdoodles.com/tags/dns/index.xml" rel="self" type="application/rss+xml"/><item><title>DNS on the Wire: Queries, Answers and the Lookups You Didn't Type (Wireshark 101, Lesson 5)</title><link>https://networkdoodles.com/lessons/wireshark-101/dns/</link><pubDate>Mon, 16 Nov 2026 09:00:00 -0500</pubDate><dc:creator>David Henderson</dc:creator><guid>https://networkdoodles.com/lessons/wireshark-101/dns/</guid><category>wireshark</category><category>packet-capture</category><category>networking-basics</category><category>dns</category><description>DNS queries and responses in a capture: transaction IDs, flags, NXDOMAIN vs REFUSED, A, AAAA and CNAME records, TTLs, and the search domain's lookups.</description><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>A DNS lookup on the wire is usually two packets: a <strong>query</strong> sent over UDP to port 53, and a <strong>response</strong> that
copies the question back and adds the answers. A 16-bit <strong>transaction ID</strong> ties the two together. Everything
else you need to read a lookup is in a handful of fields: the flags, the reply code, the records and their
TTLs. And the most useful thing a capture shows you about DNS is often what the computer asked for that you
never typed.</p>
<p><a href="/lessons/networking-101/">Networking 101</a> described DNS as the network&rsquo;s phone book. This lesson opens the
phone book&rsquo;s envelope. Every example comes from the
<a href="/labs/wireshark-101/">Wireshark 101 lab</a>, where a laptop looks up names from a small DNS server two routers
away.</p>
<hr>
<h2 id="what-does-a-dns-query-look-like-in-wireshark">What does a DNS query look like in Wireshark?</h2>
<p>Here are three lookups from the lab: <code>dig</code> asking for <code>web.lab</code>, <code>intranet.lab</code> and <code>nas.lab</code>.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">4 1.186582542 192.168.1.175 → 192.168.2.53 DNS 90 Standard query 0x6aec A web.lab OPT
</span></span><span class="line"><span class="cl">5 1.190101167 192.168.2.53 → 192.168.1.175 DNS 94 Standard query response 0x6aec A web.lab A 192.168.2.10 OPT
</span></span><span class="line"><span class="cl">6 1.240939542 192.168.1.175 → 192.168.2.53 DNS 95 Standard query 0xc2f2 A intranet.lab OPT
</span></span><span class="line"><span class="cl">7 1.241206167 192.168.2.53 → 192.168.1.175 DNS 120 Standard query response 0xc2f2 A intranet.lab CNAME web.lab A 192.168.2.10 OPT
</span></span><span class="line"><span class="cl">8 1.302522250 192.168.1.175 → 192.168.2.53 DNS 90 Standard query 0x822d A nas.lab OPT
</span></span><span class="line"><span class="cl">9 1.303036709 192.168.2.53 → 192.168.1.175 DNS 78 Standard query response 0x822d No such name A nas.lab OPT
</span></span></code></pre></div><p>Six packets, three conversations. Each line tells you most of the story before you open anything: the
transaction ID (<code>0x6aec</code>), the record type asked for (<code>A</code>), the name, and in the response, the answer or the
reason there isn&rsquo;t one.</p>
<h3 id="why-dns-uses-udp-and-what-the-transaction-id-is-for">Why DNS uses UDP, and what the transaction ID is for</h3>
<p><strong>UDP</strong> (User Datagram Protocol) sends one packet and forgets about it. There&rsquo;s no handshake and no
connection, which is exactly what you want for a question that fits in one packet: a lookup costs one round
trip, not three. The price is that UDP doesn&rsquo;t match answers to questions for you.</p>
<p>That&rsquo;s the job of the <strong>transaction ID</strong>, a 16-bit number the client picks at random for each query. The server
copies it into the response, and the client accepts only a response whose ID (and ports) match a question it
asked. <a href="https://www.rfc-editor.org/rfc/rfc1035">RFC 1035</a> defines it. The randomness matters: a predictable ID
makes it easier for someone else to slip in a forged answer first.</p>
<p>Wireshark does the matching for you. Open a response and you&rsquo;ll find <code>[Request In: 4]</code> and
<code>[Time: 3.518625 milliseconds]</code>. That time is <code>dns.time</code>, the gap between question and answer, and it&rsquo;s the
quickest way to find a slow DNS server: filter <code>dns.time &gt; 0.1</code> to see every answer that took longer than 100
ms. In the lab, the first answer took 3.5 ms and the next two under 0.6 ms. A capture on the laptop&rsquo;s cable
can&rsquo;t tell you why the first one was slower. It can only tell you that it was, which is where every
investigation starts.</p>
<hr>
<h2 id="what-do-the-dns-flags-mean">What do the DNS flags mean?</h2>
<p>Every DNS message has a 16-bit flags field. Wireshark shows it as one hex number and then breaks it out bit by
bit. Here&rsquo;s the answer for <code>web.lab</code>:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Flags: 0x8580 Standard query response, No error
</span></span><span class="line"><span class="cl">    1... .... .... .... = Response: Message is a response
</span></span><span class="line"><span class="cl">    .000 0... .... .... = Opcode: Standard query (0)
</span></span><span class="line"><span class="cl">    .... .1.. .... .... = Authoritative: Server is an authority for domain
</span></span><span class="line"><span class="cl">    .... ..0. .... .... = Truncated: Message is not truncated
</span></span><span class="line"><span class="cl">    .... ...1 .... .... = Recursion desired: Do query recursively
</span></span><span class="line"><span class="cl">    .... .... 1... .... = Recursion available: Server can do recursive queries
</span></span><span class="line"><span class="cl">    .... .... .... 0000 = Reply code: No error (0)
</span></span></code></pre></div><table>
  <thead>
      <tr>
          <th>Flag</th>
          <th>Set by</th>
          <th>Means</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><strong>QR</strong> (Response)</td>
          <td>both</td>
          <td>0 in a query, 1 in a response. Filter <code>dns.flags.response == 0</code> for questions only</td>
      </tr>
      <tr>
          <td><strong>AA</strong> (Authoritative)</td>
          <td>server</td>
          <td>&ldquo;I own this name. This answer comes from my own data, not from a cache&rdquo;</td>
      </tr>
      <tr>
          <td><strong>TC</strong> (Truncated)</td>
          <td>server</td>
          <td>&ldquo;the full answer didn&rsquo;t fit; ask again over TCP&rdquo;</td>
      </tr>
      <tr>
          <td><strong>RD</strong> (Recursion desired)</td>
          <td>client</td>
          <td>&ldquo;if you don&rsquo;t know, go and find out for me&rdquo;</td>
      </tr>
      <tr>
          <td><strong>RA</strong> (Recursion available)</td>
          <td>server</td>
          <td>&ldquo;I&rsquo;m willing to do that&rdquo;</td>
      </tr>
  </tbody>
</table>
<p>The two recursion flags describe the two kinds of DNS server. A <strong>recursive resolver</strong> (your home router, your
company&rsquo;s DNS servers, a public resolver) takes your question and chases it across the internet for you. An
<strong>authoritative server</strong> holds the records for a zone and only answers for those. The lab&rsquo;s server is a small
<code>dnsmasq</code> that does a bit of both, which is why its answer for <code>web.lab</code> has AA and RA set at once.</p>
<p>Notice that the answer for <code>nas.lab</code> came back with flags <code>0x8183</code>: AA is <strong>off</strong>. The server is saying &ldquo;no
such name&rdquo; without claiming to be the authority for it. Small details like that tell you what kind of server
you&rsquo;re talking to.</p>
<hr>
<h2 id="nxdomain-refused-servfail-what-does-each-reply-code-tell-you">NXDOMAIN, REFUSED, SERVFAIL: what does each reply code tell you?</h2>
<p>The last four bits of the flags are the <strong>reply code</strong> (rcode). It&rsquo;s the server&rsquo;s one-word verdict on your
question, and it&rsquo;s worth more than anything else in the packet when a lookup fails.</p>
<table>
  <thead>
      <tr>
          <th>rcode</th>
          <th>Name</th>
          <th>Wireshark shows</th>
          <th>What it tells you</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>0</td>
          <td>NOERROR</td>
          <td>No error</td>
          <td>the server answered. It may still have no records of the type you asked for</td>
      </tr>
      <tr>
          <td>2</td>
          <td>SERVFAIL</td>
          <td>Server failure</td>
          <td>the server tried and couldn&rsquo;t get an answer: often a broken upstream or a DNSSEC failure</td>
      </tr>
      <tr>
          <td>3</td>
          <td>NXDOMAIN</td>
          <td>No such name</td>
          <td>the name doesn&rsquo;t exist. The server is sure</td>
      </tr>
      <tr>
          <td>5</td>
          <td>REFUSED</td>
          <td>Refused</td>
          <td>the server won&rsquo;t answer this question for you, by policy</td>
      </tr>
  </tbody>
</table>
<p>The difference between NXDOMAIN and REFUSED is the difference between &ldquo;the name is wrong&rdquo; and &ldquo;you asked the
wrong server&rdquo;. NXDOMAIN is about the <strong>name</strong>: check the spelling, the domain, the record. REFUSED is about
the <strong>server</strong>: it isn&rsquo;t configured to answer that question, or to answer you. A capture tells them apart in
one glance, while most applications report both as the same vague &ldquo;host not found&rdquo;.</p>
<p>One code that catches people out is NOERROR with an empty answer section. It means the name exists but has no
record of the type you asked for, such as a name with an IPv4 address and no IPv6 one.
<a href="https://www.rfc-editor.org/rfc/rfc2308">RFC 2308</a> calls this NODATA. It isn&rsquo;t an error, even though nothing
useful came back.</p>
<hr>
<h2 id="a-aaaa-and-cname-records">A, AAAA and CNAME records</h2>
<p>An answer is a list of <strong>resource records</strong>. Each has a name, a type, a class (always <code>IN</code>, for internet), a
<strong>TTL</strong> and a value.</p>
<table>
  <thead>
      <tr>
          <th>Type</th>
          <th>Value</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><strong>A</strong></td>
          <td>an IPv4 address, 4 bytes</td>
      </tr>
      <tr>
          <td><strong>AAAA</strong></td>
          <td>an IPv6 address, 16 bytes</td>
      </tr>
      <tr>
          <td><strong>CNAME</strong></td>
          <td>another name: &ldquo;this name is an alias; the real one is over there&rdquo;</td>
      </tr>
  </tbody>
</table>
<p>The <code>intranet.lab</code> response shows a CNAME at work:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Answers
</span></span><span class="line"><span class="cl">    intranet.lab: type CNAME, class IN, cname web.lab
</span></span><span class="line"><span class="cl">        Time to live: 60 (1 minute)
</span></span><span class="line"><span class="cl">    web.lab: type A, class IN, addr 192.168.2.10
</span></span><span class="line"><span class="cl">        Time to live: 60 (1 minute)
</span></span></code></pre></div><p>Two records in one response. The server didn&rsquo;t just say &ldquo;it&rsquo;s really web.lab, go and ask about that&rdquo;. It
followed the alias itself and put web.lab&rsquo;s address in the same packet, so the laptop got its answer in one
round trip. That&rsquo;s why the response is 120 bytes and web.lab&rsquo;s alone is 94.</p>
<p>CNAMEs are everywhere on the real internet. A company&rsquo;s <code>www</code> name is often a CNAME for a content delivery
network&rsquo;s name, which can be a CNAME for another. A chain of three or four aliases in one response is normal.
When a site resolves to an address you didn&rsquo;t expect, the CNAME chain in the response is the first thing to
read.</p>
<hr>
<h2 id="how-long-can-an-answer-be-cached-ttl">How long can an answer be cached? TTL</h2>
<p>The <strong>TTL</strong> (time to live) on each record is the number of seconds the answer may be kept and reused before
asking again. It has nothing to do with the TTL field in the IP header, which counts router hops. Same name,
different job.</p>
<p>TTLs are a trade-off. A low TTL means a change (a new server address, a failover) reaches everyone quickly,
at the cost of more lookups. A high TTL means fewer lookups and faster page loads, and a change that takes
hours to reach everyone. The lab&rsquo;s server hands out 60 seconds for everything.</p>
<p>Now the part that confuses people with their first DNS capture: <strong>caching happens off the wire</strong>. Windows,
macOS and most Linux desktops keep a local cache, and browsers keep their own on top. If the answer is cached,
the second lookup never leaves the machine, and your capture shows nothing at all. That&rsquo;s not a failure to
capture. It&rsquo;s the cache doing its job. To see a lookup, clear the cache first, or capture on a host that
doesn&rsquo;t have one.</p>
<p>The lab&rsquo;s hosts don&rsquo;t cache. They&rsquo;re small Alpine Linux machines with no caching service, so every lookup goes
on the wire, every time. That&rsquo;s handy for learning, and it&rsquo;s worth remembering that your laptop at work
behaves differently.</p>
<p>Negative answers can be cached too. RFC 2308 has an authoritative server send its zone&rsquo;s SOA record (the
zone&rsquo;s &ldquo;start of authority&rdquo;, with its timers) along with an NXDOMAIN, and that record says how long the &ldquo;no&rdquo;
may be kept. The lab&rsquo;s NXDOMAIN carries no SOA at all: <code>Authority RRs: 0</code>.</p>
<hr>
<h2 id="what-is-the-opt-record-on-the-end-of-every-line">What is the OPT record on the end of every line?</h2>
<p>Every <code>dig</code> query and answer in the lab ends with <code>OPT</code>. That&rsquo;s <strong>EDNS</strong> (Extension Mechanisms for DNS,
<a href="https://www.rfc-editor.org/rfc/rfc6891">RFC 6891</a>). The original DNS limited a UDP answer to 512 bytes. EDNS
adds a pseudo-record, type OPT (41), to the additional section, where the client says how big an answer it can
take, and leaves room for options:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">&lt;Root&gt;: type OPT
</span></span><span class="line"><span class="cl">    UDP payload size: 1232
</span></span><span class="line"><span class="cl">    EDNS0 version: 0
</span></span><span class="line"><span class="cl">    Option: COOKIE
</span></span></code></pre></div><p>dig offers 1,232 bytes and adds a DNS cookie, a small token that helps a server tell a real client from a
spoofed one. None of it is part of the answer. If an answer is still too big, the server sets the TC flag and
the client asks again over TCP.</p>
<hr>
<h2 id="why-did-one-short-name-cause-six-queries">Why did one short name cause six queries?</h2>
<p><code>dig</code> asks exactly what you tell it. Almost nothing else does. Ping, curl, your browser and your mail client
ask the operating system&rsquo;s <strong>resolver</strong>, the library code that does lookups for programs, and the resolver
has its own ideas.</p>
<p>In the lab, the laptop got its resolver settings from DHCP (lesson 4):</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">search lab
</span></span><span class="line"><span class="cl">nameserver 192.168.2.53
</span></span></code></pre></div><p><code>nameserver</code> came from DHCP option 6. <code>search lab</code> is the <strong>search domain</strong>, from option 15: when a name looks
short, try it with <code>.lab</code> on the end. The rule for &ldquo;short&rdquo; is <code>ndots</code>, which defaults to 1 (see the
<a href="https://man7.org/linux/man-pages/man5/resolv.conf.5.html">resolv.conf man page</a>): a name with fewer dots than
that gets the search list tried first.</p>
<p>So here&rsquo;s what the laptop sent when it ran <code>ping nas</code>:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl"> 3 0.219553792 192.168.1.175 → 192.168.2.53 DNS 67 Standard query 0xc991 A nas.lab
</span></span><span class="line"><span class="cl"> 4 0.220102917 192.168.1.175 → 192.168.2.53 DNS 67 Standard query 0xcb5b AAAA nas.lab
</span></span><span class="line"><span class="cl"> 5 0.221055167 192.168.2.53 → 192.168.1.175 DNS 67 Standard query response 0xc991 No such name A nas.lab
</span></span><span class="line"><span class="cl"> 6 0.221235334 192.168.2.53 → 192.168.1.175 DNS 67 Standard query response 0xcb5b No such name AAAA nas.lab
</span></span><span class="line"><span class="cl"> 7 0.221357750 192.168.1.175 → 192.168.2.53 DNS 63 Standard query 0x968f A nas
</span></span><span class="line"><span class="cl"> 8 0.221519209 192.168.1.175 → 192.168.2.53 DNS 63 Standard query 0x97b8 AAAA nas
</span></span><span class="line"><span class="cl"> 9 0.221737250 192.168.2.53 → 192.168.1.175 DNS 63 Standard query response 0x968f Refused A nas
</span></span><span class="line"><span class="cl">10 0.221890417 192.168.2.53 → 192.168.1.175 DNS 63 Standard query response 0x97b8 Refused AAAA nas
</span></span><span class="line"><span class="cl">13 2.729063751 192.168.1.175 → 192.168.2.53 DNS 63 Standard query 0x968f A nas
</span></span><span class="line"><span class="cl">14 2.729521918 192.168.1.175 → 192.168.2.53 DNS 63 Standard query 0x97b8 AAAA nas
</span></span><span class="line"><span class="cl">15 2.730466668 192.168.2.53 → 192.168.1.175 DNS 63 Standard query response 0x968f Refused A nas
</span></span><span class="line"><span class="cl">16 2.730674918 192.168.2.53 → 192.168.1.175 DNS 63 Standard query response 0x97b8 Refused AAAA nas
</span></span></code></pre></div><p>Read it in four steps:</p>
<ol>
<li><strong>The search domain first.</strong> <code>nas</code> has no dots, so the resolver tried <code>nas.lab</code> before <code>nas</code>.</li>
<li><strong>A and AAAA, side by side.</strong> The resolver doesn&rsquo;t know whether the program wants IPv4 or IPv6, so it asks
for both at once, two queries per name, even on a network where nobody uses IPv6.</li>
<li><strong>The bare name.</strong> <code>nas.lab</code> was NXDOMAIN, so it tried plain <code>nas</code>. The lab&rsquo;s server only answers for names
under <code>lab</code> and has nowhere else to ask, so it refused.</li>
<li><strong>A retry.</strong> 2.5 seconds later the resolver sent the same two questions again, with the <strong>same transaction
IDs</strong> (<code>0x968f</code>, <code>0x97b8</code>), got refused again, and gave up.</li>
</ol>
<p>Six queries and two and a half seconds, for one word. Ping just said <code>Try again</code>.</p>
<p>Two more things in that listing are worth noticing. The queries are 67 and 63 bytes, against 90 for dig&rsquo;s,
because the laptop&rsquo;s resolver (Alpine&rsquo;s C library, musl) sends no OPT record at all. Different clients send
different DNS, and that&rsquo;s one reason &ldquo;it works with dig&rdquo; doesn&rsquo;t prove an application&rsquo;s lookup will work. And
the retry reused its transaction IDs, which is how you can tell a retry from a new lookup at a glance.</p>
<hr>
<h2 id="what-you-wont-see-in-a-capture">What you won&rsquo;t see in a capture</h2>
<p>Plain DNS over UDP port 53 is the easy case. Three others show up less clearly, or not at all:</p>
<table>
  <thead>
      <tr>
          <th>Transport</th>
          <th>What the capture shows</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>DNS over TCP, port 53 (<a href="https://www.rfc-editor.org/rfc/rfc7766">RFC 7766</a>)</td>
          <td>a normal TCP connection carrying DNS. Wireshark decodes it. Used after a truncated answer, and for zone transfers</td>
      </tr>
      <tr>
          <td>DNS over TLS, port 853 (<a href="https://www.rfc-editor.org/rfc/rfc7858">RFC 7858</a>)</td>
          <td>a TLS connection to port 853. You can see that DNS happened, not what was asked</td>
      </tr>
      <tr>
          <td>DNS over HTTPS (<a href="https://www.rfc-editor.org/rfc/rfc8484">RFC 8484</a>)</td>
          <td>HTTPS on port 443, like any other web traffic. Nothing marks it as DNS</td>
      </tr>
  </tbody>
</table>
<p>The last one matters for troubleshooting. A browser that uses DNS over HTTPS doesn&rsquo;t ask the resolver in
<code>resolv.conf</code> at all, so a capture filtered on <code>dns</code> stays empty while pages load fine. If you see no DNS and
expected some, ask whether the application is doing its own. <a href="/lessons/wireshark-101/tls-without-decryption/">Lesson 7</a>
covers what an encrypted connection still shows.</p>
<hr>
<h2 id="what-i-see-go-wrong">What I see go wrong</h2>
<p><strong>&ldquo;DNS is slow&rdquo; that&rsquo;s really the search list.</strong> A short or mistyped name that walks the search list, gets
refused or times out, and retries, can cost seconds before the application gives up or falls back. From the
application it looks like a slow network. In a capture, it&rsquo;s a run of queries for names nobody typed. Count
the queries a single lookup causes before blaming the server.</p>
<p><strong>Reading only the first answer.</strong> Wireshark&rsquo;s Info column shows the answers in order, and the first one is
often a CNAME. The address you care about is at the end of the chain.</p>
<p><strong>Treating REFUSED like NXDOMAIN.</strong> They send you to different places. NXDOMAIN: fix the name or the record.
REFUSED: fix which server is asked, or what that server is allowed to answer.</p>
<p><strong>Expecting every lookup on the wire.</strong> A cached answer never leaves the machine. An empty capture right after
a successful lookup usually means the cache worked, not that capturing failed.</p>
<p><strong>Forgetting AAAA.</strong> Hosts ask for both. A broken or slow AAAA answer can delay an application that only ever
uses IPv4, because it waits for both answers before it connects.</p>
<hr>
<h2 id="try-it">Try it</h2>
<p><a href="/labs/wireshark-101/#chapter-5">Chapter 5 of the lab</a> has you capture three lookups, read an address, a TTL,
an alias and a name that doesn&rsquo;t exist, then count what one short name really costs.</p>
<h2 id="whats-next">What&rsquo;s next</h2>
<p>Once the laptop has an address for <code>web.lab</code>, it opens a connection to it.
<a href="/lessons/wireshark-101/tcp/">Lesson 6</a> follows that connection from the first SYN to the last FIN.</p>
]]></content:encoded></item></channel></rss>