Friday, July 13, 2007

Tomcat server listens on the network interface

Issue: Installed tomcat under linux server

(/usr/local/java/tomcat/jakarta-tomcat-5.0.25-src/jakarta-tomcat-5/build/).

If run the tomcat under
( /usr/local/java/tomcat/jakarta-tomcat-5.0.25-src/jakarta-tomcat-5/build/bin/ sh startup.sh), getting the message as

[root@server bin]# sh startup.sh
Using CATALINA_BASE: /usr/local/java/tomcat/jakarta-tomcat-5.0.25-src/jakarta-tomcat-5/build
Using CATALINA_HOME: /usr/local/java/tomcat/jakarta-tomcat-5.0.25-src/jakarta-tomcat-5/build
Using CATALINA_TMPDIR: /usr/local/java/tomcat/jakarta-tomcat-5.0.25-src/jakarta-tomcat-5/build/temp
Using JAVA_HOME: /usr/local/java

And http://localhost:8080 is also not getting through............


Solution:

The Tomcat is running on a Linux server, but trying to reach it on the localhost of a windows machine (using Internet Explorer)

1) We will need to find the right hostname to reach to the tomcat server.

2) Then check the log files for error.

Tomcat logs in a "logs" directory under the main tomcat directory. The first thing to look at is "catalina.out" which is where stdout and stderr messages from tomcat are sent.

3) # netstat -na|grep 8080 |grep -i listen

will reveal on the Linux box whether the port 8080 is listened on.

4) If you are using 8888 port number, then use the command as

# netstat -na|grep 8888 |grep -i listen

5) Looks like the server is starting so the next most likely problem is with your network setup.

Try accessing the server from the machine it's running on. If you can't run a browser just try

telnet localhost 8888

and, if you get a connection, type

GET /

If that works try a telnet from the windows machine.

You could have DNS or firewall problems.

6) If you get something like .....

[root@server bin]# telnet localhost 8888
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused


"Connection refused" means that there's nothing listening on that port. Use the ps command to check that the tomcat instance is still running.

7) # netstat -na|egrep -i 'Proto|8888'
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN

8)TELNET LOCALHOST 9876
Connecting To LOCALHOST...Could not open a connection to host on port 9876 : Connect failed

TELNET 127.0.0.1 9876
Connecting To 127.0.0.1...Could not open a connection to host on port 9876 : Connect failed


9) Looks like the tomcat server listens on the network interface.