Monday, December 17, 2007

Tomcat java.net.BindException: Cannot assign requested address

I had a very strange error today when I tried to startup tomcat on some linux box that used to work. Since google was no help I figured I should document this somewhere.

Tomcat startup gave the notorious java.net.BindException: Cannot assign requested address. This usually means that another process is listening on the same port on this machine. I started with ps -ef grep java to make sure that no other tomcat process was running on the machine. Nothing.

I suspected that maybe some other web server was holding the port, but netstat -an showed that nothing binds this address. Moreover, telnet localhost 80 showed that no one is listening.

Looking at the server.xml I found out that the connector was binding to the hostname "demoserver" on port 80.

<Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
address="demoserver" port="80"
minProcessors="5" maxProcessors="75"
enableLookups="true" redirectPort="8443"
acceptCount="100" debug="0" connectionTimeout="20000"
useURIValidationHack="false" disableUploadTimeout="true" />

trying to ping demoserver gave me errors, but nslookup demoserver gave me the right ip address.

After a few minutes I noticed that some clown added demoserver to /etc/hosts with the wrong ip address. Fixing /etc/hosts to have the right ip address for demoserver made tomcat work smooth and nice.

26 comments:

  1. Great tip. This helped me solve the exact same problem.

    ReplyDelete
  2. Thanks a lot, had the exact same problem.

    ReplyDelete
  3. This is what I just need.
    Many thanks :-)

    ReplyDelete
  4. You're awesome! Saved me a lot of time and head banging....

    ReplyDelete
  5. Hey I had a similar issue with Weblogic 10 starting the nodemanager - and your comment fixed it - someone had put the wrong ip address of my server in /etc/hosts - thanks!!!

    ReplyDelete
  6. have same problem but not on linux, its on vista. can i be helped ?

    ReplyDelete
  7. cheers! had a duplicate and inccorect entry in hosts file for localhost. removed it and it worked fine!

    ReplyDelete
  8. Thanks, had the same issue on linux.

    ReplyDelete
  9. Same issue here, thanks so much!

    ReplyDelete
  10. Thanks! Also fixed an issue for me (bad entry in the /etc/hosts file), Java app in question was an AR System Plug-in Server. Seems like the same message is used for cases where the TCP port the bind is trying is in use, so the message was just a bit too generic.

    ReplyDelete
  11. this tip helped me as i noticed that the error msg is related to ip address in case i had to request ip and port open on the LoadBalncer
    thanx

    ReplyDelete
  12. thanks a lot. even we are facing same issue. we added an entry for localhost into /etc/hosts then our server started without any problem

    ReplyDelete
  13. Saved me some time here thank you very much.

    ReplyDelete
  14. It works great!!! Thanks a lot my friend!!!

    ReplyDelete
  15. thanks dude
    worked like a charm with glassfish

    ReplyDelete
  16. We got a similar error doing an ftp connection with a java application, using sunone appserver 8.2.
    The issue was solved adding the following jvm option to the appserver and restarting it.

    -Dcom.sun.enterprise.server.ss.ASQuickStartup=false

    Hope it will help ...

    Regards.
    Elibm

    ReplyDelete
  17. You made my day! Big Thx !

    ReplyDelete
  18. Great article!
    In my case QA guys simply deleted the following mandatory lines in /etc/hosts:
    127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

    ReplyDelete
  19. Thanks..worked for me...I checked /etc/host but did not find that same IP 127.0.0.1 has two different host

    ReplyDelete
  20. Dear all,

    I am happy that after 4 years this post (one of the first I wrote) is still very helpful and all the more relevant.

    Thank you for the comments...

    ReplyDelete
  21. Still useful in 2012. Upgrading from Tomcat5 to Tomcat6. Worked all fine in Tomat5, but with Tomcat6 it could not bind to the shutdown port. After finding this post, I noticed that the hosts file contained a typo "i127.0.0.1". This server was running for the last 6 years with that ;)

    ReplyDelete
  22. really works! thanks a lot

    ReplyDelete
  23. great dude..it worked for me also..saved time

    ReplyDelete
  24. thanks dude, This post saved me tons of headache

    ReplyDelete

[Due to much spam, comments are now moderated and will be posted after review]