How to delete DNS cache on Linux?

dns linux

To delete the DNS cache on most used Linux distributions, the commands will vary depending on the distribution and version:

Ubuntu 14.04 (Trusty Tahr)

Ubuntu 14.04 uses dnsmasq as the DNS resolver. To clear the DNS cache, you can restart the dnsmasq service:

sudo service dnsmasq restart

Ubuntu 16.04 (Xenial Xerus)

Ubuntu 16.04 uses systemd-resolved as the DNS resolver. To clear the DNS cache, you can restart the systemd-resolved service:

sudo systemctl restart systemd-resolved

Ubuntu 18.04 (Bionic Beaver)

Ubuntu 18.04 also uses systemd-resolved. The command to clear the DNS cache remains the same:

sudo systemctl restart systemd-resolved

Ubuntu 20.04 (Focal Fossa) and Later

Ubuntu 20.04 and later versions continue to use systemd-resolved. To clear the DNS cache, you can use the following command:

sudo systemctl restart systemd-resolved

AlmaLinux 7

AlmaLinux 7 uses nscd (Name Service Cache Daemon) for DNS caching. To clear the DNS cache, you can restart the nscd service:

sudo systemctl restart nscd

If you are using dnsmasq for DNS caching, you can restart the dnsmasq service:

sudo systemctl restart dnsmasq

AlmaLinux 8

AlmaLinux 8 uses systemd-resolved for DNS caching. To clear the DNS cache, you can restart the systemd-resolved service:

sudo systemctl restart systemd-resolved

If you are using nscd for DNS caching, you can restart the nscd service:

sudo systemctl restart nscd

AlmaLinux 9

AlmaLinux 9 continues to use systemd-resolved for DNS caching. The command to clear the DNS cache remains the same:

sudo systemctl restart systemd-resolved

Debian 7 (Wheezy)

Debian 7 uses nscd (Name Service Cache Daemon) for DNS caching. To clear the DNS cache, you can restart the nscd service:

sudo service nscd restart

Debian 8 (Jessie)

Debian 8 also uses nscd for DNS caching. The command to clear the DNS cache remains the same:

sudo service nscd restart

Debian 9 (Stretch)

Debian 9 uses systemd-resolved for DNS caching. To clear the DNS cache, you can restart the systemd-resolved service:

sudo systemctl restart systemd-resolved

If you are using nscd for DNS caching, you can restart the nscd service:

sudo systemctl restart nscd

Debian 10 (Buster)

Debian 10 continues to use systemd-resolved for DNS caching. The command to clear the DNS cache remains the same:

sudo systemctl restart systemd-resolved

If you are using nscd for DNS caching, you can restart the nscd service:

sudo systemctl restart nscd

Debian 11 (Bullseye) and Later

Debian 11 and later versions continue to use systemd-resolved. To clear the DNS cache, you can use the following command:

sudo systemctl restart systemd-resolved

If you are using nscd for DNS caching, you can restart the nscd service:

sudo systemctl restart nscd

Rocky Linux 7

Rocky Linux 7 uses nscd (Name Service Cache Daemon) for DNS caching. To clear the DNS cache, you can restart the nscd service:

sudo systemctl restart nscd

If you are using dnsmasq for DNS caching, you can restart the dnsmasq service:

sudo systemctl restart dnsmasq

Rocky Linux 8

Rocky Linux 8 uses systemd-resolved for DNS caching. To clear the DNS cache, you can restart the systemd-resolved service:

sudo systemctl restart systemd-resolved

If you are using nscd for DNS caching, you can restart the nscd service:

sudo systemctl restart nscd

Rocky Linux 9

Rocky Linux 9 continues to use systemd-resolved for DNS caching. The command to clear the DNS cache remains the same:

sudo systemctl restart systemd-resolved

If you are using nscd for DNS caching, you can restart the nscd service:

sudo systemctl restart nscd