I'm trying to test some multicast code on a single machine. I'm trying to get the packets sent over the loopback device (lo) instead of the default eth1. Googling keeps turning up the incantation

route add -net netmask dev lo
ifconfig lo multicast

but even after doing this the packets are still going out over eth1. Sample code (Python)

#!/usr/bin/env python
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(b'hello world', ('', 8888))

Output from tcpdump -i any 'udp port 8888':

10:28:28.957679 IP > UDP, length 11

where is the host address for eth1. I know I can use the IP_MULTICAST_IF socket option to force it (and this does work), but I'd prefer to be able to set routing policy once on the machine rather than in every application that does multicast.

I'm running Ubuntu 14.04 with kernel 3.13.0-68-generic.

  • You can test what route will be taken with ip route get It should say multicast dev lo .... Perhaps you need to clear the routing cache with ip route flush cache. – meuh Nov 18 '15 at 10:40
  • is not the route cache supposed to have a defined time to live...i.e. would there be a need to clear the routing cache? – Rui F Ribeiro Nov 18 '15 at 10:44
  • I did try flushing the cache: it didn't appear to make any difference. – Bruce Merry Nov 19 '15 at 7:16

It turns out that looking at IP addresses in tcpdump was misleading: it always seems to use as the source address, even when sending the packet over loopback. When specifying an interface to tcpdump I could tell which interface was actually used. The route was indeed working some of the time. This question describes a case where it doesn't work.

  • Interesting and duly noted. Often people forget the loopback is the route to talk with the server itself. – Rui F Ribeiro Nov 19 '15 at 8:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.