Howto clear/Flush DNS Cache in Ubuntu

Sponsored Link
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

You may also like...

30 Responses

  1. nevinka says:

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


  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


  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 and 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’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:


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

    However, “ping typho” returns with:
    PING ( 56(84) bytes of data.
    From 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” looks good, so there is a connection:

    PING ( 56(84) bytes of data.
    64 bytes from 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

    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?


  14. Brian says:

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

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

  15. Ryan says:

    @Brian: No, it doesn’t. It’s because ping uses C library functions like gethostbyname, and so follows the order directive (/etc/nsswitch.conf, /etc/hosts, locally running bind daemons, etc.). On the other hand, utilities like dig and nslookup were meant to query nameservers only and could care less about that crap, because they were meant to query nameservers only without taking any of the local superseding entries in to account. So, it is not surprising that you’re seeing different responses. To the trained eye, this is a benefit, not a hindrance, because it points out where the problem is, which in this case is your Ubuntu machine’s configuration. Installing nscd is pointless and irrelevant in this situation, and will only complicate your problems. There are more files that just resolv.conf that control the behavior you’re seeing from utilities like ping – resolv.conf, nsswitch.conf, /etc/hosts, /etc/hostname, so on and so forth. Google or read the manpages, or keep chasing ghosts. It’s up to you.

  16. takizo says:

    @Brian, it has nothing to do with DNS when you do IP ping. It’s more like your host is having problem to reach.

  17. srweb says:

    I’m having the same problem!!! TOO

  18. finally did it.
    i thought i don’t need to install nscd. thanks

    ubuntu should have it by default

  19. Delrey says:

    Since I am no expert (by far). I’m having similar issue I’m hoping someone can shed light to. I have Ubuntu 10.04 64bit installed on a Lenovo Z61T. Docked most of the time I have NO issues with networking or resolving DNS. I also have another Lenovo X200 dual boot with Windows 7 and Ubuntu 10.04LTS 64bit. My problem is with either laptop and only using Ubuntu DNS seems to fail resolving after a short of use. I can still ping thru and whe compared to Windows (unfortunately) I have no problems. Reading some other posts seems to indicate and issue with IP6. I was tempted to totally remove by following some hacks but I’m not yet convinced its a bug probably something I have overlooked or just naive to as a newbe. my instincts say try a tcp dump but thought I would post here to save more aggravation

  20. Systems says:

    Is Wrong In ubuntu Is this command sudo apt-get install nscd and After sudo /etc/init.d/nscd restart

    ubuntu10@ubuntu10-virtual-machine:/etc/init.d$ sudo apt-get install nscd
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    The following NEW packages will be installed:
    0 upgraded, 1 newly installed, 0 to remove and 188 not upgraded.
    Need to get 207kB of archives.
    After this operation, 381kB of additional disk space will be used.
    Get:1 maverick-updates/universe nscd i386 2.12.1-0ubuntu9 [207kB]
    Fetched 207kB in 0s (400kB/s)
    Selecting previously deselected package nscd.
    (Reading database … 120088 files and directories currently installed.)
    Unpacking nscd (from …/nscd_2.12.1-0ubuntu9_i386.deb) …
    Processing triggers for man-db …
    Processing triggers for ureadahead …
    Setting up nscd (2.12.1-0ubuntu9) …
    * Starting Name Service Cache Daemon nscd [ OK ]
    ubuntu10@ubuntu10-virtual-machine:/etc/init.d$ sudo /etc/init.d/nscd restart
    * Restarting Name Service Cache Daemon nscd [ OK ]

  21. kim says:

    i don’t need to install nscd. thanks

  22. Dan says:

    Why would you want to install something extra when Ubuntu already comes with it’s own DNS caching service (dns-clean)?

    The dns-clean service runs at every boot, so a simple reboot of Ubuntu cleans out your DNS anyway.

    If you don’t feel like rebooting:

    sudo /etc/init.d/dns-clean start

  23. tcpdump says:


    full ACK to Dan.

    /etc/init.d/dns-clean start will do the trick for you. if you look into the script, it calls /etc/ppp/ip-down.d/0dns-down and the last line in that script is:

    [ -x /etc/init.d/nscd ] &, which means if nscd installed it will be restarted too.

    regards tcpdump

  24. Billy LaRocque says:

    Dudes, I have been using *NIX systems since ’79 and there is no DNS cache in UNIX or LINUX (think someone mentioned it above). The only cache is in your browser, usually closing all your browser windows will reset it. Should there be an issue still, go into Preferences (on firefox) and clear the cache manually, close and then re-open firefox.
    Good Luck for those of you still struggling with installing something you don’t need on *NIX.

  25. Arash pazandi says:

    hi guys
    you must be type first
    sudo apt-get install nscd
    and after install successfully nscd Service .
    for restart type it :
    sudo /etc/init.d/nscd restart

    just do it !

  26. Juegos says:

    Great thank you as I can see, for me runs /etc/init.d/dns-clean
    I have not installed too the nscd by default. i’ll install it roght now, and test.

    Greetens and thanks!

  27. Som says:

    If a user wants to flush DNS cache and if the user uses Internet via LAN connection ,the best way to do so is changing the DNS address manually . He just needs to alter the DNS entry .Setting alternative DNS address as primary address will solve the issue instantly. This trick worked for me . I faced the same problem . I am aLinux user .so , I installed NSCD client and tried to flush the cache . But , it could not solve my issue .i solved it myself just changing the DNS entry . It worked for me instantly .I kept the new entry for two days without any problem and later reinstated the older entry

  28. Anonymous says:

    sudo apt-get install nscd

    sudo /etc/init.d/nscd restart

    Get your facts right knobhead!

  29. santosh says:

    was looking for command to clear flushdns
    your site helped me with good info


  30. Chaim says:

    For anyone looking at this fix:
    – Still works on current Ubuntu versions a/o March 2015.
    – “aptitude” in the instructions should be replaced with “apt-get” and it should work fine.

Leave a Reply

Your email address will not be published. Required fields are marked *