Mac OS X – Clearing DNS Cache
Once you go to a Web site, or do any DNS lookup, the IP gets cached for quite a while. This becomes a royal pain if you’re a systems administrator who is in the middle of migrating domains from one server to another. Executing clears the cache, restarts the caching daemon, and fetches fresh DNS records. And there was much rejoicing…sudo killall lookupd lookupd -flushcache
Updated November 26, 2007: Thanks to Syd, the Leopard (Mac OS X 10.5) command has changed to dscacheutil -flushcache and lookupd has been deprecated.
`lookupd -flushcache` works as well. No sudo required.
Hrm. I really should have thought of that. ;) Thanks!
*shudder*
killall scares me from my DEC Unix days. ps | grep | awk | xargs -n 1 kill, or skill if your platform supports it.
/Andrew
While “lookupd -flushcache” seems to work in most instances, I’ve discovered that it doesn’t fully flush the cache when dealing with a PPTP VPN link (and probably any PPP link for that matter). In this instance, and if a host is accessible both publically and across the private network via VPN, and if lookupd has already looked up the public address, making the VPN connection then issuing a flushcache does not successfully force lookupd to release record of the public address. As evidence of this, a ping to the target hostname continues to point to the public address until lookupd is killed (sighup). Note: this scenario assumes that during the VPN connection the default route is not pointing to the private network (hence all public traffic is routed across the public, not private link).
In this instance a killall or the like seems to be the only solution. (c’mon it’s only a killall!)
Clearing the DNS cache
Sometimes you need to flush the local DNS cache on a machine after a website moves it server. Here’s how…
look up there
For the past week or so, my Mac at work has been failing on initial DNS lookups, and then suceeding immediately afterwords. So basically, I key in a URL, wait a second for it to fail, and then hit the…
quick question…after you enter this command, lookupd -flushcache does terminal give you a “Flushed” message or a “cleared” message or something, I used this but I’m not sure if it worked. How do I check?
Nope. No output is generated since the command is meant to be silently run from scripts. If you didn’t get an error then the command worked. Just to be safe, you may want to quit and relaunch any network applications (Mail, Safari, Firefox, etc.) since they sometimes keep their own caches.
links for 2005-03-22
Math and Physics Applets (categories: physics applets) How to Do Anything Photographic © 2005 Ken Rockwell (categories: photography howto…
That’s strange, but on my computer lookupd -flushcache don’t work. Instead, I invoke interactive lookupd prompt: lookupd -d, then type the command ‘flushCache’
strange…
Help! I am not as technical as most. I am the only Mac in our environment. I cannot see our coporate domain while connected internally. From home I have no problem. Our Admin has stated that I need to flush DNS. I have done so but still cannot see the domain. Any help would be appreciated.
danbrodie@builddirect.com
Here’s what worked for me:
1. Quit and relaunch Safari.app
2. Safari > Empty Cache
3. History > Clear History
4. Quit Safari.app
5. Launch Terminal.app and type in: lookupd -flushcache
6. Quit Terminal.app
7. Launch System Preferences > Network > TCP/IP > DNS Servers
8. Enter:
4.2.2.1 (Return)
4.2.2.2
9. Configure IPv6 > Off > Click “Ok”
10. Click “Renew DHCP Lease” Button
11. Apply Now
12. Restart Mac and launch Safari.app again and give it a whirl
I hope this works for you. It’s probably too much, but it’s what fixed my problem on my Quad.
Dan from post above says that this procedure worked for him.
Edit by Sean: The above instructions seem a bit overkill just to fix a simple DNS caching issue. The IP addresses 4.2.2.1 and 4.2.2.2 are owned by Qwest Communications. Please note that using remote DNS servers may solve your lookup issue but be slower than using local DNS servers from your own company/ISP.
I’ve tried everything and can’t seem to get my site to load. I recently changed servers, but the old IP is cached. here’s the weird thing–I used Applications > Utilities > Network Utility to test traceroute, lookup, ping, etc. and I get different results for different requests. “Lookup” find the correct IP, but Ping and Traceroute find the old IP. Any ideas what’s going on? It’s driving me crazy. I also noticed that it’s only the “www.” version of my site that’s cached, leaving the “www.” off seems to work. I can go to another computer and access the site fine though. It’s only this one computer. Lame.
For Leopard (Mac OS X 10.5), lookupd is deprecated apparently. So, use this instead:
$ dscacheutil -flushcache
Thank you for posting this. It’s actually hard to find!
Thx Syd, you saved an old man a lot of headaches.
Thanks folks — I have the flakiest home connection and DNS constantly (especially for gmail) getting into a state where it would let me hit sites.
works like a charm for leopard. Thanks!
Hi, I wonder if you can help me. I’m trying to find out the names of my DNS server when I use the cat /etc/resolv.conf it says something about a LAN and gives me my IP Address. Whats that about? Cheers.
Roy,
If it says something like this:
mac:~$ cat /etc/resolv.conf
domain localnet
nameserver 192.168.1.1
Then that probably means your router is acting as a DNS relay. Try logging into the router config pages, and the DNS settings for your ISP should be there someplace…
Justin is right, the command is now
dscacheutil -flushcache
for 10.5
Thanks for this page – this solved my prob.
It worked. Great thanks.
10.5: dscacheutil -flushcache