Take the 2-minute tour ×
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

4 Answers 4

up vote 9 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

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
Looks like the forced 10-minute caching is fixed in JB — see this commit. For older releases the Java cache behavior could be tuned by networkaddress.cache.ttl and networkaddress.cache.negative.ttl in build.prop. –  Sergey Vlasov Jun 2 '13 at 18:19
Fwiw, there are still some (perhaps different) DNS issues even in 4.3 - tablets on wifi may not get an IP address for names that Linux and Windows machines (on the network that hosts the wifi) can resolve. –  Jon Shemitz Feb 25 '14 at 21:50

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

There're also apps like Internet Booster promising to "clear DNS cache" (amongst other things). I didn't try it out myself, and furthermore there seems no way to do only that (just one "optimize" button which "applies improvements"); also its effects might differ between devices (says the app's description) -- but it might be better than a reboot. Btw: while not mentioning root as requirement, it might still be needed.

There are several "similar apps" listed on Google Play -- but be aware that most of them include Airpush ads and/or want excessive permissions, which is why I didn't name them here.

Another possible solution (not tested by myself) I found at MadPC, seemingly quoting user8522's answer before stating:

The last option but most intensive on the user themselves unless they want to just wait the update out: Have your users go into settings -> applications -> Network Location -> Clear data

Another short howto mentions a different easy way to flush DNS (again, I didn't test this myself): Simply switch to airplane mode (oops, no network?) and back (ah, there it is) should do the trick. Might sound stupid, but I could imagine when entering airplane mode Android does something similar to /etc/init.d/networking stop, which has a DNS flush as side-effect.

A very easy solution was supplied by dtumaykin in the comments below: simply switching to airplane-mode and back might already do it (of course with the side-effect of the network going down for a couple of seconds ;) Though it might not work on some devices, it's worth a try: no extra installs, and easily performed even by n00bs.

If anybody tried one of those solutions, confirmation (or the opposite) is surely welcome :)

share|improve this answer
There are shell commands ndc resolver flushdefaultif and ndc resolver flushif wlan0; they require root. There is also NetworkManagementService.flushDefaultDnsCache() method, which required just CHANGE_NETWORK_STATE before JB, but then was locked down to CONNECTIVITY_INTERNAL. So there apparently was a hackish way to clean DNS cache without root (after build.prop tuning to kill the Java-level cache), but it will not work in JB. –  Sergey Vlasov Jun 2 '13 at 19:20
Thanks for the additional information, @SergeyVlasov ! Do you know if any of the methods you mentioned gets triggered by the two proposed solutions mentioned last in my answer (or if they do work, but for a different reason)? –  Izzy Jun 2 '13 at 19:37
Airplane mode on-off worked out for me. Samsung Galaxy S4 Mini and CM12.1. –  dtumaykin Jul 4 at 12:45

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

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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