Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Networking code sometimes throws UnknownHostException

I am trying to data from a server. Sometimes my code fails due to an UnknownHostException. Why is that? What is the cause of this problem?

like image 220
TCM Avatar asked May 25 '10 17:05

TCM


People also ask

What can cause UnknownHostException?

UnknownHostException is a common error message in Java applications. This error typically indicates that there was a DNS resolution failure. If a Java application fails to get a valid DNS answer, then it might throw an UnknownHostException error.

How do you handle UnknownHostException?

The UnknownHostException can be avoided with the following checks: Valid hostname - The hostname should be double checked to make sure it does not contain any typos or whitespaces. DNS settings - The system DNS settings should be checked to ensure that the DNS server is reachable.

How do I resolve unknown host exception in spring boot?

A few tips to prevent the exception are: Double-check the hostname: Make sure there is no typo, and trim all whitespaces. Check the system's DNS settings: Make sure the DNS server is up and reachable, and if the hostname is new, wait for the DNS server to catch up.


2 Answers

This may occur if a hiccup in DNS server has occurred. Apart from making the DNS server more robust or looking for another one, you can also just use the full IP address instead of the hostname. This way it doesn't need to lookup the IP address based on the hostname. However, I would rather fix the DNS issue and prefer the DNS since IP addresses may change from time to time.

like image 86
BalusC Avatar answered Nov 15 '22 08:11

BalusC


An UnknownHostException indicates the host specified couldn't be translated to an IP address. It could very well be a problem with your DNS server.

like image 43
Mark Peters Avatar answered Nov 15 '22 08:11

Mark Peters