January 10, 2008 · General, Server · Email This Post
Share

If you're new here, you may want to subscribe to my RSS feed and if you have questions related to your ubuntu system post question to our forums. Thanks for visiting!

Some distributions run a caching nameserver in the background out of the box while some do not. To clear the cache if you have such a daemon running, simply restart the nscd service in ubuntu.

Why would you clear your cache?

Most DNS clients will cache the results of name resolution request to speed up multiple lookups to the same URL. Just think about how many requests are made to the same domain when visiting a single web page. Every file, image, style sheet, etc. that is on that page and served from the same domain requires a DNS lookup.

So if you have an invalid DNS entry cached on your local client you’ll need to flush it out of the cache so your client can do a new lookup and get the correct information. Or your other option is to wait until that DNS entry expires and the cache flushes it automatically… which typically takes about 24 hours.

In ubuntu if you want to flush DNS cache you need to restart nscd daemon

Install nscd using the following command

sudo aptitude install nscd

Flush DNS Cache in Ubuntu Using the following command

sudo /etc/init.d/nscd restart

  • Share/Bookmark

Related Articles

14 Comments to “Howto clear/Flush DNS Cache in Ubuntu”

  1. nevinka says:

    admin@admin-machine:~$ sudo /etc/init.d/nscd restart
    [sudo] password for admin:
    sudo: /etc/init.d/nscd: command not found
    admin@admin-machine:~$

    :(

  2. Melvin van den Berg says:

    My Ubuntu Hardy Heron 8.04 gave the same error as stated by Nevinka.

    hammerhead@HammerHead:~$ sudo /etc/init.d/nscd restart
    [sudo] password for hammerhead:
    sudo: /etc/init.d/nscd: command not found

  3. cruff says:

    I’m having the same problem!!!

  4. Richard says:

    Hey guys,

    Just stumbled accross the correct code to flush the DNS cache on 8.04 -

    sudo /etc/init.d/networking restart

    Cheers,
    Richard

  5. Re Quired says:

    Guys, read the text you post to…
    ----------------8 Install nscd using the following command 8-------------------
    You can not find the command when it is not installed of course…

  6. Hackel says:

    Ugh, I’m so tired of seeing people posting technical advice that is just plain wrong! Why does it seem like it is always Ubuntu users? Has Ubuntu just brought over so many pathetic former MCSE’s that don’t understand the way an operating system works but are full of themselves and so feel the need to post things like this? I really don’t understand this.

    In any case, nscd is NOT installed by default in Ubuntu. It makes absolutely no sense to install it, only to be able to reset it. If it is not installed, then DNS is not cached directly by libc. Firefox, for example, maintains its own DNS cache, and the only way to clear it is to restart the browser. The OS does not cache DNS unless you install nscd manually, as this article advocates. It’s just common sense here, people… *sigh*

  7. Gerry says:

    Totally agree with Hackel. Also “sudo aptitude install nscd” requires your DNS to be working, which is pointless if you’re needing to flush the cache because you’ve just switched over to a working dns. You have to have a working dns before you can flush the dns that isn’t working… hmmm that’s logical.

    Under Ubuntu I was able to get the new dns entry working by reselecting my network connection.

  8. thomas says:

    For people companing about command not found problem, try “sudo bash /etc/…” (bash after sudo)

  9. tehhi5 says:

    How to flush the DNS Resolver Cache if temporary problems are preventing accessing a

    particular website. Windows XP caches DNS entries (these change human-readable names such

    as malektips.com and google.com into IP addresses that allow communication over the

    Internet). This way instead of having to access a remote DNS server every time you

    re-access the same web address, Windows can use the cached entry to speed communication.

  10. Flush DNS says:

    For those not as technical a good old fashioned reboot seems to work just fine for me too.

  11. Jan says:

    I just had a similar problem… dns updated, but nslookup or ping gave the old address.
    Turns out that it was my own DNS server that was lacking updates! I switched my /etc/resolv.conf to use opendns.org’s servers and the updates came through immediately!
    nothing to flush on a ubuntu or other linux system unless you specifically install software to cache dns queries, like nscd.
    If you are brave enough to “restart” your network on a live server, good luck to you! “/etc/init.d/networking restart” will stop all networking for a split second on all connected network cards. If you’re running services that other people depend on, not such a good idea.

  12. alex dekker says:

    thomas, if the command isn’t found, that’s because NSCD isn’t installed. If NSCD isn’t installed, then there’s no cache to flush!

  13. Brian says:

    I’ve got a similar problem…

    The program ‘nscd’ is currently not installed.

    “typho” is a computer on my network. “nslookup typho” returns:

    Name: typho.example.com
    Address: 192.168.0.64

    This is correct (verified by walking over to typho and typing “ipconfig”). Yes, it is a WinXP machine.

    However, “ping typho” returns with:
    PING 192.168.0.65 (192.168.0.65) 56(84) bytes of data.
    From 192.168.139.67 icmp_seq=1 Destination Host Unreachable

    My IP address is 67, but typho is 64, *not* 65. A few *weeks* ago it *was* 65, but I changed it on my DNS server.

    In fact, every application I’ve tried (except nslookup) is resolving typho to 65, including Nautilus (smb://typho/share), ftp, and others.

    “ping 192.168.0.64″ looks good, so there is a connection:

    PING 192.168.0.64 (192.168.0.64) 56(84) bytes of data.
    64 bytes from 192.168.0.64: icmp_seq=1 ttl=128 time=0.976 ms

    Rebooting does not solve this. There is clearly a dns cache somewhere, and it is not being updated with the correct information. Other Ubuntu machines on my network can “ping typho” correctly (they automatically resolve the correct address).

    My /etc/resolv.conf is simply:
    # Generated by NetworkManager
    domain example.com
    search example.com
    nameserver 192.168.0.40

    That is correct. My nameserver is located at 40.

    Other Ubuntu machines on my network have the same resolv.conf.

    What’s going on here? Where is the cache, and how do I flush it?

    Thanks,

  14. Brian says:

    Sorry, that ping response should have read:
    From 192.168.0.67 icmp_seq=1 Destination Host Unreachable

    (While changing the addresses and names to protect the innocent, I missed a line).

Leave a Reply