Cannot access Google Analytics on Wi-Fi
TL;DR Check your hosts file for a filter list e.g EasyList, AdAway.
Shamefully, at time of writing this article, this site uses Google Analytics, but as its only tracker. This is temporary, however it gives me the opportunity to talk about a problem that has been bugging me for a while. I had trouble accessing https://analytics.google.com/ from my Wi-FI hotspot, but could access it at home without a problem. I finally got around to checking what’s up.
First things first, nslookup
:
1 | $ nslookup analytics.google.com |
First of all, what kind of DNS server is that? It turns out that I had been using dnsmasq, I believe for some cybersecurity class experiment involving DNS spoofing (the VM setup turned out to cause trouble so I was running things on bare metal). Quick fix from here:
1 | $ sudo nano /etc/NetworkManager/NetworkManager.conf |
And nslookup
again:
1 | $ nslookup analytics.google.com |
Well, I know that address, that’s the Android hotspot DNS server address that it delivers by DHCP. Let’s check the default gateway:
1 | $ route -nee |
Right. And sure enough, on my home connection, it looks better:
1 | $ nslookup analytics.google.com |
That DNS server is my router’s inside NAT address. So let’s try a different DNS server on the hotspot then, e.g Google’s 8.8.8.8:
1 | $ nslookup analytics.google.com 8.8.8.8 |
Aha. So the DNS server is to blame. I opened my terminal emulator on my phone and sure enough, the nslookup looks just like on my laptop, returns localhost.
So what can it be? /etc/hosts
is the first thing to check, and it is indeed littered with stuff blocked by AdAway based on EasyList. (Yes. I am a hypocrite and I block ads yet I use Google Analytics for my own site… I promise it’s temporary!)
So I headed to AdAway, used the DNS logging feature, saw the analytics.google.com
entry and added it to the whitelist from there. Rebooted my phone and it works!
Side note: Did you know that systemd falls back to DNS servers in the order of resolv.conf without recovery after the first server comes back? That’s one thing to check when debugging DNS. On that note, systemd breaks many very old UNIX practices, and that’s just one example. But it has its merits. It’s just that it aims to fit 99% of people, and the others are out of luck.