How to Configure Jetty to Listen on All Interfaces (0.0.0.0) in Ubuntu 10.04 (Lucid)


2 views

When deploying Jetty 6.1.22 on Ubuntu 10.04 (Lucid Lynx) via the Canonical partner repository, you might notice the server only binds to 127.0.0.1 despite setting JETTY_HOST= empty in /etc/default/jetty. This prevents external connections.

Jetty's default configuration in Ubuntu packages uses jsvc (Java Service Wrapper), which has its own binding rules. The key configuration files involved are:

/etc/default/jetty
/etc/init.d/jetty
/usr/share/jetty/bin/jetty.sh

Here's how to properly configure Jetty to listen on all interfaces:

  1. Edit the main configuration:
    sudo nano /etc/default/jetty
    

    Set these values:

    JETTY_HOST=0.0.0.0
    JETTY_ARGS="jetty.host=0.0.0.0"
    
  2. Modify the init script behavior:
    sudo nano /etc/init.d/jetty
    

    Find the DAEMON_ARGS line and add:

    -Djetty.host=0.0.0.0
    
  3. Restart Jetty:
    sudo /etc/init.d/jetty restart
    

After making these changes, verify the binding:

sudo netstat -tulnp | grep java

You should see output similar to:

tcp6  0  0 :::8080  :::*  LISTEN  12345/java

For more control, you can modify Jetty's XML configuration:

<Configure id="Server" class="org.mortbay.jetty.Server">
    <Set name="connectors">
        <Array type="org.mortbay.jetty.Connector">
            <Item>
                <New class="org.mortbay.jetty.nio.SelectChannelConnector">
                    <Set name="host"><SystemProperty name="jetty.host" default="0.0.0.0"/></Set>
                    <Set name="port"><SystemProperty name="jetty.port" default="8080"/></Set>
                </New>
            </Item>
        </Array>
    </Set>
</Configure>

On Amazon EC2, ensure your security group allows inbound connections on port 8080. Also verify that Ubuntu's UFW firewall isn't blocking the port:

sudo ufw allow 8080/tcp

When examining your netstat output, the key observation is:

tcp6       0      0 127.0.0.1:8080          :::*                    LISTEN

This shows Jetty is only bound to the loopback interface (127.0.0.1) rather than all available interfaces (0.0.0.0). The IPv6 notation (tcp6) with IPv4 address is normal for modern Linux systems with dual-stack configuration.

While you've set JETTY_HOST empty, we need to ensure Jetty's XML configuration reflects this. Edit your Jetty configuration:

sudo nano /etc/jetty/jetty.xml

Locate the Connector configuration and modify it:

<Call name="addConnector">
  <Arg>
    <New class="org.mortbay.jetty.nio.SelectChannelConnector">
      <Set name="host"><SystemProperty name="jetty.host" default="0.0.0.0"/></Set>
      <Set name="port"><SystemProperty name="jetty.port" default="8080"/></Set>
      <Set name="maxIdleTime">30000</Set>
      <Set name="Acceptors">2</Set>
      <Set name="statsOn">false</Set>
    </New>
  </Arg>
</Call>

For Ubuntu packages, you might need to modify the startup script instead:

sudo nano /etc/init.d/jetty

Find the JAVA_OPTIONS section and add:

JAVA_OPTIONS="$JAVA_OPTIONS -Djetty.host=0.0.0.0"

Ensure your EC2 security group allows inbound traffic on port 8080. Also check Ubuntu's built-in firewall:

sudo ufw status
sudo ufw allow 8080/tcp

After making changes and restarting Jetty (sudo service jetty restart), verify with:

sudo netstat -tulnp | grep 8080

You should see:

tcp6   0   0 :::8080   :::*   LISTEN   12345/java
  • Check Jetty logs: tail -f /var/log/jetty/<date>.stderrout.log
  • Test locally first: curl http://localhost:8080
  • Test remotely: curl http://your-ec2-public-ip:8080
  • If using jsvc (as shown in your netstat), check /etc/default/jetty for jsvc-specific options