linux多播不好用,可能是接口未开启多播,也有可能是内核忽略了了多播报文,具体操作如下:
在主机分别执行下面命令
1)查看接口是否启用了多播
In order to check whether multicast is enabled to a IP address :
$ ip add | grep MUL
如果未启用,启用命令如下:
$ ifconfig ethX multicast
2)编辑/etc/sysctl.conf文件,加入
#tell Linux to forward packets...
net.ipv4.ip_forward = 1
#启用多播
net.ipv4.icmp_echo_ignore_broadcasts = 0
sysctl -p #生效配置
3)加入多播路由(按实际添加)
We've enabled multicasting. Now, we have to tell the Linux kernel to actually do something with it, so we can start routing. This means adding the Multicast virtual network to the router table:
$ ip route add 224.0.0.0/4 dev eth0
3)加完后,执行下边命令
$ ping 224.0.0.1 #224.0.0.1为默认组播
PING 224.0.0.1 (224.0.0.1) 56(84) bytes of data.
64 bytes from 192.168.124.18: icmp_seq=1 ttl=64 time=0.076 ms
64 bytes from 192.168.124.21: icmp_seq=1 ttl=64 time=0.460 ms (DUP!)
所有在这个LAN里边的机器在收到这个多播后,会相应回复,下边为详细的解释:
At this point, you may be wondering if this is ever going to do anything. So, to test our connection, we ping the default group, 224.0.0.1, to see if anyone is alive. All machines on your LAN with multicasting enabled should respond, but nothing else. You'll notice that none of the machines that respond have an IP address of 224.0.0.1. What a surprise! :) This is a group address (a "broadcast" to subscribers), and all members of the group will respond with their own address, not the group address.
详细:http://www.jianshu.com/p/0871235d2ad1