The basic problem to be solved is that in the RMI world the server-side decides how a client should connect (right?). So setting e.g. java.rmi.server.hostname on HostX isn't going to help. As I see it I can only make either HostA happy or HostB happy, but not both at the same time.
This is not going to help you but for others, the trick to do is to set the java.rmi.server.hostname
system property to a name that means something on HostA which is inside of the firewall but another thing to HostB which is outside.
For example, in EC2 land we set the hostname property to be the EC2 node's "public hostname" which we get by doing a:
wget -q -O - http://169.254.169.254/latest/meta-data/public-hostname
This resolves to be some like:
ec2-54-1-2-3.compute-1.amazonaws.com
On the box itself and any others that are inside of EC2 this resolves to be 10.1.2.3
while on the outside world it resolves to the externally facing IP 54.1.2.3
. Amazon does this DNS work by default. You may need to adjust the /etc/hosts
file as necessary to get the names to be correct.
For more details on EC2 and JMX, see: How to connect to Java instances running on EC2 using JMX