I'm trying to send a UDP datagram message with socat to a broadcast address.

On the receiving end this is how I'm running socat (with root privileges):

socat UDP-LISTEN:1011 -

I'm trying to send the message with the following code (with root privileges):

echo -n "test" | socat - UDP-DATAGRAM:,broadcast

Observed behavior

When using a port below 1025 (a privileged port, etc), broadcast datagram messages seem to get dropped. When I use a port above 1024, it works fine.

I also tried a broadcast address according to my local network, but I observe the same behavior, only ports above 1024 receive the datagram.

iptables don't have any entries, that would impede receiving of UDP messages on the receiving side. Similarly, no entries on the sending side. In fact iptables -L contains no entries except what is expected after running iptables -F.


Is this standard behavior and I should simply use a port >1024, or can I work around this? I'd like to use a port below 1025 in my case.

  • I don't see the same behavior in my environment. Here broadcast works also for ports < 1024 even when non-root user transmits. Few questions: 1. Does it happen even if you're running both receiving and transmitting ends on the same host? 2. Can you connect to the port directly (without broadcast) with the IP? 3. Is it possible you have a firewall in your environment? Can you run tcpdump udp port 1011 on the receiving end while you're listening to the port, and see if something shows up when you try to transmit something to this port?
    – aviro
    Jul 19, 2023 at 11:00
  • Which OS are you using on each side? Is SELinux enabled on either of them? Jul 19, 2023 at 11:01
  • @aviro №1: yes. №2: yes. №3: no. №4: will try, and report back.
    – polemon
    Jul 19, 2023 at 11:30
  • @SvižnýSvišť Both are Linux Fedora 38. SELinux is enabled. Could that have an impact? Shall I disable it and retry?
    – polemon
    Jul 19, 2023 at 11:32
  • @aviro I do see activity when running tcpdump udp port 1011: 13:58:14.049065 IP fedora.39522 > UDP, length 4`
    – polemon
    Jul 19, 2023 at 11:58

1 Answer 1


Here all examples must be run as root because we are considering at least one port <1024.

First, I set up a repeating broadcast utility on my sending server:

while sleep 5
    text="$((n++)): $(date)"
    echo "Sending: $text"
    for port in 1011 2022
        socat - UDP-DATAGRAM:$port,broadcast <<<"$text on port $port"
        echo "Sent on port $port"

The remaining commands in this answer are run on a different system, the receiving client (two of them in my case).

The documentation (man socat) describes UDP-LISTEN such that it, "waits for a [i.e. one] UDP/IP packet arriving on and 'connects' back to [the] sender". The key here is that it accepts one single packet. It then waits for a response (on stdin), which it tries to return to the sender. You can see this in action with an example such as these:

socat UDP-LISTEN:1011 - </dev/null       # Succeeds as nothing sent
socat UDP-LISTEN:1011 - <<<'response'    # Fails to send as sender not listening

socat UDP-LISTEN:2022 - </dev/null       # Succeeds as nothing sent
socat UDP-LISTEN:2022 - <<<'response'    # Fails to send as sender not listening

I think you might be wanting either UDP-RECVFROM, which receives a single packet and relays it to stdout before exiting, or UDP-RECV, which continuously accepts packets and relays them to stdout:

socat UDP-RECVFROM:1011 -                # Receives one packet and exits
socat UDP-RECV:1011 -                    # Continuously relays packets to stdout

socat UDP-RECVFROM:2022 -                # Receives one packet and exits
socat UDP-RECV:2022 -                    # Continuously relays packets to stdout

The port 2022 examples can be run either as root or as a normal unprivileged user. The port 1011 examples require root (or an appropriate capability).

  • I tried just that, but I'm experiencing the same issue, even though SELinux and firewalls, etc. are disabled, I can't receive a UDP datagram with UDP-RECV on ports <1025.
    – polemon
    Jul 24, 2023 at 12:51
  • @polemon hmm. Network topology? Any of the clients or the server running as a container or VM (or a container/VM host)? Can you either amend your question to provide full networking details or, if that's not appropriate, can you email them to me? Contact details are in my SE profile. For each client and server, IP address with subnet, and routing table. Jul 24, 2023 at 14:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .