-
TutorialsBASH ShellTroubleshootingNginxNetworkingMySQLGoogle
Cloud PlatformAmazon Cloud ComputingRackspace Cloud
ComputingLinux
CentOSDebian / UbuntuUbuntu LinuxSuseRedHat and FriendsSlackware
Linux
UNIXAIXMac OS XFreeBSDFreeBSD Jails (VPS)OpenbsdSolaris
See all tutorial topicsBlogAboutContact usForumLinux Scripting
GuideRSS/FEED
Linux FAQ / Howtos
How To Flush Linux / UNIX DNS Cacheby Nix Craft on January 29,
2008 29 comments LAST UPDATED June 2, 2012
in BASH Shell, CentOS, Debian / Ubuntu
I'm on a Dial UP Internet connection under Linux and frequent
dial up disconnectioncausing dns problems. How do I flush DNS cache
under UNIX / Linux distributionusing a shell prompt?
Under MS-Windows you can use the ipconfig command to flush dns
cache.However, Linux and UNIX provides various ways to flush cache.
Linux can run nscdor BIND or dnsmasq as the name service caching
daemon. Large and work-groupservers may use BIND or dnsmasq as a
dedicated caching server to speed up queries.
HowTo: Flush nscd dns cache
How To Flush Linux / UNIX DNS Cache
http://www.cyberciti.biz/faq/rhel-debian-ubuntu-flush-clear-dns-cache/
1 of 13 5/22/2014 11:15 AM
-
Nscd caches libc-issued requests to the Name Service. If
retrieving NSS data is fairly expensive, nscd isable to speed up
consecutive access to the same data dramatically and increase
overall systemperformance. Just restart nscd:$ sudo
/etc/init.d/nscd restartOR# service nscd restartOR# service nscd
reloadThis daemon provides a cache for the most common name service
requests. The default configuration file,/etc/nscd.conf, determines
the behavior of the cache daemon.
Flush dnsmasq dns cachednsmasq is a lightweight DNS, TFTP and
DHCP server. It is intended to provide coupled DNS andDHCP 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 cheaprouters to cache
dns queries. Just restart the dnsmasq service to flush out dns
cache:$ sudo /etc/init.d/dnsmasq restartOR# service dnsmasq
restart
Flush caching BIND server dns cacheA caching BIND server obtains
information from another server (a Zone Master) in response to a
hostquery and then saves (caches) the data locally. All you have to
do is restart bind to clear its cache:# /etc/init.d/named
restartYou can also use rndc command as follows flush out all
cache:# rndc restartOR# rndc execBIND v9.3.0 and above will support
flushing all of the records attached to a particular domain name
withrndc flushname command. In this example flush all records
releated to cyberciti.biz domain:# rndc flushname cyberciti.bizIt
is also possible to flush out BIND views. For example, lan and wan
views can be flushed using thefollowing command:# rndc flush lan#
rndc flush wan
A note about Mac OS X Unix usersType the following command as
root user:# dscacheutil -flushcacheOR$ sudo dscacheutil
-flushcacheIf you are using OS X 10.5 or earlier try the following
command:lookupd -flushcache
A note about /etc/hosts file
How To Flush Linux / UNIX DNS Cache
http://www.cyberciti.biz/faq/rhel-debian-ubuntu-flush-clear-dns-cache/
2 of 13 5/22/2014 11:15 AM
-
/etc/hosts act as the static table lookup for hostnames. You
need to remove and/or update records as peryour requirements under
Unix like operating systems:# vi /etc/hostsSample outputs:
127.0.0.1 localhost127.0.1.1 wks01.WAG160N wks01# The following
lines are desirable for IPv6 capable hosts::1 ip6-localhost
ip6-loopbackfe00::0 ip6-localnetff00::0 ip6-mcastprefixff02::1
ip6-allnodesff02::2 ip6-allrouters10.37.34.2 build192.168.1.10
nas01192.168.1.11 nas02192.168.1.12 nas03#192.168.2.50
nfs2.nixcraft.net.in nfs2#192.168.2.51 nfs1.nixcraft.net.in
nfs1172.168.232.50 nfs1.nixcraft.net.in nfs1172.168.232.51
nfs2.nixcraft.net.in nfs2192.168.1.101 vm01
See also:
Related: Windows Vista / XP Flush DNS Cache with ipconfig
Command
TwitterFacebookGoogle+PDF versionFound an error/typo on this
page? Help us!Featured Articles:
30 Cool Open Source Software I Discovered in 2013 30 Handy Bash
Shell Aliases For Linux / Unix / Mac OS XTop 30 Nmap Command
Examples For Sys/Network Admins25 PHP Security Best Practices For
Sys Admins20 Linux System Monitoring Tools Every SysAdmin Should
Know20 Linux Server Hardening Security TipsLinux: 20 Iptables
Examples For New SysAdminsTop 20 OpenSSH Server Best Security
PracticesTop 20 Nginx WebServer Best Security Practices20 Examples:
Make Sure Unix / Linux Configuration Files Are Free From Syntax
Errors15 Greatest Open Source Terminal Applications Of 2012My 10
UNIX Command Line MistakesTop 10 Open Source Web-Based Project
Management SoftwareTop 5 Email Client For Linux, Mac OS X, and
Windows UsersThe Novice Guide To Buying A Linux Laptop
{ 29 comments read them below or add one }
1 NoPremium.org April 18, 2008 at 8:32 am
it dont work for me i have ubunu 7.10
Reply
2 kazoolist July 10, 2008 at 10:54 pm
How To Flush Linux / UNIX DNS Cache
http://www.cyberciti.biz/faq/rhel-debian-ubuntu-flush-clear-dns-cache/
3 of 13 5/22/2014 11:15 AM
-
I my experience service nscd restart does not clear NSCDs cache.
service nscd reloaddoes, however.
Reply
3 Subhash July 27, 2010 at 5:26 pm
That is correct!
Reply
4 James Mills September 19, 2008 at 8:32 am
Actually, in Bind, you can flush the daemons cache by doing
rndc flush
Reply
5 Lost Eagle January 31, 2011 at 4:01 pm
Thank U
This rndc flush help lot restart doesnt flush
Have a nice day
Reply
6 RudyD February 4, 2009 at 12:35 pm
Whoops!
It seems that not the perfect view for precise approach. It
seems that if I use bind and there is aresolv.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 itseems it worked. But
there were reports that this did not do the job. Anyhow, I want to
make surethat especially my debian system without restarting, even
the networking, how can I just restartthe name resolution to the
newly set values and how to get sure that it is done well?
Thanks!
Reply
7 Tricky April 26, 2009 at 11:50 pm
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 entrymay be stored elsewhere, such as
your firefox DNS cache, your routers cache, or another upstreamDNS
caching server.
Reply
How To Flush Linux / UNIX DNS Cache
http://www.cyberciti.biz/faq/rhel-debian-ubuntu-flush-clear-dns-cache/
4 of 13 5/22/2014 11:15 AM
-
8 takizo July 26, 2010 at 2:58 pm
it could be nscd is not install?
@James, rndc reload works too :D
Reply
9 dejf August 31, 2010 at 3:04 pm/etc/init.d/dnsmasq restart do
not work, even stop and start does not. There is a clear cache
optionentioned, but it does not help anyway dnsmasq remembers
Reply
10 Yogesh September 2, 2010 at 12:08 pm
I guess this is for DNS server. What shall I do if I wish to
clear DNS cache on a linux client/desktopmachine? [Like ipconfig
/flushdns in windows]
Reply
11 Tricky September 2, 2010 at 2:14 pm
@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 theDNS is being cached elsewhere. You
have to flush the DNS on all your upstream DNS servers aswell or
change the DNS servers that youre using.See the following for info
on how to change your DNS settings to these 2 popular public
DNSservers:
http://code.google.com/speed/public-dns/https://store.opendns.com/setup/router/
Reply
12 Yogesh September 2, 2010 at 3:32 pm
@TrickyThanks for comment, but I am unable to find
/etc/init.d/nscd or named on my Centos 5.3 Desktop.Any help?
Reply
13 Tricky September 3, 2010 at 4:48 am
@Yogesh. Chances are the DNS is cached outside of your desktop
or the DNS is being cached byan 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 FlushMozilla Firefoxs internal DNS cache.
Reply
How To Flush Linux / UNIX DNS Cache
http://www.cyberciti.biz/faq/rhel-debian-ubuntu-flush-clear-dns-cache/
5 of 13 5/22/2014 11:15 AM
-
14 Manish December 4, 2010 at 6:49 pm
Hi
I have a local name resolution issues on CentOS 5.5. I have
edited the /etc/hosts file and still thehostname doesnt resolves to
right IP.
Here is what I have priority configuration# more
/etc/host.conforder hosts,bindAlso /etc/nsswitch.conf file has
hosts: files dnsmore /etc/hosts192.168.1.1 admin.domain.com
admin
# host adminHost admin not found: 3(NXDOMAIN)
Any suggestions would be appreciated.
Reply
15 Tricky December 6, 2010 at 3:49 am
host doesnt bother with the entries in the hosts file. Try ping
admin instead.
Reply
16 nobbiecentos February 8, 2011 at 1:15 pm
TY for information its working solution for clear cash from
server side
Reply
17 takprosto April 9, 2011 at 11:45 pm
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 threadsusage Give a short usage
message
commands restart and reload not work ! haven`t ))) and -shutdown
not work
Reply
18 Tricky April 10, 2011 at 11:58 am
@takprostoDo the commands give an error or are they just not
refreshing the DNS? If theres no error then the
How To Flush Linux / UNIX DNS Cache
http://www.cyberciti.biz/faq/rhel-debian-ubuntu-flush-clear-dns-cache/
6 of 13 5/22/2014 11:15 AM
-
DNS entry could be cached elsewhere, for example on your router
or your ISPs DNS server.
Reply
19 andre July 22, 2011 at 7:18 am
on Debian Squeeze/wheezy:
Usage: /etc/init.d/nscd
{start|stop|force-reload|restart|status}Reply
20 m4h September 15, 2011 at 8:10 am
Manish ->
Change from:192.168.1.1 admin.domain.com adminTO:192.168.1.1
admin admin.domain.com admin
Reply
21 david.chen February 3, 2012 at 2:45 am
why not just usenscd -i hostsnscd -i passwd .to flush the
cache
Reply
22 Tim March 21, 2012 at 1:23 pm
The articles recomendations are distribution specific and depend
on how the init scripts are set upand what they do. The proper way
to flush the cache on nscd is nscd -i hosts and for named,rndc
flush
Anything else, like /etc/init.d/nscd reload depends on how your
distro wrote the init script. Justbecause that works for you on
Fedora does not mean Debian or someone else set it up that way
aswell.
Reply
23 Som June 13, 2012 at 8:44 pm
If a user wants to flush DNS cache and if the user uses Internet
via LAN connection ,the best wayto do so is changing the DNS
address manually . He just needs to alter the DNS entry
.Settingalternative 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
thecache . But , it could not solve my issue .i solved it myself
just changing the DNS entry . It workedfor me instantly .I kept the
new entry for two days without any problem and later reinstated
theolder entry
Reply
How To Flush Linux / UNIX DNS Cache
http://www.cyberciti.biz/faq/rhel-debian-ubuntu-flush-clear-dns-cache/
7 of 13 5/22/2014 11:15 AM
-
24 nick September 6, 2012 at 9:57 pm
This post is a little misleading. Linux by default does not have
a caching system (at least not mostof the destributions). So unless
you installed a caching system (or your system came with
onepre-installed), there is no need to flush DNS because your
system doesnt store any.
This post isnt clear about that and will cause people (who have
no caching in place) to install acaching package (like nscd) just
so that they could flush it. Thats a little counterproductive I
think.Reply
25 Mac January 11, 2013 at 3:20 pm
*NOTE* The mistake I have often made is my /etc/hosts (on my
CentOS6 workstation) I alwaysFORGET to update it.
So after a DNS update, I cannot reach the site by name and think
something is amiss, well I forgotto edit my /etc/hosts file for all
of the servers.
Reply
26 Willian Braga da Silva February 1, 2013 at 1:44 pm
The correct way to flush NSCD cache is using the command
line:
sudo /usr/sbin/nscd invalidate=hosts
from the man page:
$ /usr/sbin/nscd helpUsage: nscd [OPTION...]Name Service Cache
Daemon.
-d, debug Do not fork and display messages on the currenttty-f,
config-file=NAME Read configuration data from NAME-g, statistic
Print current configuration statistics-i, invalidate=TABLE
Invalidate the specified cache-K, shutdown Shut the server down-t,
nthreads=NUMBER Start NUMBER threads-?, help Give this help
listusage Give a short usage message-V, version Print program
version
-
$ sudo /usr/sbin/nscd -gnscd configuration:()hosts cache:
yes cache is enabledyes cache is persistentyes cache is
shared()
How To Flush Linux / UNIX DNS Cache
http://www.cyberciti.biz/faq/rhel-debian-ubuntu-flush-clear-dns-cache/
8 of 13 5/22/2014 11:15 AM
-
yes check /etc/hosts for changes
hope this help
Reply
27 Jesin June 28, 2013 at 8:29 am
Does restarting the networking service clear the cache ?
I do not find all Linux distributions having the one of the
three tools youve mentioned above.
Reply
28 Mac November 16, 2013 at 2:02 pm
-> nscd is there any reason why you would use this service,
just wanting to help understand what itdoes?
thanks
Reply
29 samuel March 26, 2014 at 7:03 am
I suggest changing this post about flush dns cache since its not
correct to reload or restart nscd.
I read the man and found the correct way is use:
nscd -i hosts
This method was mentioned in several comments, but if your post
were not updated, more andmore users would be misguided.
Reply
Leave a Comment
Name *
E-mail *
Notify me of followup comments via e-mail
Tagged as: /etc/init.d/dnsmasq, /etc/init.d/named,
/etc/init.d/nscd, clear dns cache in linux, clear dns cacheon
linux, clearn dns cache, dns queries, dnsmasq, flush dns cache in
linux, flush dns cache on linux, flush
How To Flush Linux / UNIX DNS Cache
http://www.cyberciti.biz/faq/rhel-debian-ubuntu-flush-clear-dns-cache/
9 of 13 5/22/2014 11:15 AM
-
linux dns cache, how to clear cache, linux clear dns cache,
linux flush dns cache, named, nscd, redhatflush dns cache
Previous Faq: Fingerprint / Identify Remote Web Server
Next Faq: Debian / Ubuntu Linux WARNING: The following packages
cannot be authenticated! Errorand Solution
Related Faqs
How To Set Caching DNS Server
Bash Clear DNS Cache
BIND: Stop Recursion DNS Under Linux / UNIX
How To Flush Linux / UNIX DNS Cache
http://www.cyberciti.biz/faq/rhel-debian-ubuntu-flush-clear-dns-cache/
10 of 13 5/22/2014 11:15 AM
-
dnstop: Monitor BIND DNS Server (DNS Network Traffic) From
aShell Prompt
Monit: Monitor BIND 9 (named) Name Server and Auto Restart SSHIf
It Does Not Respond
Linux: Start / Stop / Restart BIND DNS Server
Linux / UNIX: DNS Lookup Command
Find Out If My DNS Server Free From DNS Cache Poisoning Bug
OrNot
How to Set Up DNS Lookup in Linux
How To Flush Linux / UNIX DNS Cache
http://www.cyberciti.biz/faq/rhel-debian-ubuntu-flush-clear-dns-cache/
11 of 13 5/22/2014 11:15 AM
-
Mail delivery: DNS: Service unavailable error
nixCraft
44,587 people like nixCraft.
Facebook social plugin
LikeLike
Latest posts from our blog
Download of the day: Ubuntu Linux 14.04 LTS CD / DVD ISOLinux
and Unix nload App: Monitor Network Traffic and Bandwidth Usage In
Real Time10 Linux/Unix Bash and KSH Shell Job Control
ExamplesDownload of The Day: FreeBSD 10 ISO DVD / CD Images30 Cool
Open Source Software I Discovered in 2013
How To Flush Linux / UNIX DNS Cache
http://www.cyberciti.biz/faq/rhel-debian-ubuntu-flush-clear-dns-cache/
12 of 13 5/22/2014 11:15 AM
-
Interview with Linus Torvalds the legendary inventor of #Linux
and founder of the Open Source crusade
huffingtonpost.com/billrobinson/t
nixCraft Linux Blog @nixcraft
Show Summary
Been there, done that. #life #humour #LifeIsLikeThat #sysadmin
pic.twitter.com/Gr82hdHIIy
nixCraft Linux Blog @nixcraft
21 May
21 May
Tweets Follow
Tweet to @nixcraft
Subscribe to nixCraft
Learn something new about Linux/Unix by email
Enter your email address:
2000-2014 nixCraft. All rights reserved. Privacy Policy - Terms
of Service - Questions or Comments -We are proudly powered by Linux
+ Nginx + WordPress.The content is copyrighted to nixCraft and may
not be reproduced on other websites.
How To Flush Linux / UNIX DNS Cache
http://www.cyberciti.biz/faq/rhel-debian-ubuntu-flush-clear-dns-cache/
13 of 13 5/22/2014 11:15 AM