Enthusiasm never stops


Get default outgoing IP address and interface on Linux

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

This, of course, assumes that 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: via dev eth0  src

The output is pretty much self-explanatory — the route to “” will originate from device “eth0”, the used source IP address will be “”, and the next hop, the (default) gateway, will be “”.

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”.