<?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[Stacked Thoughts]]></title><description><![CDATA[Stacked Thoughts]]></description><link>https://blog.yasir-khurshid.com</link><generator>RSS for Node</generator><lastBuildDate>Tue, 02 Jun 2026 15:41:54 GMT</lastBuildDate><atom:link href="https://blog.yasir-khurshid.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Understanding DNS Records]]></title><description><![CDATA[The Domain Name System (DNS) serves as the internet's phonebook, translating human-readable domain names into machine-readable IP addresses. Understanding DNS is essential for building reliable, secure applications and troubleshooting network issues....]]></description><link>https://blog.yasir-khurshid.com/understanding-dns-records</link><guid isPermaLink="true">https://blog.yasir-khurshid.com/understanding-dns-records</guid><category><![CDATA[dns]]></category><category><![CDATA[dns-records]]></category><category><![CDATA[networking]]></category><dc:creator><![CDATA[Yasir khurshid]]></dc:creator><pubDate>Sun, 06 Apr 2025 22:00:00 GMT</pubDate><content:encoded><![CDATA[<p>The Domain Name System (DNS) serves as the internet's phonebook, translating human-readable domain names into machine-readable IP addresses. Understanding DNS is essential for building reliable, secure applications and troubleshooting network issues.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744053309632/d9128d2b-24b7-4b0c-a86e-7f06adbb4e76.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-dns-resolution-process">DNS Resolution Process</h2>
<p>When you type <code>example.com</code> in your browser, the DNS resolution process works like this:</p>
<ol>
<li><p><strong>Local Cache Check</strong>: Your browser and operating system check their local DNS caches for recent lookups.</p>
</li>
<li><p><strong>Recursive Resolution</strong>: If the address is not found in the local cache, your system contacts a recursive DNS resolver (typically provided by your ISP). The recursive resolver performs the following steps:</p>
<ul>
<li><p><strong>Root Nameserver Query</strong>: The resolver first contacts one of the 13 root nameservers (labeled A through M), asking, “Who knows about .com domains?”</p>
</li>
<li><p><strong>TLD Nameserver Query</strong>: The root nameserver responds with the address of the Top-Level Domain (TLD) nameservers for .com domains. The resolver then queries these TLD nameservers, asking, “Who knows about <code>example.com</code>?”</p>
</li>
<li><p><strong>Authoritative Nameserver Query</strong>: The TLD nameserver responds with the address of the authoritative nameservers for <code>example.com</code>. The resolver then queries these authoritative servers, asking, “What is the IP address for <code>example.com</code>?”</p>
</li>
<li><p><strong>Answer Delivery</strong>: The authoritative nameserver responds with the requested DNS record (e.g., the A record containing the IP address).</p>
</li>
</ul>
</li>
<li><p><strong>Response Caching</strong>: The recursive resolver caches this response for future use, according to the Time-to-Live (TTL) value.</p>
</li>
<li><p><strong>Final Delivery</strong>: The IP address is returned to your browser, which then establishes a connection to the server hosting <code>example.com</code>.</p>
</li>
</ol>
<h2 id="heading-essential-dns-record-types">Essential DNS Record Types</h2>
<h3 id="heading-a-record"><strong>A Record</strong></h3>
<p>The fundamental record that maps a hostname to an IPv4 address. Tells your computer the IPv4 address of the server hosting your website or application.</p>
<pre><code class="lang-plaintext">example.com.     IN   A     93.184.216.34
</code></pre>
<p>This record indicates that <code>example.com</code> is hosted at the IPv4 address <code>93.184.216.34</code></p>
<h3 id="heading-aaaa-record"><strong>AAAA Record</strong></h3>
<p>Similar to the A record, but maps a hostname to an IPv6 address. Provides the IPv6 address for your website or application. Adopting IPv6 is becoming increasingly important</p>
<pre><code class="lang-plaintext">example.com.    IN   AAAA  2606:2800:220:1:248:1893:25c8:1946
</code></pre>
<p>This record maps <code>example.com</code> to the IPv6 address <code>2606:2800:220:1:248:1893:25c8:1946</code></p>
<h3 id="heading-cname-record"><strong>CNAME Record</strong></h3>
<p>It creates an alias for another domain name. It redirects one domain or subdomain to another. Common use cases include pointing <code>www.example.com</code> to <code>example.com</code> or creating specific subdomains for different services.</p>
<pre><code class="lang-plaintext">www.example.com.    IN   CNAME example.com.
</code></pre>
<p>This records makes <code>www.example.com</code> an alias of <code>example.com</code></p>
<p><strong>Why is this useful?</strong> Imagine you have multiple subdomains pointing to the same server. If the server's IP address changes, you only need to update the A record for the <em>original</em> domain. All CNAME records pointing to that domain will automatically inherit the new IP address, simplifying maintenance.</p>
<h3 id="heading-mx-record"><strong>MX Record</strong></h3>
<p>Specifies the mail servers responsible for accepting email messages on behalf of a domain. Essential for setting up email services for your domain</p>
<pre><code class="lang-plaintext">example.com.        IN   MX    10 mail.example.com.
</code></pre>
<p>This record routes email for <code>example.com</code> to <code>mail.example.com</code> with priority 10. Lower numbers indicate higher priority. If you have multiple MX records, the mail server will try the lowest priority number server first</p>
<h3 id="heading-ns-record"><strong>NS Record</strong></h3>
<p>Specifies the authoritative name servers for a domain. Delegates the authority for a domain or subdomain to specific name servers. Typically, you'll have multiple NS records for redundancy</p>
<pre><code class="lang-plaintext">example.com.        IN   NS    ns1.exampledns.com.
example.com.        IN   NS    ns2.exampledns.com.
</code></pre>
<p>This record specifies the authoritative nameservers for <code>example.com</code>.</p>
<h3 id="heading-txt-record"><strong>TXT Record</strong></h3>
<p>Contains arbitrary text-based information associated with a domain. Used for a variety of purposes, including domain ownership verification, SPF (Sender Policy Framework) records for email authentication, and storing arbitrary metadata</p>
<pre><code class="lang-plaintext">example.com.        IN   TXT   "v=spf1 include:_spf.google.com ~all"
</code></pre>
<p>Provides text info, often used for SPF, domain verification, or other metadata.</p>
<h3 id="heading-ptr-record"><strong>PTR Record</strong></h3>
<p>Performs a reverse DNS lookup, mapping an IP address back to a domain name. Used for verifying the legitimacy of a server. Often used in email authentication.</p>
<pre><code class="lang-plaintext">34.216.184.93.in-addr.arpa.  IN   PTR   example.com.
</code></pre>
<p>This maps an IP address back to a domain name (used for reverse DNS)</p>
<h3 id="heading-soa-record"><strong>SOA Record</strong></h3>
<p>Defines the primary authoritative server for a domain and provides essential administrative information like the contact email, serial number, and zone refresh settings. It is the first record in a DNS zone file and is required for proper zone operation and replication.</p>
<pre><code class="lang-plaintext">ns.icann.org. noc.dns.icann.org. 2025011602 7200 3600 1209600 3600
</code></pre>
<p>This record provides the following information:</p>
<ul>
<li><p><strong>Primary nameserver:</strong> <code>ns.icann.org</code> – the main server for DNS information.</p>
</li>
<li><p><strong>Admin contact:</strong> <code>noc@dns.icann.org</code> – contact email for DNS issues (written with a dot instead of <code>@</code>).</p>
</li>
<li><p><strong>Serial number:</strong> <code>2025011602</code> – version number of the zone file; changes when the zone is updated.</p>
</li>
<li><p><strong>Refresh interval:</strong> <code>7200</code> seconds (2 hours) – how often secondary servers check for updates.</p>
</li>
<li><p><strong>Retry interval:</strong> <code>3600</code> seconds (1 hour) – how long to wait before retrying after a failed update check.</p>
</li>
<li><p><strong>Expire time:</strong> <code>1209600</code> seconds (14 days) – how long a secondary server keeps using data if it can’t reach the primary.</p>
</li>
<li><p><strong>Minimum TTL:</strong> <code>3600</code> seconds (1 hour) – default time DNS records are cached by other servers.</p>
</li>
</ul>
<h3 id="heading-srv-record"><strong>SRV Record</strong></h3>
<p>Specifies the location (hostname and port number) of servers for specific services. Used to locate services like SIP, XMPP, and other network protocols. Useful for applications (VoIP or messaging systems) that rely on service discovery.</p>
<pre><code class="lang-plaintext">_ldap._tcp.example.com.  IN   SRV   10  5  389  ldap-server.example.com.
</code></pre>
<p>Specifies that the LDAP service (over TCP) for <code>example.com</code> is handled by <code>ldap-server.example.com</code>, with priority 10, weight 5, and port 389</p>
<h2 id="heading-symbol-in-dns-records">@ Symbol in DNS Records</h2>
<p>The <code>@</code> symbol in DNS records is shorthand for the domain itself, simplifying zone files. Instead of repeating the domain name, <code>@</code> acts as a placeholder. For example, <code>@ IN A 93.184.216.34</code> maps <code>example.com</code> to the IP address <code>93.184.216.34</code>. Similarly, <code>@ IN MX 10 mail.example.com</code> designates <code>mail.example.com</code> as the mail server for the main domain, making DNS records more concise and easier to manage. Use <code>@</code> for records applying to the entire domain, but not for subdomains.</p>
<h2 id="heading-dns-ttl-time-to-live">DNS TTL (Time To Live)</h2>
<p>It defines how long a DNS record is cached by resolvers before it must be refreshed. Measured in seconds, a <strong>higher TTL</strong> improves speed and reduces server load but delays DNS updates, while a <strong>lower TTL</strong> allows faster changes at the cost of increased traffic and potentially slower performance. Choosing the right TTL depends on how often you expect to update your DNS records</p>
<h2 id="heading-dns-records-vs-zone-files">DNS Records vs Zone Files</h2>
<p>A DNS record is a single entry within a DNS database that maps a domain name or subdomain to a specific value, like an IP address or another domain. Think of it as a single row in a spreadsheet, defining a specific piece of DNS information.</p>
<p>A zone file, on the other hand, is a text file that contains a collection of DNS records for a particular domain. It represents the complete authoritative source of DNS information for that domain, encompassing all its records (A, MX, CNAME, etc.). The zone file is what the authoritative DNS server reads to respond to DNS queries for that domain. So, a zone file is the container holding multiple DNS records</p>
<h2 id="heading-digging-into-dns-with-the-dig-command">Digging into DNS with the dig Command</h2>
<p>The dig command (Domain Information Groper) is a powerful command-line tool for querying DNS name servers. It's an essential tool for any developer who needs to troubleshoot DNS issues, verify configurations, or simply understand how DNS resolution work</p>
<p>Getting the A record for a domain</p>
<pre><code class="lang-bash">dig example.com A
</code></pre>
<p>Finding the MX records for a domain</p>
<pre><code class="lang-bash">dig example.com MX
</code></pre>
<p>Querying a specific DNS server</p>
<pre><code class="lang-bash">dig @8.8.8.8 example.com A  <span class="hljs-comment"># Query Google's Public DNS</span>
</code></pre>
<p>Getting a concise output</p>
<pre><code class="lang-bash">dig example.com A +short
</code></pre>
<p>Tracing the DNS resolution path</p>
<pre><code class="lang-bash">dig example.com A +trace
</code></pre>
<p>Check domain name for an IP Address</p>
<pre><code class="lang-bash">dig -x 172.217.168.206
</code></pre>
<p>View list of top level name servers</p>
<pre><code class="lang-bash">dig com +short NS
</code></pre>
<p>Check when cache will expire (use <a target="_blank" href="https://ttl-calc.com/">https://ttl-calc.com/</a> to calculate in hours and minutes)</p>
<pre><code class="lang-bash">dig example.com +noall +answer
</code></pre>
<p>Understanding DNS records is fundamental for software developers deploying and maintaining online services. By understanding the different record types and their purposes, you can ensure your applications are reachable, resilient, and performant.</p>
]]></content:encoded></item><item><title><![CDATA[Debugging Disappearing Console Logs on Redirects: A Simple Trick]]></title><description><![CDATA[A while back, I was debugging the implementation of tracking events for a registration form. The tracking script was logging debug information to the browser’s Developer Tools console, which was helpful for verifying event data. However, there was a ...]]></description><link>https://blog.yasir-khurshid.com/debugging-disappearing-console-logs-on-redirects-a-simple-trick</link><guid isPermaLink="true">https://blog.yasir-khurshid.com/debugging-disappearing-console-logs-on-redirects-a-simple-trick</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Developer Tools]]></category><dc:creator><![CDATA[Yasir khurshid]]></dc:creator><pubDate>Wed, 02 Apr 2025 13:15:55 GMT</pubDate><content:encoded><![CDATA[<p>A while back, I was debugging the implementation of tracking events for a registration form. The tracking script was logging debug information to the browser’s Developer Tools console, which was helpful for verifying event data. However, there was a problem—after a successful registration, the user was redirected to another page, and all console logs vanished.</p>
<h2 id="heading-why-do-console-logs-disappear-on-redirect"><strong>Why Do Console Logs Disappear on Redirect?</strong></h2>
<p>When a browser like Chrome performs a redirect, it unloads the current page and loads a new one. This means:</p>
<ul>
<li><p>The JavaScript execution context is lost.</p>
</li>
<li><p>The Developer Tools console is refreshed, clearing previous logs.</p>
</li>
<li><p>Any debug information logged before the redirect is no longer accessible.</p>
</li>
</ul>
<h2 id="heading-the-simple-trick-to-debug-before-redirect"><strong>The Simple Trick to Debug Before Redirect</strong></h2>
<p>After some research, I found a simple yet effective trick to pause execution right before the redirect:</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">window</span>.addEventListener(<span class="hljs-string">"beforeunload"</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{ <span class="hljs-keyword">debugger</span>; }, <span class="hljs-literal">false</span>);
</code></pre>
<p>Run the above code snippet in the Developer Tools console. This listens for the <code>beforeunload</code> event, which fires just before the page is unloaded (e.g., during navigation or refresh). Inside the event listener, <code>debugger;</code> triggers a breakpoint in the browser’s Developer Tools, pausing execution and allowing you to inspect console logs before they disappear.</p>
<p>For more details about <code>beforeunload</code>, check out <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event">MDN documentation on beforeunload</a>.</p>
]]></content:encoded></item></channel></rss>