Let's say I have a machine with two network adapters on different subnets, eth0 ( and eth1 ( Assuming both subnets have routes to the internet (though their own NATs) and to the rest of the local network (though their own switches):

  1. How will Linux choose which network interface to use when making a request to, or
  2. Is there a way I can influence this at the network level? Would removing the routes from the subnets influence this? I'm in an AWS environment and working with an Appliance AMI that I can't log into, so something like this won't work.

AWS VPC environment, other machines running Ubuntu 12.04, no idea what the machine I'm trying to influence is running (since I can't log into it).


  • Both subnets are set up as /24s
  • for more info please provide output of route -n – Hrvoje Špoljar Nov 15 '14 at 23:35
  • As mentioned, I can't log into the box on question - later tonight I can spin up another one in the same configuration and check, though. – Dan Nov 15 '14 at 23:38

Subnet is defined by network and mask, e.g.

network : mask : /8

This means your subnet is :

Basically any valid IP of 10.xxx.xxx.xxx family belongs to this subnet. Only one interface can be used to access hosts in this subnet. So it's either eth0 or eth1 in your case. Other interface can have IP in same subnet, but it wont work properly.

Here is what happens if you have situation like you described with both eth0 and eth1 connected to same network with IPs on same subnet.

  • eth0
  • eth1

Now only one of those interfaces has route (let's say it's eth0) which says to access subnet use eth0. So packet leaving this interface will have source address

! NOTICE - and are same subnet (because mask masks last 3 occets, we can also write it as

So now consider we have host on this subnet which attempts to communicate with Packet enters system through eth1 but can't return from eth1 since eth0 is only one with route to network and responses from eth0 have different IP; so the one initiating connection to will not be able to understand response coming from some other source.


To determine which interface will be used you need to look at your routing table. Since question does not contain routing table I'll try to explain with following routing table

$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface         UG    0      0        0 wlan0   U     0      0        0 eth0   U     0      0        0 wlan0

alternative routing table output

$ ip route show
default via dev wlan0  proto static dev eth0  proto kernel  scope link  src dev wlan0  proto kernel  scope link  src 

So we have 2 interfaces in example above.

  • eth0 with IP on subnet or in CIDR notation
  • wlan0 with IP on subnet or in CIDR notation

Now what routing table tells us; line by line interpretation, bottom up: dev wlan0 proto kernel scope link src

To access hosts in subnet use interface wlan0 and src IP dev eth0 proto kernel scope link src

To access hosts in subnet use interface eth0 and src IP

default via dev wlan0 proto static

To access any other host not covered by rules above use default route, which is reachable using interface wlan0 and gateway to other networks is

  • Added clarification about the mask I'm using - sorry about the omission. – Dan Nov 15 '14 at 23:32
  • Can you clarify how the routing table impacts this? – Dan Nov 15 '14 at 23:39
  • check latest edited answer for more details – Hrvoje Špoljar Nov 15 '14 at 23:49

Look at your routing table - command is route. With the newer ip command use ip route show. You can look at help for either of these on how to add / delete routing entries in the table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.