无法远程调试应用程序 - 端口无法外部访问

4

我需要远程调试我的应用程序,但由于以下错误,我无法这样做:

Unable to open debugger port (X.X.X.X:8000): java.net.ConnectException "Connection timed out: connect"

我有:

  1. 在远程服务器(Debian)上运行的 Tomcat 中的 Java 应用程序
  2. 本地运行的 IntelliJ Idea(Windows)

我得出的结论是,用于远程调试的端口8000只能通过“localhost”访问,无法通过外部IP访问。以下是我认为原因的几点:

远程调试正在预期的端口上进行:

root@victor-app-server:/opt/tomcat-home/bin# netstat -tulpn | grep 8000
tcp  0  0  0.0.0.0:8000  0.0.0.0:*  LISTEN  3773/java

我能通过“localhost”用telnet登录它:
root@victor-app-server:/opt/tomcat-home/bin# telnet localhost 8000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.

但是无法通过外部IP进行Telnet:

root@victor-app-server:/opt/tomcat-home/bin# telnet X.X.X.X 8000
Trying X.X.X.X...
telnet: Unable to connect to remote host: Connection timed out

这里是iptables的输出结果:
root@victor-app-server:/opt/tomcat-home/bin# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

我该如何解决8000端口的问题?或者我的主要问题可能有其他原因吗?


我假设你的Debian服务器防火墙不允许连接到8000端口。 - Heri
@Heri,我认为既然iptables没有规则,防火墙就不会引起问题。如果不是这样,请告诉我如何检查防火墙? - Victor Dombrovsky
1
服务器在哪里?在本地局域网内还是外部?如果服务器在另一个局域网内,那么连接到该服务器的路由器配置是否正确? - MikeCAT
3个回答

1
这是让我成功的命令:
sudo ufw allow

1

我曾在使用Java 11时遇到过同样的问题,涉及地址属性,如以下JVM参数:

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=6565

然而,我的问题通过改变地址属性的值来解决,就像这个示例一样:
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=*:6565

现在6565端口可以从外部访问。


0
尝试使用“iptables -F”命令来解除防火墙的屏障。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接