You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决Vagrant虚拟机上Java应用远程调试连接失败问题?

远程调试Vagrant虚拟机Java应用失败:Connection reset/握手失败

场景概述

使用IntelliJ IDEA 2023.1.2(社区版),尝试远程调试运行在Vagrant Ubuntu 20.04虚拟机上的Java应用时,遭遇网络类故障,无法建立调试连接。

错误详情

IntelliJ启动远程调试器时的报错

Unable to open debugger port (localhost:5005): java.net.SocketException "Connection reset"

Vagrant虚拟机syslog日志(连接失败后)

Aug 01 19:14:43 ubuntu2004.localdomain sshd[2095]: debug3: channel 0: waiting for connection
Aug 01 19:14:43 ubuntu2004.localdomain sshd[2095]: debug1: channel 0: connection failed: Connection refused
Aug 01 19:14:43 ubuntu2004.localdomain sshd[2095]: error: connect_to 192.168.121.118 port 5005: failed.

使用jdb尝试连接时的报错

$> jdb -attach localhost:5005
java.io.IOException: handshake failed - connection prematurally closed
    at jdk.jdi/com.sun.tools.jdi.SocketTransportService.handshake(SocketTransportService.java:142)
    at jdk.jdi/com.sun.tools.jdi.SocketTransportService.attach(SocketTransportService.java:255)
    at jdk.jdi/com.sun.tools.jdi.GenericAttachingConnector.attach(GenericAttachingConnector.java:119)
    at jdk.jdi/com.sun.tools.jdi.SocketAttachingConnector.attach(SocketAttachingConnector.java:83)
    at jdk.jdi/com.sun.tools.example.debug.tty.VMConnection.attachTarget(VMConnection.java:519)
    at jdk.jdi/com.sun.tools.example.debug.tty.VMConnection.open(VMConnection.java:328)
    at jdk.jdi/com.sun.tools.example.debug.tty.Env.init(Env.java:63)
    at jdk.jdi/com.sun.tools.example.debug.tty.TTY.main(TTY.java:1095)

Fatal error:
Unable to attach to target VM.

已验证的信息

  • 虚拟机上的Java应用已启用调试,启动参数为java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005,因限制无法修改为新版本Java建议的address=*:5005
  • 执行netstat确认目标进程确实在虚拟机的5005端口监听
  • 已配置虚拟机5005端口转发至主机5005端口,且转发规则生效
  • 主机执行nc localhost 5005可成功连接到远程进程

问题

可能遗漏了哪些排查点?有哪些可行的解决思路?


内容的提问来源于stack exchange,提问作者Ben Weintraub

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 14:28:19