javaandroidinetaddress

InetAddress.getByName returns "akamaitechnologies.com for non-existent host


I have found that resolution of a hostname that does NOT exist always returns an address belonging to "akamaitechnologies.com" (e.g. 23.221.222.250). It does work correctly for hosts that do exist.

Code:

InetAddress addr = InetAddress.getByName( "NON-EXISTING.com" );

The documentation for InetAddress or a Google search provide little help. It is claimed that an UnknownHostException should occur but that does not happen for me.

Why is this happening?


Solution

  • This is not an Android/Java defect. It turns out it was a DNS issue. Namely, my AT&T phone uses AT&T's default DNS server (sbcglobal.net). This P.O.S. server returns a valid IP address even for non-existent domains. After I changed to "dns.google" (8.8.8.8), everything worked as expected.

    This DNS spoofing is a Bad Thing because many apps depened on a Unknown-Host-Exception to detect an incorrectly entered domain, e.g. in an email address.