Inert Ramblings

Mac OS X – Clearing DNS Cache

Posted in Gnus by Sciri on May 11, 2004

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 sudo killall lookupd lookupd -flushcache clears the cache, restarts the caching daemon, and fetches fresh DNS records. And there was much rejoicing…

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.

22 Responses

Subscribe to comments with RSS.

  1. rentzsch said, on May 11, 2004 at 8:23 pm

    `lookupd -flushcache` works as well. No sudo required.

  2. Sean said, on May 11, 2004 at 11:02 pm

    Hrm. I really should have thought of that. ;) Thanks!

  3. Andrew said, on May 13, 2004 at 6:44 pm

    *shudder*

    killall scares me from my DEC Unix days. ps | grep | awk | xargs -n 1 kill, or skill if your platform supports it.

    /Andrew

  4. Lazer said, on July 29, 2004 at 1:05 am

    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!)

  5. ONE/Northwest KnowledgeBase said, on September 24, 2004 at 2:26 pm

    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…

  6. takecover! said, on November 15, 2004 at 11:24 am

    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…

  7. ramz said, on February 1, 2005 at 11:47 pm

    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?

  8. Sean said, on February 2, 2005 at 10:48 am

    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.

  9. The Room said, on March 22, 2005 at 11:22 am

    links for 2005-03-22

    Math and Physics Applets (categories: physics applets) How to Do Anything Photographic © 2005 Ken Rockwell (categories: photography howto…

  10. stan said, on February 16, 2006 at 7:47 am

    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…

  11. Dan said, on June 20, 2006 at 3:52 pm

    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

  12. Matt said, on July 18, 2006 at 5:42 pm

    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.

  13. Justin said, on August 1, 2006 at 11:44 pm

    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.

  14. Syd said, on November 16, 2007 at 2:14 am

    For Leopard (Mac OS X 10.5), lookupd is deprecated apparently. So, use this instead:

    $ dscacheutil -flushcache

    • grateful! said, on May 16, 2009 at 9:01 pm

      Thank you for posting this. It’s actually hard to find!

  15. Slab said, on November 23, 2007 at 4:28 am

    Thx Syd, you saved an old man a lot of headaches.

  16. David Janes said, on January 2, 2008 at 5:48 am

    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.

  17. roger pack said, on January 4, 2008 at 3:38 pm

    works like a charm for leopard. Thanks!

  18. Roy said, on January 5, 2008 at 7:03 pm

    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.

  19. Gary said, on January 24, 2008 at 8:37 am

    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…

  20. g_face said, on February 29, 2008 at 3:39 pm

    Justin is right, the command is now
    dscacheutil -flushcache
    for 10.5

    Thanks for this page – this solved my prob.

  21. Muthu said, on April 14, 2008 at 9:26 pm

    It worked. Great thanks.

    10.5: dscacheutil -flushcache


Leave a Reply