<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>2 Minute Serverless — DNS</title>
<link>https://www.serverless.fyi/</link>
<description>DNS posts from 2 Minute Serverless.</description>
<language>en</language>
<copyright>© Serverless Ventures LLC</copyright>
<generator>serverless-fyi 1.0.0</generator>
<lastBuildDate>Wed, 29 Oct 2025 21:57:35 GMT</lastBuildDate>
<atom:link href="https://www.serverless.fyi/t/dns/rss.xml" rel="self" type="application/rss+xml"/>
<image><url>https://www.serverless.fyi/brand/icon-192.png</url><title>2 Minute Serverless — DNS</title><link>https://www.serverless.fyi/</link></image>
<item>
<title>Understanding the DNS Header</title>
<link>https://www.serverless.fyi/p/understanding-the-dns-header/</link>
<guid isPermaLink="true">https://www.serverless.fyi/p/understanding-the-dns-header/</guid>
<pubDate>Wed, 29 Oct 2025 21:57:35 GMT</pubDate>
<dc:creator>Mohinish Shaikh</dc:creator>
<description>The Tiny Packet That Runs the Internet. The Domain Name System (DNS) is often called the “phonebook of the internet,” translating human-readable domain names…</description>
<category>dns</category>
<content:encoded><![CDATA[<p>The <strong>Domain Name System (DNS)</strong> is often called the “phonebook of the internet,” translating human-readable domain names like <a href="https://serverless.fyi">serverless.fyi</a> into IP addresses that computers can understand. While most users interact with DNS through their browsers, the real magic happens in the <strong>DNS header</strong>, a compact 12-byte structure that drives every query and response.</p>
<hr>
<h2>Why the DNS Header Matters</h2>
<p>Every time you open a website, your device sends a DNS query to a server. The <strong>DNS header</strong> contains the information needed to route the query, track the response, and apply special rules for caching, recursion, or security. Understanding it can be a game-changer for network engineers, penetration testers, and developers working with networking protocols.</p>
<hr>
<h2>Anatomy of a DNS Header</h2>
<p>A DNS header is exactly <strong>12 bytes</strong>, divided into six key fields:</p>
<pre><code class="language-text">+---------------------+---------------------+
|        ID (16)      |   Flags (16)        |
+---------------------+---------------------+
|      QDCOUNT (16)   |      ANCOUNT (16)   |
+---------------------+---------------------+
|      NSCOUNT (16)   |      ARCOUNT (16)   |
+---------------------+---------------------+
</code></pre>
<p><strong>Breakdown:</strong></p>
<ul>
<li><strong>ID (16 bits):</strong> Unique identifier for the query, used to match requests and responses.</li>
<li><strong>Flags (16 bits):</strong> Bit-level flags controlling query/response type, recursion, and error codes.</li>
<li><strong>QDCOUNT (16 bits):</strong> Number of questions in the query section.</li>
<li><strong>ANCOUNT (16 bits):</strong> Number of answer records.</li>
<li><strong>NSCOUNT (16 bits):</strong> Number of authority records.</li>
<li><strong>ARCOUNT (16 bits):</strong> Number of additional records.</li>
</ul>
<hr>
<h2>A Closer Look at Flags</h2>
<p>The <strong>Flags</strong> field is packed with bit-level details that affect DNS behavior:</p>
<pre><code class="language-text">QR | Opcode | AA | TC | RD | RA | Z | RCODE
</code></pre>
<ul>
<li><strong>QR (1 bit):</strong> Query (0) or Response (1)</li>
<li><strong>Opcode (4 bits):</strong> Type of query (standard, inverse, status)</li>
<li><strong>AA (1 bit):</strong> Authoritative Answer</li>
<li><strong>TC (1 bit):</strong> Truncated message</li>
<li><strong>RD (1 bit):</strong> Recursion Desired</li>
<li><strong>RA (1 bit):</strong> Recursion Available</li>
<li><strong>Z (3 bits):</strong> Reserved</li>
<li><strong>RCODE (4 bits):</strong> Response code (NoError, NXDomain, etc.)</li>
</ul>
<p><strong>Pro Tip:</strong> You can manipulate RD and RA flags when testing DNS resolvers to see how recursion affects response times and caching.</p>
<hr>
<h2>Hands-On: Inspecting DNS Headers</h2>
<p>Here’s a sample <strong>packet dump</strong> from a dig command:</p>
<pre><code class="language-bash">dig @8.8.8.8 serverless.fyi +norecurse +tcp
</code></pre>
<pre><code class="language-text">;; HEADER SECTION:
;; opcode: QUERY, status: NOERROR, id: 0x1a2b
;; flags: qr rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
</code></pre>
<ul>
<li><strong>id:</strong> 0x1a2b → matches request and response</li>
<li><strong>flags:</strong> qr rd → response, recursion desired</li>
<li><strong>Counts:</strong> QD=1, AN=1</li>
</ul>
<p>For network engineers, this is a simple way to verify resolver behavior and test DNS configurations.</p>
<hr>
<h2>Tricks and Tips with DNS Headers</h2>
<ol>
<li><strong>Custom Queries:</strong> Modify the ID and flags to test how servers handle out-of-order or spoofed requests.</li>
<li><strong>Load Testing:</strong> Adjust QDCOUNT to batch multiple questions in one query to simulate high DNS load.</li>
<li><strong>Security Analysis:</strong> Inspect the AA, TC, and RCODE bits to detect misconfigured authoritative servers.</li>
<li><strong>Packet Crafting:</strong> Tools like scapy let you build raw DNS packets and control every header bit:</li>
</ol>
<pre><code class="language-python">from scapy.all import *
dns_query = IP(dst="8.8.8.8")/UDP()/DNS(id=0x1234, rd=1, qd=DNSQR(qname="serverless.fyi"))
send(dns_query)
</code></pre>
<hr>
<h2>Conclusion: Small Header, Big Impact</h2>
<p>The <strong>DNS header</strong> may only be 12 bytes, but it carries critical instructions that govern the behavior of the most important internet service. From troubleshooting latency issues to testing server security, understanding each field opens a world of possibilities. Whether you are a developer, engineer, or cybersecurity enthusiast, mastering DNS headers gives you deeper insight into the hidden mechanics of the internet.</p>
<p><strong>Next time you open a website, remember:</strong> a tiny header is working behind the scenes to make it all possible.</p>]]></content:encoded>
</item>
</channel>
</rss>
