Flush DNS cache for ubuntu 20.04
How to clear/flush DNS cache for ubuntu 20.04
sudo systemd-resolve --flush-caches
The use below command to verify
sudo systemctl status systemd-resolved
Below is the real outputs of above two commands
root@ubuntu2004:~# systemd-resolve --flush-caches
root@ubuntu2004:~# systemctl status systemd-resolved
● systemd-resolved.service - Network Name Resolution
Loaded: loaded (/lib/systemd/system/systemd-resolved.service; enabled; vendor preset: enable>
Active: active (running) since Mon 2021-08-02 08:39:35 EDT; 29s ago
Docs: man:systemd-resolved.service(8)
https://www.freedesktop.org/wiki/Software/systemd/resolved
https://www.freedesktop.org/wiki/Software/systemd/writing-network-configuration-mana>
https://www.freedesktop.org/wiki/Software/systemd/writing-resolver-clients
Main PID: 4624 (systemd-resolve)
Status: "Processing requests..."
Tasks: 1 (limit: 4617)
Memory: 4.6M
CGroup: /system.slice/systemd-resolved.service
└─4624 /lib/systemd/systemd-resolved
Aug 02 08:39:35 ubuntu2004 systemd[1]: Starting Network Name Resolution...
Aug 02 08:39:35 ubuntu2004 systemd-resolved[4624]: Positive Trust Anchors:
Aug 02 08:39:35 ubuntu2004 systemd-resolved[4624]: . IN DS 20326 8 2 e06d44b80b8f1d39a95c0b0d7c65>
Aug 02 08:39:35 ubuntu2004 systemd-resolved[4624]: Negative trust anchors: 10.in-addr.arpa 16.172>
Aug 02 08:39:35 ubuntu2004 systemd-resolved[4624]: Using system hostname 'ubuntu2004'.
Aug 02 08:39:35 ubuntu2004 systemd[1]: Started Network Name Resolution.
Aug 02 08:39:55 ubuntu2004 systemd-resolved[4624]: Flushed all caches.
root@ubuntu2004:~#
A snippet of systemd-resolve man page:
--flush-caches
Flushes all DNS resource record caches the service maintains locally. This is mostly equivalent to sending the SIGUSR2 to the systemd-resolved service