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 ?