Config RHEL8 for Local DNS Caching

Time to configure: 30 seconds if you're drag your feet...

Linux hosts have DNS "Alzheimers": it does't "remember" anything of previous DNS queries it made. When hostnames are resolved, these name:IP mappings are not retained locally by default. So the next time a Linux host needs a mapping that was previously resolved it once again must reach-out to a remote DNS server to resolve it. This causes undue latency and can also impact on bandwidth.

Although Red Hat very helpfully setup a local DNS stub resolver systemd-resolved in RHEL 8, they did half a job: the default is NOT to use it. However, it's trivial to configure, takes 2 seconds and if you don't use local DNS caching, you're a masochist.

To configure your RHEL 8 host to use systemd-resolved as a local DNS caching server just one change to a single directive is required. In /etc/nsswitch.conf prepend "resolve" to the list of DNS sources consulted in the "hosts:" directive as follows:

hosts: resolve files dns myhostname

(2) Screenshots follow which show you BEFORE and AFTER making the change.

SCREENSHOT 1: Proof systemd-resolved is not caching DNS query answers, nor attempting to consult the cache at all:

We show systemd-resolved is both present and enabled, but after doing a ping requiring name resolution, the mapping is not added to the systemd-resolved 's cache:

BEFORE changing the hosts: directive in /etc/nsswitch.conf

SCREENSHOT 2: Proof the host is now both caching DNS queries and retrieving those name:IP mapping locally from the cache in lieu of reaching out to a remote DNS server:

No alt text provided for this image

DNS name caching doesn't sound very sexy, but it's the "boring" details such as these that can kill performance. Being both a Linux & Network Engineer, I really suggest you implement this feature on your hosts: big reward for little effort-

-Terrence Houlahan

要查看或添加评论,请登录

Terrence Houlahan的更多文章

社区洞察

其他会员也浏览了