Friday, September 2, 2022

[SOLVED] DNS caching in Linux

Issue

I am confused about DNS caching. I am writing a small forward proxy server and want to use the OS DNS cache on a Linux system.

If I understand correctly, there is DNS caching at the browser level. Then there is DNS caching at the OS level (Windows has it. I am not sure if Linux distros have it by default).

How does a browser or proxy server use OS DNS caching? I am trying to find out if I can rely on Linux for DNS caching instead of doing it on my own inside my proxy.


Solution

On Linux (and probably most Unix), there is no OS-level DNS caching unless nscd is installed and running. Even then, the DNS caching feature of nscd is disabled by default at least in Debian because it's broken. The practical upshot is that your linux system very very probably does not do any OS-level DNS caching.

You could implement your own cache in your application (like they did for Squid, according to diegows's comment), but I would recommend against it. It's a lot of work, it's easy to get it wrong (nscd got it wrong!!!), it likely won't be as easily tunable as a dedicated DNS cache, and it duplicates functionality that already exists outside your application.

If an end user using your software needs to have DNS caching because the DNS query load is large enough to be a problem or the RTT to the external DNS server is long enough to be a problem, they can install a caching DNS server such as Unbound on the same machine as your application, configured to cache responses and forward misses to the regular DNS resolvers.



Answered By - Celada
Answer Checked By - Gilberto Lyons (WPSolving Admin)