Use ip route add to add multicast routes to multiple devices

两盒软妹~` 提交于 2020-01-03 13:34:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!