java.net.UnknownHostException
Java couldn't resolve the hostname
Seen in Java, Android, Spring, Maven, Gradle, Kafka clients
DNS lookup for the hostname failed, so Java never opened a connection.
Common causes
- A typo in the hostname or a URL passed where a host was expected.
- The record does not exist, or only resolves inside a VPN or private network.
- No working DNS in the container, emulator or device.
- A negative lookup cached by the JVM (networkaddress.cache.negative.ttl).
How to fix it
- Check the exact hostname in the exception message.
- Look up the name from the same machine (getent hosts or nslookup).
- Check the container, VPN or device DNS settings.
- Restart the JVM after fixing DNS if the failure was cached.
Got a different message? Paste it into the error explainer.
Related errors
- socket.gaierror: [Errno -2] Name or service not known · Python couldn't resolve the hostname
- socket.gaierror: [Errno -3] Temporary failure in name resolution · Python couldn't reach a DNS resolver
- dial tcp: lookup example.com: no such host · Go couldn't resolve the hostname
- No such host is known · Windows couldn't resolve the hostname
- php_network_getaddresses: getaddrinfo failed · PHP couldn't resolve the hostname
- [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed · Python couldn't verify the server's certificate
- certificate verify failed: Hostname mismatch, certificate is not valid for · The certificate doesn't cover this hostname
- Max retries exceeded with url · requests gave up connecting to the URL
- requests.exceptions.ConnectTimeout · Python couldn't open the connection in time
- requests.exceptions.ReadTimeout · The server took too long to respond
- ConnectionRefusedError: [Errno 111] Connection refused · Nothing is listening on that port
- http.client.RemoteDisconnected: Remote end closed connection without response · The server closed the connection without replying