Skip to content

Instantly share code, notes, and snippets.

@PhilipSchmid
Last active February 11, 2025 08:02
Show Gist options
  • Save PhilipSchmid/2597c23c68f21d938779aa92683d30b2 to your computer and use it in GitHub Desktop.
Save PhilipSchmid/2597c23c68f21d938779aa92683d30b2 to your computer and use it in GitHub Desktop.
Testing Multicast Traffic on Linux

Testing Multicast Traffic on Linux

Prerequisites

By default Linux ignores Broadcast and Multicast ICMP messages. That's why you need to enable it first:

sysctl -w net.ipv4.icmp_echo_ignore_broadcasts=0

Join and Test Multicast Traffic

To join any mutlicast address (e.g. 224.10.10.10/24) just add it to your active interface (e.g. eth0) and append the keyword autojoin at the end:

ip addr add 224.10.10.10/24 dev eth0 autojoin

Now you can verify the join:

ip -f inet maddr show dev eth0

Finally to test the Multicast communication, ping to the chosen IP address from another host:

ping 224.10.10.10

You should now get an answer from your Multicast enabled host. That's it.

Change IGMP Version

The Linux Kernel normally uses IGMP version 3 to join Multicast groups. If you would rather use IGMP version 2, just change it via the command down here:

echo "2" > /proc/sys/net/ipv4/conf/eth0/force_igmp_version

Multicast Group Join Inside Docker Container

In order to get the commands above here working inside a Docker container, it must be started with the Linux capability NET_ADMIN:

docker run --rm -it --cap-add NET_ADMIN alpine /bin/sh

Fun fact: GNS3 starts all containers with all Linux capabilities added and in priviledged mode.

@dwinurhadia
Copy link

Hi Philip,
thanks for sharing your snippet gist,
I've testing in my ubuntu 21.04

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:15:5d:01:b6:27 brd ff:ff:ff:ff:ff:ff
    inet 10.55.254.126/24 brd 10.55.254.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 224.10.10.10/24 scope global autojoin eth0
       valid_lft forever preferred_lft forever

But when i've test ping to 224.10.10.10 its getting error

root@zu:/home/d# ping 224.10.10.10
ping: connect: Invalid argument

what's wrong with my config?

@lesurJ
Copy link

lesurJ commented Sep 13, 2022

Hi, same problem for me !

@Surya-ARBY
Copy link

Be sure to start a multicast ping from another host and the one from which you've bound to the multicast address. Also be sure to issue ping -t 16 224.10.10.10 otherwise all packets will leave with a TTL=1.

@Pengtai9928
Copy link

still seeing "connect: Invalid argument" after adding "-t 16" argument to ping

@Surya-ARBY
Copy link

is multicast correctly enabled on your system ?

@Pengtai9928
Copy link

do you mean set "sysctl -w net.ipv4.icmp_echo_ignore_broadcasts=0"?

@Surya-ARBY
Copy link

yes, the command given above works well on my ubuntu.

@Pengtai9928
Copy link

I see. Maybe there is some issue on my end. Thanks Surya

@pavelskipenes
Copy link

sudo sysctl -a | grep "net.ipv4.icmp_echo_ignore_broadcasts"
net.ipv4.icmp_echo_ignore_broadcasts = 0

ip -f inet maddr show dev ztmosn2bor
6:      ztmosn2bor
        inet  224.10.10.10
        inet  224.0.0.252
        inet  224.0.0.251 users 2
        inet  224.0.0.1

ip -c addr show dev ztmosn2bor
6: ztmosn2bor: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 2800 qdisc fq_codel state UNKNOWN group default qlen 1000
    link/ether 9a:05:17:7a:90:31 brd ff:ff:ff:ff:ff:ff
    inet 10.147.19.11/24 brd 10.147.19.255 scope global ztmosn2bor
       valid_lft forever preferred_lft forever
    inet 224.10.10.10/24 scope global autojoin ztmosn2bor
       valid_lft forever preferred_lft forever
    inet6 fe80::9805:17ff:fe7a:9031/64 scope link proto kernel_ll
       valid_lft forever preferred_lft forever

/usr/bin/ping -v -t 15 224.10.10.10
/usr/bin/ping: sock4.fd: 3 (socktype: SOCK_DGRAM), sock6.fd: 4 (socktype: SOCK_DGRAM), hints.ai_family: AF_UNSPEC

ai->ai_family: AF_INET, ai->ai_canonname: '224.10.10.10'
/usr/bin/ping: connect: Invalid argument

/usr/bin/ping -v 224.10.10.10
/usr/bin/ping: sock4.fd: 3 (socktype: SOCK_DGRAM), sock6.fd: 4 (socktype: SOCK_DGRAM), hints.ai_family: AF_UNSPEC

ai->ai_family: AF_INET, ai->ai_canonname: '224.10.10.10'
/usr/bin/ping: connect: Invalid argument

/usr/bin/ping -V
ping from iputils 20240905
libcap: yes, IDN: yes, NLS: yes, error.h: yes, getrandom(): yes, __fpending(): yes

connect: Invalid argument does not seem to be related to -t flag.

nc -u 224.10.10.10 42069

meanwhile

nc -u 224.0.0.1 42069

works but only on wlan0 interface in my case

@Surya-ARBY
Copy link

"hints.ai_family: AF_UNSPEC"

Address Family unspecified. The multicast address put in argument is not recognized.

@pavelskipenes
Copy link

No, not really. By passing in -4 hints.ai_family changes from AF_UNSPEC to AF_INET. However no matter if the flag is present or not it's getting detected correctly as ai->ai_family: AF_INET.

/usr/bin/ping -v -4 -t 15 224.10.10.10
/usr/bin/ping: sock4.fd: 3 (socktype: SOCK_DGRAM), sock6.fd: -1 (socktype: 0), hints.ai_family: AF_INET

ai->ai_family: AF_INET, ai->ai_canonname: '224.10.10.10'
/usr/bin/ping: connect: Invalid argument

@Surya-ARBY
Copy link

that's strange. the very same command works well on my ubuntu 22.04

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment