0

I'm aware that DNS translates domain names to IPs. And for communication, the closest the other party is the faster it is of course. But in the case of DNS, where the user queries for one time about the server IP until the TTL expires (which might be a day) and has that answer cached.

So, why many are advising to keep the DNS close to the end user?

3

I believe this is related first to security reasons to avoid attacks such as DNS Spoofing/DNS cache poisoning. With those they could redirect the connections from your network to dodgy servers that would make you download unwanted files, would access pages that you don't want to etc.

Here you can read more about this kind of attack:

DNS Spoofing

Also probably you wouldn't want your server to have thousands of requests all the time from all around the world.

1
  • 1
    I would like to expand on your answer if may to include the fact that DNS resolution occurs in priority of hop count. If you have one internal and one external DNS server that both have resolution for "google.com" your host is going to query the server that requires the least amount of hops.
    – Gansheim
    Apr 12 '17 at 15:40
3

Keep in mind that it's an assumption that "closer" means "faster", and it often isn't the case.

where the user queries for one time about the server IP until the TTL expires (which might be a day) and has that answer cached.

When you hit a page your browser needs to do DNS lookups for all the resources on the page, so if you hit a page with 100 images that have DNS names for addresses, your browser is doing 100 DNS queries for that page.

For a more direct example: Looking at the debug/network tab in my browser while refreshing THIS page shows additional 39 GET requests, each (potentially) needing a DNS lookup.

Web page authors can decide how long a page is cached for (for the most part), and more and more resources on pages are not static these day, and as such are generated non the fly with each page call. This can potentially prevent/negate any browser caching options (at least in part).

So how often you need to hit DNS depends on a few things, including:

  • Number of additional resource/URL calls made to get content of the page you requested.
  • The users' browser cache settings.
  • The page's use of dynamic content.
  • The page's cache settings.

Since the advice your seeking clarification on is "general" advice, it has to cover all scenarios in general, including bad/worst case.

In the/a "worst case", there would be NO DNS caching happening by the client (i.e.: they've never visited a given page before), and therefore every resource location on the page needs to be looked up in DNS to render the page to you.

To get the fastest responses to render the page, you want the fastest possible DNS responses.

Also keep in mind that it's the same for practically ANY computing resource (not just DNS servers) -- while caching is great, the faster you can access it and get responses back when there is currently no cache, the better.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.