30

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?

GAThrawn
  • 22,094
  • 9
  • 79
  • 127
Steve Robbins
  • 752
  • 2
  • 7
  • 16

7 Answers7

15

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.

user8522
  • 209
  • 2
  • 3
11

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

aleksikallio
  • 16,330
  • 6
  • 49
  • 73
7

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.

Martin
  • 989
  • 8
  • 16
6

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

Izzy
  • 91,536
  • 76
  • 351
  • 968
2

In modern versions of Android there is an option to clear Chrome's DNS cache under chrome://net-internals/#dns

Joao Costa
  • 121
  • 2
1

In my case, I just had one domain name that I needed flushed. Suggestions such as toggling Airplane Mode, performing a hard reboot, or the actions in chrome://net-internals/#dns did not work for me. Instead I temporarily changed my WiFi settings to use Google's nameserver at 8.8.8.8.

These are the steps I took:

  • Settings -> WiFi -> tap current connection and note the current IP address
  • Long click current connection -> Modify network
  • Check "Advanced settings"
  • Change "IP settings" to "static"
  • Set "IP address" to the current IP from the first step
  • Set "Gateway" to your IP address but with .1 as the 4th number (This is just a guess. If you know it is something different, use that)
  • Set "DNS 1" to 8.8.8.8

After these steps, when I pinged the domain name in the console it resolved to the correct IP address and seemed to write over the old cached one. Presumably visiting the domain in a browser will have the same effect.

When I went back to WiFi and set "IP settings" back to "DHCP", the correct domain continued to resolve to the current IP address.

This is on a Sony Xperia Z3 running Android 5.1.1

pix
  • 111
  • 1
0

On a Adroid 5.1 Mobile which has took wrong DNS as is switched to much between two WLAN;( A question Mark on a WLAN Connexion. i did not want to restore my phone as i did it once.. Engelsiz: DNS Changer fixed it;)