Bind Outgoing Traffic to Eth0 Instead of Eth0:1

Java Socket specify a certain network interface for outgoing connections

This is the result of the 'weak end system model'. It's too broad to describe here but it is discussed in RFC 1122.

capturing both incoming and outgoing packets using raw socket

I have found this while searching over your problem. I haven't tried this. May be this will work.

  int v=0;
v = PACKET_MASK_ANY & ~(1<<PACKET_OUTGOING) & ~(1 << PACKET_LOOPBACK);
setsockopt( raw_sock, SOL_PACKET, PACKET_RECV_TYPE, &v, sizeof(v));

Can Python select what network adapter when opening a socket?

On Windows, if you know the IP address of the interface you want to use, just bind to that before you connect. On Linux,use socket option SO_BINDTODEVICE as suggested by JimB (seems to be a privileged call too).

i.e. on Windows

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('192.168.0.1', 0))
s.connect(('...'))

Binding source address under Windows, selects the interface with the same IP address as that device, even if that IP address has a higher routing metric cost. This doesn't work under Linux though, as it always overwrites the source address with the IP address of the selected device. Routing is done based solely on the destination address. The only exception it seems is if you set source address to 127.0.0.1, then Linux prevents these packets from going out of that box.



Related Topics



Leave a reply



Submit