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

If you're new here, you may want to subscribe to my RSS feed. 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/Save/Bookmark

Related Articles

8 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)

Leave a Reply