[wellylug] Network broadcasts on second Ethernet interface

David Antliff david.antliff at gmail.com
Tue May 20 11:15:18 NZST 2008


Hello,

I am working with a proprietary network discovery protocol. I have a
Python script that sends out a UDP broadcast (to address
255.255.255.255, port 26005) and I'm using sendto() to send the
packet:

    target_address = ('255.255.255.255',26005)
    host = ''
    port = 2600

    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    s.bind((host, port))

    try:
        s.sendto("data", target_address)
            # Wait for response
            r, w, e = select.select([s], [], [], 10)
            ...


I have two network cards in the Linux machine - eth0 configured to
10.16.x.x/16, eth1 to 192.168.0.x/24. Both eth0 and eth1 are
operational.

No target hosts on my 192.168.0.0 network are responding to the
broadcast, so I used WireShark to determine if my packet is being
broadcast on both interfaces. It seems that the packet is only
broadcast on interface eth0, but eth1 is silent.

I've replicated the scenario on a Windows PC and the broadcast leaves
both interfaces instead.

The statement [host = ''] is meant to bind to all interfaces, but I
believe this is for incoming packets only (listen).

Apparently it's a Linux feature that only one interface is used for
outgoing broadcasts. The interface choice is made by the OS and it is
not random, but from what I gather it's pretty close to it. It turns
out to be eth0 in most cases.

Does anyone know how to configure Linux so that the broadcasts leave
on both interfaces? Or at least change the default to broadcast on
eth1?

I've read about 'bonding' but I'm not sure that it's the correct
solution, as I need to maintain two separate subnets.

Regards,
David.



More information about the wellylug mailing list