Howto clear/Flush DNS Cache in Ubuntu
Sponsored Link
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
admin@admin-machine:~$ sudo /etc/init.d/nscd restart
[sudo] password for admin:
sudo: /etc/init.d/nscd: command not found
admin@admin-machine:~$
🙁
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
I’m having the same problem!!!
Hey guys,
Just stumbled accross the correct code to flush the DNS cache on 8.04 –
sudo /etc/init.d/networking restart
Cheers,
Richard
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…
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*
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.
For people companing about command not found problem, try “sudo bash /etc/…” (bash after sudo)
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.
For those not as technical a good old fashioned reboot seems to work just fine for me too.
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.
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!
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,
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).
@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.
@Brian, it has nothing to do with DNS when you do IP ping. It’s more like your host is having problem to reach.
I’m having the same problem!!! TOO
finally did it.
i thought i don’t need to install nscd. thanks
ubuntu should have it by default
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
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:
nscd
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 http://us.archive.ubuntu.com/ubuntu/ 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 ]
ubuntu10@ubuntu10-virtual-machine:/etc/init.d$
i don’t need to install nscd. thanks
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
Hi,
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
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.
Cheers,
Billy
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 !
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!
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
sudo apt-get install nscd
sudo /etc/init.d/nscd restart
Get your facts right knobhead!
was looking for command to clear flushdns
your site helped me with good info
thx
—————————————
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.