Every time you access a web page there will be a few dozen network requests to a few different servers. Before every network request can run there will be a connection made to a DNS server to look up the IP address of the website server.
If you visit the same website again soon after your computer will remember the result of the previous DNS query and not need to ask the DNS server for the IP again. However I’ve noticed that this cache expires fairly quickly and that network requests to the same server, often only minutes later, involve a DNS query that seems redundant – DNS settings don’t change all that often.
I don’t know if this is just an #OpenSuse thing or whether other distros also use the nscd daemon but on my OpenSuse Leap 15.3 system I’ve found the place where DNS gets cached locally is managed by this thing called nscd.
If you have a file /etc/nscd.conf then chances are high that the daemon is running on your system.
To increase the DNS cache time, edit /etc/nscd.conf and find the line that says
Be careful – there are many other lines that look similar in that file, you want the one ending in ‘hosts’.
The value at the end of that line is the number of seconds to cache for. FYI 43200 seconds is 12 hours, the setting I use.
A couple of lines below that is another one
which you might want to set to ‘yes’ if you reboot often.
Use nscd -g to check on the cache hit rate.
After making any changes, restart nscd with
sudo systemctl restart nscd.service