How do I clear the DNS cache?
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
For 18.04 and higher
Look at Mike Shultz' answer.
For 11.10 and below
Ubuntu doesn't cache dns records by default so unless you've installed a dns cache there isn't anything to clear.
DNS records are likely cached by your provider's DNS servers so if you want to check if the DNS changes you made were successful you can interrogate a DNS server from your domain hosting service with dig:
dig -t a ns1.myhostingcompany.com @domain_registrar_dns_server
It you want Ubuntu to start caching dns I recommend installing pdnsd
together with resolvconf
. nscd
is buggy and not advisable.
12.04
Ubuntu 12.04 uses dnsmasq
which is built into network-manager
, but it doesn't cache dns so there is no need to flush it. Here is a sample line from my syslog
to prove that point:
dnsmasq[2980]: started, version 2.59 cache disabled
There is also no need for any configuration of dnsmasq
. If you are running with stock settings it won't be caching dns, as for it to do so you have to explicitly set it up as this Ubuntu article describes.
If you wanted to refresh your settings you could disable and then enable networking or run
sudo service network-manager restart
This restarts dnsmasq
because it is built in to network-manager
; check your syslog
for the evidence for this.
If you are using a wired connection with dhcp network manager
will be taking the settings direct from your router and your connection will be automatically established when you login to Ubuntu. You could check that the settings are correct in your router if you can access it via the web interface, and perhaps reboot it if necessary.
If it is a general problem with dns, you could try using Google dns instead of your isp dns, and more information on that is detailed here.