用 netsh trace 在 Windows 上抓取网络数据包

使用内置的 netsh trace 上下文开始 ETL 抓包——服务器上不想装 Wireshark 时的轻量方案。

Windowsnetsh 网络配置捕获故障排查中风险
运行 netsh trace start capture=yes tracefile=C:\temp\nettrace.etl 开始抓包,用 netsh trace stop 结束并合并追踪文件。

01命令

命令
$ netsh trace start capture=yes tracefile=C:\temp\nettrace.etl maxsize=512

02作用说明

netsh trace 从 Windows Server 2008 起就已内置,但需要抓包时几乎没人记得它。除了抓原始数据包(capture=yes),它还能按 provider 场景追踪(如 scenario=Connectivity),停止时会生成带关联日志的 CAB 文件。生成的 .etl 可用 Microsoft Network Monitor 打开,或用 etl2pcapng 转换成 Wireshark 可读格式。

03风险

风险中风险
使用条件Run Command Prompt as Administrator
!注意: 抓包会一直进行直到执行 netsh trace stop——忘了停止会写满 maxsize 后继续覆盖记录;ETL 文件也很大,tracefile 请指定在空间充足的路径。

04撤销

撤销
$ netsh trace stop

05来源

  • netsh trace | Microsoft Learn
    Microsoft · vendor-doc · 2026-09-17
    依据: Microsoft documents 'netsh trace start' with capture=yes and tracefile parameters to begin a packet capture, and 'netsh trace stop' to end it and correlate the logs.
  • NETSH - Windows CMD
    SS64 · technical · 2026-09-17
    依据: SS64 documents the netsh trace context, including scenario-based tracing and capture options.

最后验证: 2026-09-17 · 分类: 网络

06相关方案