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

树莓派用tcpdump与socat抓包重传时遇Permission denied错误求助

解决socat发送UDP广播时的Permission Denied问题

你在树莓派上通过tcpdump捕获多播包、再用socat转发为广播包时,遇到了如下权限错误:

tcpdump: listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
2023/09/26 20:17:17 socat[2400] E sendto(5, 0x3fb000, 24, 0, AF=2 192.168.7.255:14555, 16): Permission denied

使用的脚本如下:

#!/bin/bash
# Define the multicast group and port to capture
multicast_group="224.1.1.1"  # Replace with your specific multicast group address
multicast_port=12345  # Replace with the multicast port number
# Define the broadcast address and port to retransmit
broadcast_address="192.168.xxx.xxx"  # Broadcast address for the target network
forward_port=54321  # Replace with the port number you want to use for forwarding
while true; do
# Start tcpdump to capture UDP multicast packets
sudo tcpdump -i eth0 -n -s0 -U -w - "udp and port $multicast_port" | \
sudo socat -u - UDP4-DATAGRAM:$broadcast_address:$forward_port
done

问题原因

这个错误并非因为缺少sudo权限,而是socat默认禁止发送UDP广播包,即使以root身份运行也需要显式开启广播允许选项。

解决步骤

  1. 修改socat的参数,在UDP4-DATAGRAM目标后添加,broadcast选项,允许发送广播包:
    sudo tcpdump -i eth0 -n -s0 -U -w - "udp and port $multicast_port" | \
    sudo socat -u - UDP4-DATAGRAM:$broadcast_address:$forward_port,broadcast
    
  2. 确保broadcast_address是当前子网的有效广播地址(比如子网掩码为255.255.255.0时,广播地址通常是192.168.x.255)。
  3. 重新运行脚本(可直接用sudo ./your_script.sh执行,或确保脚本有可执行权限后再用sudo运行)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 00:00:01