Ubuntu - Networking - DNS - Configure DNS Cache

/etc/systemd/resolved.conf
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See resolved.conf(5) for details
 
[Resolve]
#DNS=
#FallbackDNS=
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#DNSOverTLS=no
#Cache=no-negative
Cache=yes
#DNSStubListener=yes
#ReadEtcHosts=yes

NOTE: Options are:

Cache:

  • yes: The default. Resolving a domain name which already got queried earlier will return the previous result as long as it is still valid, and thus does not result in a new network request.
  • no: Be aware that turning off caching comes at a performance penalty, which is particularly high when DNSSEC is used.
  • no-negative: Only positive answers are cached.

CacheFromLocalhost:

  • no: The default. Caching is turned off by default for host-local DNS servers.
    • If a response comes from host-local IP address (such as 127.0.0.1 or ::1), the result wouldn't be cached in order to avoid potential duplicate local caching.
  • yes: Cache host-local DNS as well.