Is there a reliable, reproducible way to clear DNS cache on Android Nougat 7.0?
I know there is at least one other question like this but that one was from 8 years ago and I hope I can ask again and see what people are doing these days.
To explain a bit more my setup:
I am testing a simple web page loading in Chrome browser with Wireshark packet capture to see the DNS requests. I am also running
dnsmasq on my LAN and have mapped my webpages name:
mymovies to the correct IP address of the machine on my LAN that the web server is on. So
http://mymovies should work and it does load.
The DNS lookups initially start with the DHCP server appending the DNS suffix (
.home) so in the packet trace I see a DNS request for
mymovies.home which fails because I don't have an IP address mapping for that in
dnsmasq.conf. So a second DNS lookup for just
mymovies appears and is successful.
Mostly I find that subsequent DNS lookups are always just for
mymovies and never again for
mymovies.home no matter what I try to clear the DNS cache:
I am testing over WiFi with a Moto G5 running Android 7.0 and it is rooted so I can run commands from within
adb shell to the OS.
I have tried lots of things like:
- Closing down Chrome browser and starting it up again.
chrome://net-internals/#dnsto clear host cache and flushing the sockets too
- Settings > Apps > Chrome > Storage > Clear Cache
ndc resolver clearnetdns wlan0
The only thing that seemed to work for me was turning the phone off and on again. After restart I opened
http://mymovies in Chrome on the phone. The page loaded and in the Wireshark trace I see the first DNS request for
mymovies.home which fails as usual followed by a DNS request for
mymovies that succeeds. I then closed down that tab and opened a new one and loaded the page again.. I did this twice. Each time now I see a dns request for
mymovies only.. it doesn't even try
dnsmasq server and the first DNS lookup after that was for
mymovies.home followed by a lookup for
mymovies. But since then the DNS lookups are now only ever for
mymovies. This is despite restarting the
dnsmasq server a few times and trying the four so-called DNS cache clearing steps listed above.
But to confuse the matters, I tried the trick of switching into and back out of Airplane Mode. Now when I load my little test web page a few times it doesn't seem to cache at all anymore? Loading the webpage always initially gives a DNS look up for
mymovies.home which fails then a lookup for
mymovies that succeeds. Even after restarting the phone the DNS lookups have now stopped caching completely and it firstly tries
mymovies.home every time!
I think this caching behavior is normal and expected but I'd just like a way to clear that cache so it goes back to trying
mymovies.home without me having to restart the phone.
I'm not sure if the IPv6 has anything to do with things? In my router I have specified the IP address of the Raspberry Pi on my LAN that
dnsmasq is running on so the router directs DNS requests to it.
I don't want the page to stop caching OR to always cache. I just want to be able to clear the DNS cache in a predictable manner so I can make the DNS request for
mymovies.home appear once followed by the expected DNS caching.