Dev.to WebDev 🛠 Dev 👁 2 📖 3 min read

The "It Works on My Machine" DNS Nightmare: A Step-by-Step Troubleshooting Guide

Hook: The "It Works on My Machine" DNS Nightmare We pushed the new A record to production at 10:00 AM. By 2:00 PM, the client was panicking because half their global traffic was hitting a 502 Bad Gateway. I ran a quick

Hook: The "It Works on My Machine" DNS Nightmare

We pushed the new A record to production at 10:00 AM. By 2:00 PM, the client was panicking because half their global traffic was hitting a 502 Bad Gateway. I ran a quick check from my terminal and got hit with this:

dig api.client-domain.com
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 42069

My machine was resolving the old IP, the client's office was seeing the new one, and users in Europe were getting a domain not found error. Welcome to DNS propagation hell. DNS changes are not instantaneous broadcasts; they are a waiting game of TTL (Time to Live) expirations across thousands of recursive resolvers.

If you are stuck waiting for DNS to propagate, here is the exact step-by-step troubleshooting workflow to figure out exactly which layer is holding onto the stale record.

1. Prerequisites: The Tools You Need

  • Terminal/CLI: Access to dig (Linux/macOS) or nslookup (Windows).
  • Authoritative Nameservers: Know where your DNS zone is hosted (e.g., Cloudflare, Route53, Namecheap).
  • The Expected IP: The final A record or CNAME target you just updated.

2. Step-by-Step: Diagnosing the Hold-Up

Step 1: Check the Authoritative DNS (The Source of Truth)

Before you blame your ISP or Google, check if your DNS provider actually saved the record. Query the nameserver directly by bypassing recursion.

# Replace ns1.yourprovider.com with your actual authoritative NS
dig @ns1.yourprovider.com api.client-domain.com +short

If this returns the old IP, your DNS provider hasn't saved the change (or the zone update is queued). If it returns the new IP, the source of truth is correct. The problem is downstream caching.

Step 2: Bypass Local Caching (Check Public Resolvers)

Your local ISP or Mac/Windows machine is likely caching the old record. Let's ask major public resolvers what they see. Use Google (8.8.8.8) and Cloudflare (1.1.1.1).

# Ask Cloudflare
dig @1.1.1.1 api.client-domain.com +short

# Ask Google
dig @8.8.8.8 api.client-domain.com +short

If one returns the new IP and the other returns the old one, they are just waiting for the TTL to expire. If both return the old IP, they are still holding onto the cached record.

Step 3: Trace the Entire Resolution Chain

If you want to see the exact path the DNS query takes from the root servers down to your domain, use the +trace flag. This is the ultimate X-ray for DNS issues.

dig api.client-domain.com +trace

Look at the final response section. It will show you exactly which nameserver is handing out the stale IP.

Step 4: Flush Your Local OS Cache

Sometimes, the issue is literally just your own laptop refusing to forget the old address.

# Windows
ipconfig /flushdns

# macOS (Ventura+)
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

# Linux (systemd)
sudo resolvectl flush-caches

3. Verify & Common Mistakes

Once your local cache is flushed and the TTL has expired, you should be routing to the new server. The easiest way to verify globally is using a browser-based DNS Lookup tool that queries multiple geographic locations simultaneously. If the new IP is showing up worldwide, propagation is done.

Common Mistake 1: The Missing "www" Record. You updated the root domain (@), but forgot to update the www CNAME. Always check both.

Common Mistake 2: CNAME at the Root. You cannot put a CNAME record at the apex/root domain (@). It violates RFC standards and breaks MX (email) records. Use an ALIAS or ANAME record if your provider supports it.

Common Mistake 3: Forgetting TTL. If you had a TTL of 86400 (24 hours) before the migration, it can literally take 24 hours for the old record to expire from global caches. Next time, lower the TTL to 300 seconds 24 hours before the migration.

4. Tool Table & Pitfalls

Scenario Recommended Tool Why it works
Check global propagation DNS Lookup Queries multiple TLDs and returns authoritative records instantly.
Test server response after DNS update HTTP Status Checker Checks if the new IP is serving traffic with a 200 OK.
Verify network reachability Ping Test Confirms the new server is actually responding to ICMP requests.

Pitfalls Summary:

  1. Never migrate without lowering TTL first — Drop TTL to 300s at least 24 hours before the switch.
  2. Always check the www subdomain — Most users type www, don't forget to route it.
  3. Do not put CNAMEs on root domains — It breaks email MX records and violates RFC.
  4. Wait for the TTL, don't panic — No amount of refreshing will speed up the global cache expiry.
  5. Check authoritative NS before blaming the world — If dig @ns1 is wrong, nothing else matters.
📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.