Suppose you have one or more network interfaces, and they have one or more assigned IP addresses, also called aliases. If you need to find out which IP address and interface will be used as a default “source” by your Linux box, you need to execute the following:
ip route get 126.96.36.199
This, of course, assumes that 188.8.131.52 is not directly connected on your networks somehow. Since this is one of the Public Name Servers of Google, I think it is safe to assume so.
A sample output of the ip command follows:
184.108.40.206 via 10.0.2.2 dev eth0 src 10.0.2.15 cache
The output is pretty much self-explanatory — the route to “220.127.116.11” will originate from device “eth0”, the used source IP address will be “10.0.2.15”, and the next hop, the (default) gateway, will be “10.0.2.2”.
This method is 100% reliable. The man page of “ip” says that “this command gets a single route to a destination and prints its contents exactly as the kernel sees it”.
- When IP aliasing how does the OS determine which IP address will be used as source for outbound TCP/IP connections?