I am not able to connect to an remote known server through Java code; java.net.NoRouteToHostException: No route to host exception occurs when connection is tried.

But strangely, I am able to connect to same server through ssh.

Details: Simple Java client when tries to establish connection with Java standalone server, while conneting the exception occurs at following statement:

Socket socket = new Socket(ServerIP ServerPort);

The port needed is open on server so that externally request can come in.

Again the following is returns false


The Server is running on Fedora, Java 5.

FYI: Java cannot resolve DNS address from AIX: UnknownHostException is almost same to my question, but somehow this is neither AIX nor dns related; moreover I feel the issue to be more of Network or firewall issue.

Please guide me.


This is the error you'd expect from a host being firewalled. Can you telnet to the same port on that IP?

|improve this answer|||||
  • you guessed it right, I cannot telnet, although the netstat show me that the port is open for listening. netstat -pan | grep 5014 tcp 0 0 :::5014 :::* LISTEN 6212/java – nilesh Sep 8 '09 at 6:00
  • netstat will only tell you whether the port is listening, not if it's firewalled. It's entirely possible there's something in between blocking traffic, or a iptables/pf/ipfilter on the host, none of which would show up in netstat. – Cian Sep 8 '09 at 8:11
  • Recently I checked, I am able to telnet certain ports (the port on which mysql-cluster is running) ; but not any other such as 5000 mentioned earlier. I even tried to use some other ports but to no use. – nilesh Sep 8 '09 at 16:05
  • Sounds like a firewall issue. E_CONTACT_NETWORK_ADMIN – Cian Sep 8 '09 at 16:50
  1. The Socket constructor should only attempt to resolve if the hostName is null, and then it tries to resolve the local host. Is your /etc/hosts file set up properly?

  2. What does the following code return? (Please use the host name, not the ip ).

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.