Ubuntu: How do I clear the DNS cache?
Channel: Roel Van de Paar
Date: 2019-06-07

Ubuntu: How do I clear the DNS cache?


Question: I just updated the DNS record (ns1, ns2, ns3.myhostingcompany.com) for a site
I've got hosted, but I still get the domain registrar parking page.
I'd like to see if the problem is Ubuntu's cached DNS records. Is there a way
to clear Ubuntu's DNS cache? (if such a thing exists?)

Solutions Sample (Please watch the whole video to see all solutions, in order of how many people found them helpful):

== This solution helped 11 people ==
Personally, I'd https://store.opendns.com/setup/device/ubuntu/ and use their
Cache_Check_function to force a refresh just to make sure the changes work but
you can't guarantee they'll refresh for your users within 48 hours.
DNS is a slow beast. Patience will keep you sane.

== This solution helped 16 people ==
sudo /etc/init.d/nscd restart
http://www.ubuntugeek.com/howto-clearflush-dns-cache-in-ubuntu.html
Also as a note you can check and see if your DNS changes have propagated using
dig and looking up against someone else other than your default DNS servers. In
this case google DNS.
dig @8.8.8.8 example.com

== This solution helped 1 person ==
I used the following command to flush the dns cache on my 12.10 ubuntu box and
it worked fantastic.
sudo kill -HUP $(pgrep dnsmasq)
Another helpful signal is the SIGUSR1 which dump a little statistic to syslog
or as it is note from man dnsmasq:
     In --no-daemon mode or when full logging is enabled (-q), a complete
     dump of the contents of the cache is made.

== This solution helped 2 people ==
For ubuntu 14.04, I recommand this command :
sudo service dns-clean

== This solution helped 40 people ==
**** For 12.04: ****
Ubuntu 12.04 does cache DNS using dnsmasq ( see man dnsmasq). Use the following
to clear the cache:
sudo kill -HUP $(pgrep dnsmasq)

== This solution helped 45 people ==
****** Ubuntu 17.04 and higher (18.04) ******
From Ubuntu 17.04 and onwards, systemd-resolve is used for DNS. You can flush
systemd's caches like so:
sudo systemd-resolve --flush-caches

With thanks & praise to God! With thanks to all the many who have made this project possible! | Content (except music & images) licensed under cc by-sa 3.0 | Music & music license: https://www.bensound.com/royalty-free-music | Images & images license: https://stocksnap.io/license and others | With thanks to user zechariah (https://askubuntu.com/users/61808), user Oli (https://askubuntu.com/users/449), user Mike Shultz (https://askubuntu.com/users/397813), user Mark Davidson (https://askubuntu.com/users/67), user Li Lo (https://askubuntu.com/users/289), user Jorge Castro (https://askubuntu.com/users/235), user Jono (https://askubuntu.com/users/199), user j0inty (https://askubuntu.com/users/135611), user Galgalesh (https://askubuntu.com/users/172367), user fossfreedom (https://askubuntu.com/users/14356), user Eric Carvalho (https://askubuntu.com/users/65926), user BuZZ-dEE (https://askubuntu.com/users/23878), user bikesandcode (https://askubuntu.com/users/1195), user Benoit (https://askubuntu.com/users/257805), user alphayax (https://askubuntu.com/users/551536), and the Stack Exchange Network (http://stackoverflow.com/questions/2219). Trademarks are property of their respective owners. Disclaimer: All information is provided "AS IS" without warranty of any kind. You are responsible for your own actions. Please contact me if anything should be amiss at Roel D.OT VandePaar A.T gmail.com.