<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How DNS Resolution Works]]></title><description><![CDATA[How DNS Resolution Works]]></description><link>https://how-dns-resolution-chaicodeassignmentworks.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 19 Jun 2026 11:35:19 GMT</lastBuildDate><atom:link href="https://how-dns-resolution-chaicodeassignmentworks.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Deep Dive into DNS: Mastering Name Resolution with the dig Command]]></title><description><![CDATA[Introduction
Imagine trying to find a friend's house without a street address. You'd need to ask around, get directed to neighborhoods, then to specific areas, and finally to their street. That's essentially what happens every time you visit a websit...]]></description><link>https://how-dns-resolution-chaicodeassignmentworks.hashnode.dev/deep-dive-into-dns-mastering-name-resolution-with-the-dig-command</link><guid isPermaLink="true">https://how-dns-resolution-chaicodeassignmentworks.hashnode.dev/deep-dive-into-dns-mastering-name-resolution-with-the-dig-command</guid><category><![CDATA[#DNS commands]]></category><category><![CDATA[dns]]></category><category><![CDATA[dns resolver]]></category><category><![CDATA[#DNS Resolution]]></category><category><![CDATA[How DNS works]]></category><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[ChaiCohort]]></category><dc:creator><![CDATA[ALOK YADAV]]></dc:creator><pubDate>Sat, 31 Jan 2026 14:27:00 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>Imagine trying to find a friend's house without a street address. You'd need to ask around, get directed to neighborhoods, then to specific areas, and finally to their street. That's essentially what happens every time you visit a website—your browser needs to convert a human-readable domain name like <a target="_blank" href="http://google.com"><code>google.com</code></a> into an IP address that computers can understand. This translation process is DNS (Domain Name System), the internet's phonebook.</p>
<p>In this article, we'll explore DNS resolution by using the <code>dig</code> command—a powerful diagnostic tool that reveals the behind-the-scenes magic of how names get resolved to IP addresses.</p>
<h2 id="heading-what-is-dns">What is DNS?</h2>
<p>DNS stands for Domain Name System. It's a hierarchical system that translates domain names into IP addresses. Without DNS, you'd have to remember and type IP addresses like <code>142.251.32.46</code> to visit Google instead of typing <a target="_blank" href="http://google.com"><code>google.com</code></a>.</p>
<h3 id="heading-why-name-resolution-exists">Why Name Resolution Exists</h3>
<p>There are three main reasons why name resolution is critical:</p>
<ol>
<li><p><strong>Human-Friendly</strong>: IP addresses are hard to remember; domain names are intuitive</p>
</li>
<li><p><strong>Scalability</strong>: As servers move or IP addresses change, only DNS records need updating—users still use the same domain</p>
</li>
<li><p><strong>Load Distribution</strong>: Multiple IP addresses can be assigned to one domain for load balancing</p>
</li>
</ol>
<h2 id="heading-what-is-the-dig-command">What is the dig Command?</h2>
<p><code>dig</code> (Domain Information Groper) is a command-line tool for querying DNS servers. It's invaluable for:</p>
<ul>
<li><p>Debugging DNS issues</p>
</li>
<li><p>Understanding how DNS resolution works</p>
</li>
<li><p>Verifying DNS records are correctly configured</p>
</li>
<li><p>Troubleshooting connectivity issues</p>
</li>
<li><p>Learning system design and network architecture</p>
</li>
</ul>
<h3 id="heading-when-to-use-dig">When to Use dig</h3>
<ul>
<li><p>Your website isn't loading but the server is online</p>
</li>
<li><p>You're setting up DNS records and want to verify they're live</p>
</li>
<li><p>You need to understand the DNS resolution path</p>
</li>
<li><p>You're preparing for system design interviews</p>
</li>
</ul>
<h2 id="heading-dns-resolution-the-hierarchical-layers">DNS Resolution: The Hierarchical Layers</h2>
<p>DNS resolution works in three main layers, each with specific name servers:</p>
<ol>
<li><p><strong>Root Name Servers</strong> - Know where TLD servers are located</p>
</li>
<li><p><strong>TLD (Top-Level Domain) Servers</strong> - Know where authoritative servers for specific domains are</p>
</li>
<li><p><strong>Authoritative Name Servers</strong> - Hold the actual DNS records for a domain</p>
</li>
</ol>
<p>Let's explore each layer using <code>dig</code> commands.</p>
<h2 id="heading-layer-1-understanding-root-name-servers-with-dig-ns">Layer 1: Understanding Root Name Servers with <code>dig . NS</code></h2>
<p>Root name servers are the first stop in DNS resolution. They don't hold actual records; instead, they redirect queries to the appropriate TLD servers.</p>
<h3 id="heading-running-the-command">Running the Command</h3>
<pre><code class="lang-bash">dig . NS
</code></pre>
<p>This command asks: "Who are the root name servers?"</p>
<h3 id="heading-understanding-the-output">Understanding the Output</h3>
<p>You'll see results like:</p>
<pre><code class="lang-plaintext">; &lt;&lt;&gt;&gt; DiG 9.10.6 &lt;&lt;&gt;&gt; . NS
; (1 server found)
;; global options: +cmd
;; Got answer:
;; -&gt;&gt;HEADER&lt;&lt;- opcode: QUERY, status: NOERROR, id: 54321
;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 27

;; ANSWER SECTION:
.    518400    IN    NS    a.root-servers.net.
.    518400    IN    NS    b.root-servers.net.
.    518400    IN    NS    c.root-servers.net.
; ... (more root servers)
</code></pre>
<h3 id="heading-what-this-means">What This Means</h3>
<ul>
<li><p>There are <strong>13 root name servers</strong> (labeled a through m)</p>
</li>
<li><p>These are distributed globally for redundancy</p>
</li>
<li><p>They cache the locations of all TLD servers</p>
</li>
<li><p>The TTL (Time To Live) is 518400 seconds (6 days)</p>
</li>
<li><p>These root servers are the Internet's foundational infrastructure</p>
</li>
</ul>
<h2 id="heading-layer-2-understanding-tld-servers-with-dig-com-ns">Layer 2: Understanding TLD Servers with <code>dig com NS</code></h2>
<p>Once your recursive resolver knows where the root servers are, it asks them: "Where do I find information about <code>.com</code> domains?"</p>
<h3 id="heading-running-the-command-1">Running the Command</h3>
<pre><code class="lang-bash">dig com NS
</code></pre>
<p>This queries the root servers to find which servers manage <code>.com</code> domains.</p>
<h3 id="heading-understanding-the-output-1">Understanding the Output</h3>
<pre><code class="lang-plaintext">; &lt;&lt;&gt;&gt; DiG 9.10.6 &lt;&lt;&gt;&gt; com NS

;; ANSWER SECTION:
com.    172800    IN    NS    a.gtld-servers.net.
com.    172800    IN    NS    b.gtld-servers.net.
com.    172800    IN    NS    c.gtld-servers.net.
; ... (more TLD servers)
</code></pre>
<h3 id="heading-what-this-means-1">What This Means</h3>
<ul>
<li><p>There are <strong>13 TLD servers</strong> for <code>.com</code> domains (generic TLDs have multiple servers)</p>
</li>
<li><p>These are called gTLD servers (Global Top-Level Domain)</p>
</li>
<li><p>The TTL is 172800 seconds (2 days)</p>
</li>
<li><p>These servers know which companies own which <code>.com</code> domains</p>
</li>
<li><p>For every TLD (<code>.org</code>, <code>.edu</code>, <code>.net</code>, <code>.in</code>, etc.), there are dedicated TLD servers</p>
</li>
</ul>
<h2 id="heading-layer-3-understanding-authoritative-servers-with-dig-googlecomhttpgooglecom-ns">Layer 3: Understanding Authoritative Servers with <code>dig</code> <a target="_blank" href="http://google.com"><code>google.com</code></a> <code>NS</code></h2>
<p>Now we're getting specific. After the recursive resolver contacts a TLD server, it asks: "Where do I find DNS information specifically for <a target="_blank" href="http://google.com">google.com</a>?"</p>
<h3 id="heading-running-the-command-2">Running the Command</h3>
<pre><code class="lang-bash">dig google.com NS
</code></pre>
<p>This queries TLD servers to find the authoritative name servers for <a target="_blank" href="http://google.com">google.com</a>.</p>
<h3 id="heading-understanding-the-output-2">Understanding the Output</h3>
<pre><code class="lang-plaintext">;; ANSWER SECTION:
google.com.    172800    IN    NS    ns1.google.com.
google.com.    172800    IN    NS    ns2.google.com.
google.com.    172800    IN    NS    ns3.google.com.
google.com.    172800    IN    NS    ns4.google.com.
</code></pre>
<h3 id="heading-what-this-means-2">What This Means</h3>
<ul>
<li><p><strong>Google runs its own authoritative name servers</strong> for <a target="_blank" href="http://google.com">google.com</a></p>
</li>
<li><p>These servers (<a target="_blank" href="http://ns1.google.com"><code>ns1.google.com</code></a>, <a target="_blank" href="http://ns2.google.com"><code>ns2.google.com</code></a>, etc.) hold the actual DNS records</p>
</li>
<li><p>The TTL is 172800 seconds (2 days)</p>
</li>
<li><p>Only authoritative servers can respond authoritatively to queries about <a target="_blank" href="http://google.com">google.com</a></p>
</li>
<li><p>Other companies can't claim authority over <a target="_blank" href="http://google.com">google.com</a> records</p>
</li>
</ul>
<h2 id="heading-layer-4-complete-dns-resolution-with-dig-googlecomhttpgooglecom">Layer 4: Complete DNS Resolution with <code>dig</code> <a target="_blank" href="http://google.com"><code>google.com</code></a></h2>
<p>Now let's see the complete journey. This command performs the full DNS resolution—it's what happens when you type a URL in your browser.</p>
<h3 id="heading-running-the-command-3">Running the Command</h3>
<pre><code class="lang-bash">dig google.com
</code></pre>
<p>This performs a complete recursive resolution query.</p>
<h3 id="heading-understanding-the-output-3">Understanding the Output</h3>
<pre><code class="lang-plaintext">; &lt;&lt;&gt;&gt; DiG 9.10.6 &lt;&lt;&gt;&gt; google.com
;; global options: +cmd
;; Got answer:
;; -&gt;&gt;HEADER&lt;&lt;- opcode: QUERY, status: NOERROR, id: 12345
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 8

;; QUESTION SECTION:
;google.com.            IN    A

;; ANSWER SECTION:
google.com.        300    IN    A    142.251.32.46

;; AUTHORITY SECTION:
google.com.        172800    IN    NS    ns1.google.com.
google.com.        172800    IN    NS    ns2.google.com.
google.com.        172800    IN    NS    ns3.google.com.
google.com.        172800    IN    NS    ns4.google.com.

;; ADDITIONAL SECTION:
ns1.google.com.        172800    IN    A    216.239.32.10
ns2.google.com.        172800    IN    A    216.239.34.10
ns3.google.com.        172800    IN    A    216.239.36.10
ns4.google.com.        172800    IN    A    216.239.38.10
</code></pre>
<h3 id="heading-breaking-down-the-output">Breaking Down the Output</h3>
<p><strong>QUESTION SECTION</strong>: What are we looking for?</p>
<ul>
<li>We're looking for an <strong>A record</strong> (IPv4 address) for <a target="_blank" href="http://google.com"><code>google.com</code></a></li>
</ul>
<p><strong>ANSWER SECTION</strong>: The actual result</p>
<ul>
<li><p><a target="_blank" href="http://google.com"><code>google.com</code></a> resolves to <code>142.251.32.46</code></p>
</li>
<li><p>TTL is 300 seconds (5 minutes)—this answer will be cached</p>
</li>
</ul>
<p><strong>AUTHORITY SECTION</strong>: Who said this?</p>
<ul>
<li><p>The authoritative name servers that answered this query</p>
</li>
<li><p>Shows Google's four name servers</p>
</li>
</ul>
<p><strong>ADDITIONAL SECTION</strong>: Bonus information</p>
<ul>
<li><p>The IP addresses of the authoritative name servers themselves</p>
</li>
<li><p>Helps avoid additional DNS lookups</p>
</li>
</ul>
<h2 id="heading-understanding-ns-records">Understanding NS Records</h2>
<p>NS (Name Server) records are the backbone of DNS:</p>
<ul>
<li><p>They tell you "which server is responsible for this domain?"</p>
</li>
<li><p>At each layer (root, TLD, authoritative), NS records delegate to the next level</p>
</li>
<li><p>Root NS records point to TLD servers</p>
</li>
<li><p>TLD NS records point to authoritative servers</p>
</li>
<li><p>Authoritative servers provide the actual A/AAAA/CNAME records</p>
</li>
</ul>
<h2 id="heading-the-complete-dns-resolution-flow">The Complete DNS Resolution Flow</h2>
<p>Here's what happens when you visit <a target="_blank" href="http://google.com"><code>google.com</code></a>:</p>
<ol>
<li><p><strong>Browser Query</strong>: Your browser asks your recursive resolver for <a target="_blank" href="http://google.com">google.com</a>'s IP</p>
</li>
<li><p><strong>Recursive Resolver Contacts Root</strong>: The resolver queries a root name server</p>
</li>
<li><p><strong>Root Server Responds</strong>: "I don't know <a target="_blank" href="http://google.com">google.com</a>, but ask the <code>.com</code> TLD servers"</p>
</li>
<li><p><strong>Query TLD Server</strong>: The resolver asks a <code>.com</code> TLD server</p>
</li>
<li><p><strong>TLD Server Responds</strong>: "I don't have the record, but ask google's authoritative servers"</p>
</li>
<li><p><strong>Query Authoritative Server</strong>: The resolver asks <a target="_blank" href="http://ns1.google.com">ns1.google.com</a></p>
</li>
<li><p><strong>Authoritative Server Responds</strong>: "<a target="_blank" href="http://google.com">google.com</a> is 142.251.32.46"</p>
</li>
<li><p><strong>Caching</strong>: The resolver caches this result (for the TTL period)</p>
</li>
<li><p><strong>Browser Connects</strong>: Your browser connects to 142.251.32.46</p>
</li>
</ol>
<h2 id="heading-recursive-resolvers-the-invisible-workers">Recursive Resolvers: The Invisible Workers</h2>
<p>Behind the scenes, recursive resolvers (like Google's 8.8.8.8 or Cloudflare's 1.1.1.1) do the heavy lifting:</p>
<ul>
<li><p>They follow the DNS hierarchy layer by layer</p>
</li>
<li><p>They cache results to avoid repeated queries</p>
</li>
<li><p>They return results to clients even if they have to query multiple servers</p>
</li>
<li><p>They're typically provided by your ISP or run on your local machine</p>
</li>
</ul>
<h2 id="heading-real-world-connection-from-dig-to-browser">Real-World Connection: From dig to Browser</h2>
<p>When you type <a target="_blank" href="http://google.com"><code>google.com</code></a> in your browser:</p>
<ol>
<li><p>Browser queries your system's resolver</p>
</li>
<li><p>System resolver performs the same steps as <code>dig</code> <a target="_blank" href="http://google.com"><code>google.com</code></a></p>
</li>
<li><p>All three layers are contacted (root → TLD → authoritative)</p>
</li>
<li><p>The final IP address is returned and cached</p>
</li>
<li><p>Browser uses that IP to establish an HTTPS connection</p>
</li>
<li><p>Server responds and your browser displays the page</p>
</li>
</ol>
<h2 id="heading-practical-dig-commands-for-system-design">Practical Dig Commands for System Design</h2>
<p>Here are other useful <code>dig</code> queries for understanding DNS:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Get MX records (mail servers)</span>
dig google.com MX

<span class="hljs-comment"># Get all records</span>
dig google.com ANY

<span class="hljs-comment"># Query a specific name server</span>
dig @ns1.google.com google.com

<span class="hljs-comment"># Show DNSSEC information</span>
dig google.com +dnssec

<span class="hljs-comment"># Show query process step by step</span>
dig google.com +trace
</code></pre>
<h2 id="heading-key-takeaways">Key Takeaways</h2>
<ol>
<li><p><strong>DNS is hierarchical</strong>: Root → TLD → Authoritative</p>
</li>
<li><p><strong>Each layer serves a purpose</strong>: Delegation, optimization, and finally returning the IP</p>
</li>
<li><p><strong>dig reveals the process</strong>: You can see exactly how name resolution works</p>
</li>
<li><p><strong>NS records are the delegation mechanism</strong>: They point to the next server in the chain</p>
</li>
<li><p><strong>Caching is crucial</strong>: TTL values balance between accuracy and performance</p>
</li>
<li><p><strong>System design matters</strong>: Understanding DNS is essential for building scalable systems</p>
</li>
</ol>
<h2 id="heading-conclusion">Conclusion</h2>
<p>The <code>dig</code> command transforms DNS from a mysterious black box into an understandable system. By querying each layer separately (root, TLD, authoritative) and then performing a complete resolution, you've learned how billions of domain names are translated into IP addresses every day.</p>
<p>Next time a website is slow to load or doesn't resolve, you'll know exactly how to use <code>dig</code> to investigate. And if you're preparing for system design interviews, understanding this hierarchical delegation and caching system will give you deep insights into how the internet infrastructure works.</p>
<p>Happy digging!</p>
]]></content:encoded></item></channel></rss>