38

I recently installed tomcat via an installation script from the apache solr typo3 community and spent the last 3 days trying to figure out why it won't work until by chance I noticed that when I queried the process listening on the port via "lsof -i", it was bound to the ipv6 protocol.

I have googled everywhere and most say that setting address to 0.0.0.0 in the tomcat connector resolves this issue, others say setting JAVA_OPTS="-Djava.net.preferIPv4Stack=true".

I have tried the former which doesn't work but the latter I am unsure of where to put it. One solution I read somewhere suggested to put it in setenv.sh but I can't find this file in my tomcat installation. I would appreciate any help at the moment regarding this.

The tomcat version is 6.x and the OS is ubuntu 11.10.

Thanks

StackzOfZtuff
  • 1,754
  • 12
  • 21
Dark Star1
  • 1,355
  • 6
  • 21
  • 37
  • 1
    What ips/ports is it listening on, via lsof -i? – becomingwisest May 20 '12 at 19:01
  • @becomingwisest 8080. – Dark Star1 May 20 '12 at 22:50
  • You are correct - setenv.sh file does not exist out of box. You need to create setenv.sh file in your CATALINA_BASE or CATALINA_HOME bin directory. The startup scripts check if you created the file, if you did create customization (setenv.sh) file - startup script calls it, otherwise just ignores, and moves on. – nevenc Aug 14 '15 at 12:03

7 Answers7

35

Many suggested updating catalina.sh startup script. Yes, that solution would work, but catalina.sh script is not meant to be customized/updated. All changes should go into the customization script instead, i.e. setenv.sh.

NOTE: TOMCAT_HOME/bin/setenv.sh doesn't exist by default, you need to create it. Check the catalina.sh script and you will see the startup script checks if setenv.sh exists, and executes if it does.

So, I suggest you create new TOMCAT_HOME/bin/setenv.sh script with a single line:

JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true "
nevenc
  • 466
  • 4
  • 4
  • 3
    I would also use CATALINA_OPTS instead of JAVA_OPTS, especially if you have other JVM options you want to pass into JVM on Tomcat startup. If you use JAVA_OPTS, the same options will be passed into Tomcat shutdown, probably not what you would want/expect. Use CATALINA_OPTS instead :) – nevenc Aug 14 '15 at 12:01
  • I'm choosing this as the answer now since most people having this issue today would most likely be using a newer version of tomcat. – Dark Star1 Apr 06 '18 at 08:46
28

Ok I finally solved it. I was directed to try this and Henk's solution. Neither of which seemed to work with the remote virtual server. I'm guessing the fact that because I'm on a shared kernel space so the provider prevents this. In any case I added: JAVA_OPTS= $JAVA_OPTS -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses to the catalina.sh startup script and that seemed to have fixed the issue of binding tomcat to ipv6.

Dark Star1
  • 1,355
  • 6
  • 21
  • 37
5

The correct syntax for modifying catalina.sh would be:

JAVA_OPTS=" $JAVA_OPTS -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true "
yglodt
  • 245
  • 3
  • 8
3

If you used this installer: "Apache Solr for TYPO3", you can change the address in the file server.xml. The default points to localhost, so look for 127.0.0.1 and change it into the IPv4-address you want. Don't forget to restart Tomcat6 for the changes to take effect.

UPDATE, 20120521

See my comment below on how to disable IPv6 on Ubuntu 11.10.

I have successfully tested this on a Virtualbox-VM on my Mac. The address for the connector port 8080 has been changed from 127.0.0.1 to 0.0.0.0 in server.xml.

Then disabling IPv6 makes the "tcp6" to go away, so it's binded to an IPv4-only address.

Before / with IPv6 enabled:

# netstat -anp | grep 8080   
tcp6       0      0 :::8080                 :::*                    LISTEN      1972/java

After / IPv6 disabled:

# netstat -anp | grep 8080   
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      2045/java
slm
  • 7,355
  • 16
  • 54
  • 72
Henk
  • 1,321
  • 11
  • 24
  • 1
    Tried this also and that didn't work netstat shows that despite the process being bound to an ipv4 address it's still looking for an ipv6 a la this return: tcp6 0 0 X.X.X.X:8080 :::* LISTEN. which I think is odd but the problem has also been replicated on my friend's vm which is hosted on a mac. – Dark Star1 May 20 '12 at 22:46
  • And when IPv6 is disabled? Here is a howto for Ubuntu 11.10: http://pario.no/2011/12/09/disable-ipv6-on-ubuntu-11-10/ – Henk May 21 '12 at 07:29
1

Along with the other answer using setenv.sh and CATALINA_OPTS...

Using Tomcat SSL with APR, the only way I could get Tomcat to bind to ipv4 was to add this to the connector config:

address="0.0.0.0"

server.xml looks like this:

<Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
               maxThreads="150"
               SSLEnabled="true"
               scheme="https"
               compression="off"
               connectionTimeout="1190"
               address="0.0.0.0"
               >
comfytoday
  • 183
  • 1
  • 7
0

While probably not the preferred method, I have observed that disabling IPv6 at the kernel level will convince Tomcat to open an IPv4 bind.

pierce.jason
  • 193
  • 1
  • 8
-2

Debian 8 navigate to using your favorite editor on /etc/default/grub ; look for the section GRUB_CMDLINE_LINUX_DEFAULT="quiet"** with then add ipv6.disable=1, as seen below

GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1 quiet"

Save and exit. In the same directory use your favorite editor on /etc/default/tomcat8 then look for the section with JAVA_OPTS= which will be commented out, add the following below that line. JAVA_OPTS=" $JAVA_OPTS -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true"

Save and exit

At the command prompt type update-grub , if you have sudo use with sudo, then restart tomcat8 service tomcat8 restart

You should be on IPv4 now.

Please in future posts include complete paths and file names. Thank You