2

如何在不硬编码 IP 的情况下欺骗 Java RMI 以从本地主机外部访问?

4

1 回答 1

0

由于不可能使 RMI 绑定到 0.0.0.0,因此解决方案是检测 IP 并使用它。

我在 Linux 和 OS X 上都使用了以下解决方案:

IP=$(ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')
# if we have several IPs found, we pick the first one
for IP in $IP:
do
  break
done

CATALINA_OPTS="-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=8081 \
-Dcom.sun.management.jmxremote.local.only=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-Djava.rmi.server.hostname=${IP} "

显然这是配置它的不安全方式,但您可以自由调整它以满足您的需求。

于 2013-08-28T11:38:34.987 回答