Skip to main content

Socat and Multicast

·513 words·3 mins

Introduction
#

Yesterday, I referenced http://www.dest-unreach.org/socat/doc/socat.html#EXAMPLES
with examples and one of those is actually a multicast! If you remember, a network connection (TCP or UDP) is like a phone call, well, IP multicast is like TV Broadcast - a single source sent the data (stream of bytes) and others consume it (or not if not interested). IP multicast is well known for being fairly difficult to set up (and troubleshoot) but with socat, it is actually quite easy to do. Do you remember that almost-no-sense example with ssh over UDP? Here we go again!

Scenario
#

Imagine following scenario - the box s1 on the left hand side is the source of the multicast (multicast is technically an unidirectional stream of UDP packets to ‘whoever is interested’) and the box s2 is the consumer of the multicast. The source s1 sends the stream of bytes to the multicast group and s2 ‘somewhat announced’ to the network that it’s interested in the multicast group and then consumes the stream of bytes. Boxes s3 and s4 are also interested but the ‘I want to listen too’ announcement doesn’t work due to lack of multicast support between s1, and s3 and s4.

initial diagram

Let’s demonstrate:

on s1

 socat -u - UDP4-DATAGRAM:224.1.2.3:12345,range=10.0.0.0/8

on s2

 socat -u UDP4-RECVFROM:12345,ip-add-membership=224.1.2.3:10.0.1.12,fork -

on s3

 socat -u UDP4-RECVFROM:12345,ip-add-membership=224.1.2.3:10.0.2.13,fork -

on s4

socat -u UDP4-RECVFROM:12345,ip-add-membership=224.1.2.3:10.0.2.14,fork -

And sent a message from s1:

[lab@s1 ~]$  socat -u -  UDP4-DATAGRAM:224.1.2.3:12345,range=10.0.0.0/8
Good evening!

the message is received on s2:

[lab@s2 ~]$ socat UDP4-RECVFROM:12345,ip-add-membership=224.1.2.3:10.0.1.12,fork  -
Good evening!

but not on s3 nor s4

[lab@s3 ~]$ socat UDP4-RECVFROM:12345,ip-add-membership=224.1.2.3:10.0.2.13,fork -

[lab@s4 ~]$ socat UDP4-RECVFROM:12345,ip-add-membership=224.1.2.3:10.0.2.14,fork -

So what now? do we need to implement underlay/overlay network? Setup some GRE somewhat somewhere and route it through it? Or do we need to buy an expensive appliance? Do we need to bypass all firewalls? Well… let me repurpose some of our servers in the scenario - I want server s2 to work like a proxy - on one side, it will listen for the incoming multicast and on the other it will sent the exact byte stream into direct UDP connection over the part of network which doesn’t support multicast. On the other side, s3 will listen for inbound UDP traffic from s2, and all byte stream will be broadcasted sent as multicast so server s4 can consume it (as multicast). (I am going to change the used addresses and ports to make everything working as intended)

and let’s demonstrate it again: on s1

socat -u -  UDP4-DATAGRAM:224.1.2.3:12345,range=10.0.0.0/8

on s2

socat UDP4-RECVFROM:12345,ip-add-membership=224.1.2.3:10.0.1.12,fork UDP:10.0.2.13:23456

on s3

socat UDP-L:23456,fork UDP4-DATAGRAM:224.1.2.4:34567,range=10.0.0.0/8

on s4

socat UDP4-RECVFROM:34567,ip-add-membership=224.1.2.4:10.0.2.14,fork -
socat diagram

Quick test: on s1

[lab@s1 ~]$  socat -u -  UDP4-DATAGRAM:224.1.2.3:12345,range=10.0.0.0/8
Good morning!!

and received on s4

[lab@s4 ~]$ socat UDP4-RECVFROM:34567,ip-add-membership=224.1.2.4:10.0.2.14,fork -
Good morning!!

Technically, s1 act as the ‘broadcaster which is usually out of our control’, and s4 on the other side is just a ‘dummy’ application which is out of our control as well, but s2 and s3 are ‘under our control’ and we can use them to ‘bridge’ the multicast stream between s1 and s4. Isn’t it cool?

Ludek Rozehnal
Author
Ludek Rozehnal
AWS Cloud Network Engineer & Terraform Expert with 20+ years’ experience. For the last 8+ years I’ve been the primary cloud network architect and IaC authority at Flextrade Systems (UK remote), where I designed and delivered fully automated global multi-region/multi-account AWS networking using Terraform and GitOps. I combine deep traditional networking knowledge with DevOps practices to eliminate manual processes, reduce risk, and accelerate cloud migrations — especially for low-latency, business-critical workloads. I’m passionate about sharing my expertise through blogging, open-source contributions, and speaking engagements. If you’re looking for guidance on AWS cloud networking or Terraform best practices, let’s connect!