Tell me more ×
Android Enthusiasts Stack Exchange is a question and answer site for enthusiasts and power users of the Android operating system. It's 100% free, no registration required.

How can I clear my DNS cache on my android phone? (Droid3, Gingerbread, rooted to be specific)

Ideally I'm looking for a command to run through a terminal emulator, something similar to

ipconfig /flushdns

On a windows machine.

What's the Linux version of this?

share|improve this question
Do you need to do this for a system app, third party app or your app? – onik Sep 1 '11 at 4:02
Third party I guess? I need it for when I ping a server via Terminal Emulator. – Steve Robbins Sep 1 '11 at 4:30

3 Answers

up vote 4 down vote accepted

On a typical Linux system the cache is cleared by running /etc/init.d/nscd restart, but at least my ROM doesn't use nscd to cache DNS. You can check if yours does, but I doubt it. I've seen suggestions that clearing the brower cache would clear DNS cache too, but one sure way is to do a hard reboot (shutdown, remove battery for 30s, reattach battery and boot).

share|improve this answer
All of my googling also brings up the "hard reboot" suggestion. – Chahk Sep 1 '11 at 14:03

The only way to do this in Android is to do a hard reboot. The necessary command-line tools are not normally available, however in my tests a hard reboot has always done the trick for me (Galaxy Nexus, and HTC Desire, various ROMs).

This is a pain, but it is quicker than the 10min cache timeout.

share|improve this answer
How does one perform this? – Steve Robbins Nov 29 '11 at 5:20
- Hold down the power button - Choose "Power off" - Allow phone to fully shut down - Remove battery and wait 30s - Return battery - Power phone back on. In my experience removing the battery is not necessary, but some have reported it doesn't work if you miss this step. – Martin Nov 29 '11 at 8:27

Addresses are cached for 600 seconds (10 minutes) by default. Failed lookups are cached for 10 seconds. From everything I've seen, there's nothing built in to flush the cache. This is apparently a reported bug in Android because of the way it stores DNS cache. Clearing the browser cache doesn't touch the DNS, the "hard reset" clears it because it simply times out.

Can we ask the underlying reason for needing to clear the DNS cache? Perhaps there's another solution that's missed because we're not looking at the bigger picture.

share|improve this answer
Not sure about the OP, but I have a use case where my home network serves addresses like server.home.mydomain.com, but my ISP resolves *.mydomain.com (for any value of "*" this is not already mapped) to www.mydomain.com if my phone is on 3G/4G, so I'm sometimes unable to access my home network until the cache times out. – TomG Aug 25 '12 at 1:25

protected by Matthew Read Nov 29 '11 at 18:44

This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.

Not the answer you're looking for? Browse other questions tagged or ask your own question.