问题
TLDR: Is there a way to use "ip route" to add multicast routes for multiple NICs?
We have software that joins two sockets bound to different ip addresses on separate NICS to two separate multicast groups, eg socket 1 is bound to 192.168.0.2 and joined to multicast group 233.255.10.1 while socket 2 is bound to 10.57.31.2 and joined to multicast group 239.255.100.1.
We are currently using a bash script (Linux kernel 3.14.39) to set multicast routes on the two network interfaces using route, eg
route add -net 224.0.0.0 netmask 240.0.0.0 eth0
route add -net 224.0.0.0 netmask 240.0.0.0 eth1
and verified via route -n
Destination Gateway Genmask Flags Metric Ref Use Iface
224.0.0.0 0.0.0.0 240.0.0.0 U 0 0 0 eth0
224.0.0.0 0.0.0.0 240.0.0.0 U 0 0 0 eth1
I recently read that route was deprecated/obsolete and that we should be using ip route instead, eg
ip route add 224.0.0.0/4 dev eth0
ip route add 224.0.0.0/4 dev eth1
Unfortunately, the second call fails with "RTNETLINK answers: File exists" and of course the second route doesn't show up after these calls.
Is there a way to use ip route to add multicast routes to multiple NICs?
I can use /8 as a netmask? eg
ip route add 233.0.0.0/8 dev eth0
and
ip route add 239.0.0.0/8 dev eth1
but this is problematic as the script that does this is not aware of what multicast address is associated with which device and its not always guaranteed to be the same depending on system configuration. Using my first example of route add makes this a non issue.
来源:https://stackoverflow.com/questions/40391890/use-ip-route-add-to-add-multicast-routes-to-multiple-devices