Jan 132013
 Posted by on January 13, 2013 at 10:30 am FAQ, Linux  Add comments

Now that host A has two interfaces ( and in addition to the loopback interface (, we can observe how Linux will choose a source IP address to communicate with.

When an application starts, it has the option to bind to an IP address. If the application does not explicitly do so, Linux will automatically choose the IP address on behalf of the application on a connection-by-connection basis. When Linux is making the decision, it examines a connection’s destination IP address, makes a routing decision based on the current route table, and then selects the IP address corresponding to the interface that the connection will go out of. For example, if an application on host A makes a connection to, Linux will find that the packet should go out of the eth0 interface, and thus, the source IP address for the connection will be

Let us assume that the application does choose to bind to an IP address. If the application were to bind to, Linux will use that as the source IP address, regardless of which interface the connection will leave from. For example, if the application is bound to and a connection is made to, the connection will leave out of eth0 ( with the source IP address of It is now the responsibility of the remote host ( to know how to send a packet back to (Presumably, the default route for will know how to deal with that case.) For hosts that have aliased IP addresses, a single interface may have many IP addresses. For example, we can assign eth0:0 to, eth0:1 to, and eth0:2 to In this case, if the connection leaves from the eth0 interface and the application did not bind to a specific interface, Linux will always choose the nonaliased IP address, that is, for eth0. If the application did choose to bind to an IP address, say,, Linux will use that IP address as the source IP, regardless of whether the connection leaves from eth0 or eth1.

© Incase of any copyright infringements please check copyrights page for faster resolutions.

Leave a Reply

Show Buttons
Hide Buttons