Linux 网络数据收发全栈工具书:从 nc、socat 到 iperf3 的 Buildroot 路径与跨平台实战

Linux 网络数据收发全栈工具书:从 nc、socat 到 iperf3 的 Buildroot 路径与跨平台实战

日期:2025-08-26

标签:Linux、Buildroot、网络调试、iperf3、netcat、Windows、tcpdump


一、为什么要收藏这篇文章?

无论你是做嵌入式 Buildroot 固件、运维网络压测,还是 Windows 桌面抓包,只要涉及"把数据从 A 点搬到 B 点并看清沿途一切",本文一张表就能告诉你:

  • 该装哪个包
  • 在 Buildroot menuconfig 中的精确路径
  • 一条命令就能跑起来的最小示例
  • Windows 下是否可用,如何安装

全文无废话,直接复制粘贴即可用。


二、Linux 端工具速览

工具 一句话定位 最小发送示例 最小接收示例

nc (netcat) 瑞士军刀,TCP/UDP 通吃 nc -u 192.168.1.10 12345 < file.bin nc -ulk 0.0.0.0 12345 > recv.bin

socat 多协议瑞士军刀,支持 SSL、UNIX-Socket socat - UDP:192.168.1.10:12345 socat UDP-LISTEN:12345 -

iperf3 带宽、丢包、抖动压测神器 iperf3 -c 192.168.1.10 -t 30 iperf3 -s

tcpdump 命令行抓包之王 (抓) tcpdump -i eth0 -w a.pcap (看) tcpdump -nn -r a.pcap

tshark Wireshark CLI 版 tshark -r a.pcap -Y "http" ---

tcpreplay 把 pcap 原样或倍速重放 tcpreplay -i eth0 a.pcap ---


三、Buildroot:menuconfig 精确路径表

打开 make menuconfig,按以下层级勾选即可把工具编进 rootfs。

工具 完整路径(Target packages → ...)

netcat Networking applications → netcat

ncat (nmap 版) Networking applications → nmap → ncat

socat Networking applications → socat

iperf3 Networking applications → iperf3

tcpdump Networking applications → tcpdump

tshark / Wireshark CLI Networking applications → wireshark → {tshark / wireshark-cli}

tcpreplay Networking applications → tcpreplay

ethtool Networking applications → ethtool

iptables Networking applications → iptables

nftables Networking applications → nftables

技巧:在 menuconfig 里按 / 搜索关键字(如 /ncat),可直接跳转并查看依赖。


四、Windows 也能用吗?------答案汇总

工具 Windows 可用性 获取方式

iperf3 ✅ 原生 GitHub Releases 下载 iperf-3.x-win64.zip,解压得 iperf3.exe,CMD/PowerShell 直接运行

nc/socat/tcpdump ✅ 通过 WSL 或 Cygwin Windows Store 装 WSL → apt install nc socat tcpdump

Wireshark ✅ 官方 GUI 官网下载安装包,图形界面抓包

Packet Sender ✅ 跨平台 GUI GitHub Releases 下载 exe,支持 TCP/UDP/SSL 一键发包

实测 Windows 版 iperf3 与 Linux 对打数字一致,防火墙首次弹窗点"允许"即可。


五、实战小抄:一条命令解决 90% 场景

  1. 临时 UDP 回显服务器(Linux / Buildroot)
bash 复制代码
nc -ulk 0.0.0.0 7000 | hexdump -C
  1. 从 Windows 向 Linux 打流 30 秒
powershell 复制代码
# Windows 端
.\iperf3.exe -c 192.168.1.100 -t 30 -R   # 反向测试
  1. 抓包并实时打印 ASCII
bash 复制代码
tcpdump -i any -nn -A udp port 7000
  1. 把抓到的包 10 倍速重放
bash 复制代码
tcpreplay -i eth0 -l 1000 -p 10000 test.pcap

六、一张思维导图(文字版)

复制代码
网络数据收发工具
├─ 临时调试
│  ├─ nc/netcat
│  ├─ socat
│  └─ ncat
├─ 抓包分析
│  ├─ tcpdump
│  ├─ tshark
│  └─ Wireshark
├─ 性能压测
│  ├─ iperf3
│  └─ tcpreplay
└─ 内核转发
   ├─ iptables/nftables
   └─ XDP + bpftool

七、总结

  • Buildroot:记住路径 Networking applications 里应有尽有。
  • Windows:iperf3、Wireshark、Packet Sender 有官方原生包,其余 WSL 一键搞定。
  • 最小记忆:nc 临时收发、iperf3 看带宽、tcpdump 抓包,三者组合可解决 90% 网络疑难杂症。

把本文收藏 + 点赞,下次再也不用手忙脚乱搜命令!