Question

I use CentOS 6.5 and Jetty 9.1.0.v20131115. I use Jetty's JMX capabilities.

I want to have JMX accessible only from within the running computer (localhost, or 127.0.0.0/8), but not from outside (e.g. JMX shall not be accessible from public.example.com).

Therefore, I configured Jetty's JMX RMI host to use jetty.jmxrmihost=localhost instead of a wildcard jetty.jmxrmihost=0.0.0.0.

Yet still, my Jetty server instance is accessible from "outside", allowing anyone to connect to my Jetty server via JMX.

What do I have to configure to make Jetty listen to only those JMX connections which originate from localhost?

Here are my Jetty configuration files that are relevant to this topic:


file ${jetty.base}/start.d/jmx.ini:

--module=jmx
#jetty.jmxrmihost=localhost # I tried this one, but it didn't work either
jetty.jmxrmihost=127.0.0.1
jetty.jmxrmiport=1099

file ${jetty.base}/start.d/jmx-remote.ini:

--module=jmx-remote
Was it helpful?

Solution

Just from the way the question is asked, it seems like it is less of a Jetty/JMX issue and more of a firewall issue - what you want is to block unwanted outside traffic to the JMX port on this server.

If you have permissions and are willing to do so, you will want to remove any rule from /etc/sysconfig/iptables that is opening the JMX port (in this example, 1099). Such a rule will look like the following:

[0:0] -A INPUT -s SOME_IP_SUBNET -p tcp -m tcp --dport 1099 -j ACCEPT

Or, on the flip side, you may want to enable JMX monitoring only for a specific subnet (such as for a company's subnet), at which point, you'd want to add the following:

[0:0] -A INPUT -s MY_IP_SUBNET_HERE -p tcp -m tcp --dport JMX_PORT -j ACCEPT

, replacing MY_IP_SUBNET_HERE and JMX_PORT with your own IP subnet and JMX port, respectively.

I haven't written a lot of rules for iptables myself, so please consider the above as an example and not necessarily the exact syntax you need. *nixCraft provides a basic guide to handling iptables/sysctl, which also covers how to modify rules without editing the file (I usually just modify the file).

Two notes, if you go the route of modifying the iptables file:

  • Be sure to restart iptables (/etc/init.d/iptables restart or service iptables restart)
  • Call /sbin/sysctl -p after restarting iptables. Restarting iptables wipes out any custom rules from sysctl.conf, calling sysctl -p will restore those rules.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top