linux多播不好用,可能是接口未開啟多播箕昭,也有可能是內(nèi)核忽略了了多播報文,具體操作如下:
在主機分別執(zhí)行下面命令
? ?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)加完后友扰,執(zhí)行下邊命令
? $ ping 224.0.0.1 ?#224.0.0.1為默認(rèn)組播
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里邊的機器在收到這個多播后,會相應(yīng)回復(fù)晤斩,下邊為詳細的解釋:
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.reibang.com/p/0871235d2ad1