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

如何通过Wireshark捕获经跳板机的远程Linux主机实时流量?

实现通过Wireshark实时捕获远程主机B的流量(经主机A跳板)

Got it, let's break this down into straightforward, actionable steps since you already have a solid foundation with the tcpdump command. Here are two reliable methods to get real-time traffic from B into your Windows Wireshark instance:

方法1:直接通过SSH管道转发到Wireshark(最简便)

This method pipes the tcpdump output from B, through A, straight into Wireshark on your Windows machine—no intermediate files needed.

  1. 确保Windows已安装OpenSSH客户端:Windows 10/11默认预装了该工具,若未安装可通过「设置 > 应用 > 可选功能」启用。
  2. 在PowerShell或CMD中运行以下命令:
    ssh -J user@ip_of_A user@ip_of_B "sudo tcpdump -s0 -U -n -w - -i lo not port 22" | "C:\Program Files\Wireshark\Wireshark.exe" -k -i -
    
    • -J user@ip_of_A: 将主机A作为跳板,直接连接到主机B(要求OpenSSH版本7.3+,多数现代版本均支持)。
    • sudo tcpdump ... -w -: 以root权限运行tcpdump(捕获全量数据包必需),将原始数据包输出到标准输出而非本地文件。
    • Wireshark.exe -k -i -: 启动Wireshark并立即开始捕获(-k),同时从标准输入读取数据包(-i -)。

若你使用的是旧版OpenSSH(不支持ProxyJump)

改用嵌套SSH命令即可:

ssh user@ip_of_A "ssh user@ip_of_B 'sudo tcpdump -s0 -U -n -w - -i lo not port 22'" | "C:\Program Files\Wireshark\Wireshark.exe" -k -i -

注意:如果遇到引号转义问题,建议用PowerShell执行——它对单/双引号的处理比CMD更友好。

方法2:通过SSH端口转发+Netcat(更灵活)

如果需要持久化连接或共享捕获流,可将主机B的tcpdump输出转发到Windows本地端口,再用Wireshark读取。

  1. 在Windows上建立端口转发并启动tcpdump:
    ssh -L 3333:localhost:3333 -J user@ip_of_A user@ip_of_B "sudo tcpdump -s0 -U -n -w - -i lo not port 22 | nc -l 3333"
    
    • -L 3333:localhost:3333: 将主机B的3333端口流量转发到Windows本地的3333端口。
    • nc -l 3333: 使用netcat监听B的3333端口(若B上未安装netcat,可通过sudo apt install netcat安装),将tcpdump输出通过该端口发送。
  2. 打开新终端启动Wireshark:
    nc localhost 3333 | "C:\Program Files\Wireshark\Wireshark.exe" -k -i -
    
    该命令会读取本地3333端口的流量,并将其传入Wireshark进行实时分析。

关键注意事项

  • Root权限:tcpdump需要root权限才能捕获全量数据包,因此命令前需加sudo。若不想每次输入密码,可在主机B上配置tcpdump的免sudo权限。
  • Wireshark路径:若你将Wireshark安装在非默认路径,需相应调整Wireshark.exe的路径。
  • 过滤规则调整:如果需要捕获A与B之间的SSH流量,可移除not port 22——不过这会给捕获结果增加额外的噪声。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:46:19