0

There are 2 NICs (network interface cards) with IPs IP0 and IP1 as primary addresses given to them as seen in the kernel routing table via ip route. Say a TCP socket is bound to IP0 (and some port P0). So it will receive packets destined to IP0:P0 and this part I understand. When it wants to send out data to Destination IP-Dest:Port-Dest, the kernel routing table says this should ultimately go via the other NIC with primary IP as IP1. I want to know what is the rule in such cases. Does the kernel drop the packet as the sender (the socket) was bound to a different NIC with different IP (IP0) or does it send it via the other NIC but ignore the IP associated with it (IP1) and instead stamp the source IP as IP0 to which the socket was bound or (the other way around) ignore IP0 and stamp the source as IP1 while still sending over the other NIC or are there other rules that govern the behaviour here and results could vary ?

A follow up question: when binding to all interfaces via 0.0.0.0 and port 0, is the same (whatever kernel chooses) port number chosen for all interfaces for this socket or there is no such guarantee and it could choose IP0:P0 and IP1:P1 where P0 != P1 or does it depend on protocol or some other factor ?

1 Answers1

0

If the application binds to 0.0.0.0 the ports will be the same for all interfaces.

Still the routing is getting tricky when binding to 0.0.0.0. Often software generates the packets then with 0.0.0.0 source in IP SRC. This leads to ending up on the default routing table, which is typically the first interfaces gateway/subnet.

Therefore it is needed to setup two independent routing tables:

https://serverfault.com/a/823061/476056

And specify routing based on destination for the interfaces

https://serverfault.com/a/918875/476056

hargut
  • 3,848
  • 6
  • 10
  • Pls note that in my primary question, the socket is not bound to 0.0.0.0. It's bound only to `IP0` and sends out something to `IP-Dest` which from the routing table should go out of the other NIC with other IP `IP1`. What happens in this case (pls see the question for more details) ? – ustulation Jan 06 '20 at 22:17