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?)
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:
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 withresolvconf
.nscd
is buggy and not advisable.12.04
Ubuntu 12.04 uses
dnsmasq
which is built intonetwork-manager
, but it doesn't cache dns so there is no need to flush it. Here is a sample line from mysyslog
to prove that point: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
This restarts
dnsmasq
because it is built in tonetwork-manager
; check yoursyslog
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.Note that Ubuntu uses systemd-resolve from 17.04 and onwards so this answer doesn't apply anymore to recent Ubuntu versions. See "flush DNS cache in Ubuntu 17.04 and higher (18.04)"
By default, DNS is not cached in Ubuntu < 17.04 (but it might be cached in the network or application)
To confirm one way or the other whether
dnsmasq
is caching, runps ax | grep dnsmasq
and look at the running command. Here's a breakdown of my default 13.10 machine:/etc/NetworkManager/dnsmasq.d
is empty by default. So there aren't any overrides coming in there and just to check--cache-size=0
means what we think it means (instead of an unlimited cache),man dnsmasq
shows:So while
dnsmasq
can cache DNS, it isn't caching out the box. You can check your machine and various configuration directories to check you're on the same page.If you are seeing cache issues, this is likely happening in one of a few places:
I'm scraping the barrel here but perhaps you've installed a non-standard DNS server in Ubuntu instead of turning caching on in
dnsmasq
. There are many:nscd
, DJBDNSdnscache
(aka TinyDNS),pdns
,pdnsd
, Bind9 (and its variants), and more I can't even remember. These will probably be evidenced in/etc/resolv.conf
(with config in /etc/resolvconf/` to autogen that file). The following shows an locally intercepted DNS query:If you're not hitting 8.8.8.8 (or whatever you expect your DNS server to be), check what you are hitting instead. In my case I can see this is just
dnsmasq
set up to mirror DNS queries back for LXC, but in your case it might be doing bad cachey things.If you have done of the listed caches, the process for clearing each varies:
On a slightly related note, see this to enable caching in
dnsmasq
.For 12.04:
Ubuntu 12.04 does cache DNS using dnsmasq ( see
man dnsmasq
). Use the following to clear the cache: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
Personally, I'd use OpenDNS 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.
If you are using nscd:
It's worth mentioning that it might not be the OS that is caching it. Everyone likes to cache DNS... Some tests:
Check to see if it's the new or old IP. Most browsers cache DNS as well, so if you haven't restarted Chromium or whatever you might not be seeing the latest.
Switch your local nameserver in the /etc/resolv.conf to another provider, google or level , examples:
And then ping again.
Check to make sure your router isn't caching DNS in any form. (Varies by router/firmware/etc)
Finally, patience. DNS can take a bit of time to propagate throughout the internet.
All the answers above forgot one important thing in the name resolution : generally the DNS servers you request the name resolution to is not the one holding the records themselves (the authoritative server). As each DNS record comes with a Time To Live value which will oblige each DNS server in the resolution chain to do caching during the amount of seconds mentioned by this value. So not only you can cache in your machine, but CERTAINLY the result of the name lookup will be cached somewhere on a server you don't control.
The only solution to be immediately notified of a name record change is to use a TTL value of 0 when creating / updating the entry in the authoritative name server. But this means that for each name resolution, the server will be hit, usually this is not allowed by the registrars. For instance, they can provide a list of pre-defined TTL values you can choose in.
I manage different domain names and to be sure that the change are well applied in the authoritative name servers, I'm using a tool called
dnstracer
that can show the lookup result on each servers from the DNS root.In conclusion, even without any DNS caching solution in place, there will still be a delay between the moment you change the DNS records and the change is seen on a PC. This delay greatly depends on the TTL of the records and on the number of DNS servers between you PC and the authoritative name server.
I used the following command to flush the dns cache on my 12.10 ubuntu box and it worked fantastic.
Another helpful signal is the SIGUSR1 which dump a little statistic to syslog or as it is note from
man dnsmasq
: