Which IP does an interface use when the host acts as a client?
Let's say I have configured eth0 with 2 IP addresses: 192.168.1.7 and 192.168.1.8
The route command shows something like this:
$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.240.0 0.0.0.0 255.255.240.0 U 256 0 0 eth0
...
This basically means that when I try to connect to any host from the 192.168.240.0 network it uses the eth0 interface. Ok, but... Which IP address from that interface?
If the host acts as a server and a client connects to my computer using the IP address 192.168.1.7 I understand that eth0 will use 192.168.1.7 to communicate with the client, but what if I am the client?
EDIT
The IP addresses are made up, I can't add another IP address to an interface in my Ubuntu WSL because I get this error:
$ ip address add 192.168.1.7/24 dev eth0
RTNETLINK answers: Permission denied
The output of ip r s is something like this:
$ ip r s
none 224.0.0.0/4 dev eth0 proto unspec metric 256
none 255.255.255.255 dev eth0 proto unspec metric 256
none 224.0.0.0/4 dev eth1 proto unspec metric 256
none 255.255.255.255 dev eth1 proto unspec metric 256
...
EDIT 2
I upgraded to WSL2 and now the command to add ip addresses work (with sudo).
$ ip -4 a s dev eth0
4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
inet 192.168.249.181/20 brd 192.168.255.255 scope global eth0
valid_lft forever preferred_lft forever
inet 192.168.1.7/24 scope global eth0
valid_lft forever preferred_lft forever
inet 192.168.1.8/24 scope global secondary eth0
valid_lft forever preferred_lft forever