How DNS Caching Works and When to Clear It

March 1, 2024

Every time you visit a website, your computer doesn't actually look up the DNS record from scratch. That would be incredibly slow. Instead, it uses caching.

What is DNS Caching?

Caching means storing information temporarily so you don't have to fetch it again. DNS caching happens at multiple levels:

1.

Browser cache

- Your browser remembers recent lookups 2.

Operating system cache

- Windows, Mac, and Linux all maintain DNS caches 3.

Router cache

- Your home router often caches DNS too 4.

ISP cache

- Your internet provider's DNS servers cache records

When you visit a site, your request checks each cache level before going to the authoritative DNS server.

TTL: The Expiration Date

Every DNS record has a TTL (Time To Live) measured in seconds. This tells caches how long to keep the record. Common values:

- 300 (5 minutes) - For records that change frequently - 3600 (1 hour) - A reasonable default - 86400 (24 hours) - For stable records - 604800 (1 week) - For records that rarely change

When Caching Causes Problems

Caching is great until you need to make a change. If you update your website's IP address, people with cached records will still go to the old address until their cache expires.

This is why DNS propagation takes time. It's not really "propagating" - it's waiting for caches to expire.

How to Clear Your DNS Cache

Windows:

ipconfig /flushdns

Mac:

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Linux:

sudo systemd-resolve --flush-caches

Chrome:

Visit chrome://net-internals/#dns and click "Clear host cache"

Pro Tips

- Before making DNS changes, lower your TTL a day or two in advance - After changes, wait for the old TTL to expire before raising it again - Use DNS checking tools to verify your changes from multiple locations - Remember that some ISPs ignore TTL and cache longer anyway

Caching is one of those things that works so well, you forget it exists - until it doesn't.