A CentOS 5 system does not appear to come out-of-the-box with a route for multicast traffic. What it does appear to do is use a default route, if configured. In other words, a routing table like this:
# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
10.42.128.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 10.42.128.1 0.0.0.0 UG 0 0 0 eth0
will work with my Java-based multicast client application (or the test case below), which expects to be able to send to a site-local multicast address.
This setup works. If I don't have a default route, e.g.
Destination Gateway Genmask Flags MSS Window irtt Iface
10.42.128.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
my Java application will fail when it tries to send. I can correct this by adding the multicast route:
# route add -net 224.0.0.0/4 via eth0
And to do the above permanently:
# echo 224.0.0.0/4 via eth0 >>/etc/sysconfig/network-scripts/route-eth0
Should I be creating this route anyway? Is there any harm in letting the default route handle multicast traffic, other than the fact that it would stop working if the default route went away?
Here is a short test case which can be run by executing javac Sender.java; java Sender
. It sends a 0-byte UDP packet to the site-local address 239.192.0.1. If I have no default route in place, it will fail with
Exception in thread "main" java.io.IOException: Network is unreachable
at java.net.PlainDatagramSocketImpl.send(Native Method)
at java.net.DatagramSocket.send(DatagramSocket.java:629)
at Sender.main(MulticastSender.java:7)
However, if a default route (or the multicast route I mention above) is present, it will successfully send the packet to 239.192.0.1.
Sender.java
import java.net.*;
class Sender {
public static void main(String[] args) throws Throwable {
MulticastSocket socket = new MulticastSocket();
InetAddress groupAddress = InetAddress.getByName("239.192.0.1");
socket.send(new DatagramPacket(new byte[0], 0, groupAddress, 9999));
}
}