Choosing socket output interface: SO_BINDTODEVICE vs bind before connect
Source address doesn't affect routing of a packet. The interface will be selected based on the destination address and host's router table. You can modify it with route command.
route default gw [gateway IP]
No matter which interface the socket is bound, the packet is to be routed based on route table. The interface to which the socket is bound will determine the source ip address.
Now, I run some tests binding to loopback interface and connecting the socket to other address in the Internet and in that case connect failed with errno 22 (EINVAL). However, in other tests with two interfaces (none was loopback), and connecting to a server in the Internet, no matter which interface I bound the socket to, the packet was sent out according to the routing table, in my case following the default rule. The sources address depended on the bind.
Packet with Strict Source Route IP Option not being sent
It turns out that accept_source_route=1 was not set in sysctl. Instead, deny_source_route=0 was set - this was the default setting in Raspbian Jessie Lite.
Related Topics
How to Put All Command Arguments in One Variable
How to Add External References in Monodevelop
Selinux Prevented Httpd(Usr/Sbin/Httpd) Write Access to /Var/Www/HTML/Bookings/Templates_C
Host Multiple ASP.NET Core Web Application Under a Single Linux Server
Killing Stanford Core Nlp Process
Flutter PDF Viewer for Linux Desktop
Bash Concurrent Jobs Gets Stuck
Bluez: Setting Local Address to Be Private and Non-Resolvable
Udev-How to Get Value of a Child Device Attributes
Spawn_Id: Spawn Id Exp6 Not Open
Launching Sonar Scanner from a Gitlab Docker Runner
Adding Stackless Threading to Bsd Kernel
Logstash Too Many Files Opened
How to Cross-Compile a Autotools Project for Arm
Bash Linux - Massive Folder Rename