Q. I'm on a Dial UP Internet connection under Linux and frequent dial up problem causing dns problems. How do I flush DNS cache under any UNIX / Linux distribution using a shell prompt?
A. Under any Windows version you can use ipconfig command to flush dns cache. However, Linux (UNIX) is more complex and robust as compare to Windows. Linux can run nscd or BIND or dnsmasq as the name service caching daemon under most Linux distributions. Large and workgroup servers may use BIND / dnsmasq as a dedicated caching server.
Flush nscd dns cache
Nscd caches libc-issued requests to the Name Service. If retrieving NSS data is fairly expensive, nscd is able to speed up consecutive access to the same data dramatically and increase overall system performance. Just restart nscd:
$ sudo /etc/init.d/nscd restart
OR
# service nscd restart
Flush dnsmasq dns cache
dnsmasq is a lightweight DNS, TFTP and DHCP server. It is intended to provide coupled DNS and DHCP service to a LAN. Dnsmasq accepts DNS queries and either answers them from a small, local, cache or forwards them to a real, recursive, DNS server. This software is also installed many cheap routers to cache dns queries. Just restart to flush out dns cache:
$ sudo /etc/init.d/dnsmasq restart
Flush caching BIND server dns cache
A caching BIND server obtains information from another server (a Zone Master) in response to a host query and then saves (caches) the data locally. All you have to do is restart bind to clear its cache:
# /etc/init.d/named restart
Related: Windows Vista / XP Flush DNS Cache with ipconfig Command
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- My 10 UNIX Command Line Mistakes
- Linux: 20 Iptables Examples For New SysAdmins

- 25 PHP Security Best Practices For Sys Admins
- The Novice Guide To Buying A Linux Laptop
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
Facebook it - Tweet it - Print it -


{ 20 comments… read them below or add one }
it dont work for me i have ubunu 7.10
I my experience
service nscd restartdoes not clear NSCD’s cache.service nscd reloaddoes, however.That is correct!
Actually, in Bind, you can flush the daemon’s cache by doing
rndc flush
Thank U
This “rndc flush” help lot … restart doesn’t flush …
Have a nice day
Whoops!
It seems that not the perfect view for precise approach. It seems that if I use bind and there is a resolv.conf too not always the bind is in use. (Ubuntu) Other important machine (with debian), there is just resolv.conf. Anyhow I have tried to restart (hope works) the /etc/init.d/dns-clean and it seems it worked. But there were reports that this did not do the job. Anyhow, I want to make sure that – especially my debian system – without restarting, even the networking, how can I just restart the name resolution to the newly set values and how to get sure that it is done well?
Thanks!
If nscd is in use, try “nscd -i hosts” as root.
As per James Mills, “rndc flush” if using bind.
If none of these work you might not have a DNS cache to flush anyway and the problem DNS entry may be stored elsewhere, such as your firefox DNS cache, your router’s cache, or another upstream DNS caching server.
it could be nscd is not install?
@James, rndc reload works too :D
“/etc/init.d/dnsmasq restart” do not work, even stop and start does not. There is a clear cache option entioned, but it does not help anyway – dnsmasq remembers…
I guess this is for DNS server. What shall I do if I wish to clear DNS cache on a linux client/desktop machine? [Like ipconfig /flushdns in windows]
@Yogesh: The same commands apply to a desktop
@dejf: Bear in mind per my comment above, perhaps your desktop has a separate DNS cache or the DNS is being cached elsewhere. You have to flush the DNS on all your “upstream” DNS servers as well or change the DNS servers that you’re using.
See the following for info on how to change your DNS settings to these 2 popular public DNS servers:
http://code.google.com/speed/public-dns/
https://store.opendns.com/setup/router/
@Tricky
Thanks for comment, but I am unable to find /etc/init.d/nscd or named on my Centos 5.3 Desktop. Any help?
@Yogesh. Chances are the DNS is cached outside of your desktop or the DNS is being cached by an application directly.
I wrote an (admittedly regex-cryptic) article on this same issue (sorry for the “competing” link, Vivek) – http://dogma.swiftspirit.co.za/archives/300 – skip to the sections after the label “Flush Mozilla Firefox’s internal DNS cache”.
Hi
I have a local name resolution issues on CentOS 5.5. I have edited the /etc/hosts file and still the hostname doesn’t resolves to right IP.
Here is what I have priority configuration
# more /etc/host.conf
order hosts,bind
Also /etc/nsswitch.conf file has
hosts: files dns
more /etc/hosts
192.168.1.1 admin.domain.com admin
# host admin
Host admin not found: 3(NXDOMAIN)
Any suggestions would be appreciated.
host doesn’t bother with the entries in the hosts file. Try ping admin instead.
TY for information its working solution for clear cash from server side
Im sorry for my bad english…. but im have Debian.
apt-get install nscd Ok
-d, –debug Do not fork and display messages on the current tty
-f, –config-file=NAME Read configuration data from NAME
-g, –statistic Print current configuration statistic
-i, –invalidate=TABLE Invalidate the specified cache
-K, –shutdown Shut the server down
-t, –nthreads=NUMBER Start NUMBER threads
–usage Give a short usage message
commands restart and reload not work ! haven`t ))) and -shutdown not work
@takprosto
Do the commands give an error or are they just not refreshing the DNS? If there’s no error then the DNS entry could be cached elsewhere, for example on your router or your ISP’s DNS server.
Manish ->
Change from:
192.168.1.1 admin.domain.com admin
TO:
192.168.1.1 admin admin.domain.com admin
why not just use
nscd -i hosts
nscd -i passwd .
to flush the cache