7

Let's say I have a machine with two network adapters on different subnets, eth0 (10.0.100.5) and eth1 (10.0.200.5). 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 10.0.150.5, or 173.194.43.102?
  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).

Clarifications:

  • 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
8

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

network : 10.0.100.5 mask : /8

This means your subnet is : 10.0.100.5/8

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 10.0.100.5/8
  • eth1 10.0.200.5/8

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

! NOTICE - 10.0.100.5/8 and 10.0.200.5/8 are same subnet (because mask masks last 3 occets, we can also write it as 10.0.0.0/8)

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

EDIT

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
0.0.0.0         192.168.0.1     0.0.0.0         UG    0      0        0 wlan0
10.0.0.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 wlan0

alternative routing table output

$ ip route show
default via 192.168.0.1 dev wlan0  proto static 
10.0.0.0/24 dev eth0  proto kernel  scope link  src 10.0.0.5 
192.168.0.0/24 dev wlan0  proto kernel  scope link  src 192.168.0.14 

So we have 2 interfaces in example above.

  • eth0 with IP 10.0.0.5 on subnet 10.0.0.5/255.255.255.0 or in CIDR notation 10.0.0.5/24
  • wlan0 with IP 192.168.0.14 on subnet 192.168.0.14/255.255.255.0 or in CIDR notation 192.168.0.0/24

Now what routing table tells us; line by line interpretation, bottom up:

192.168.0.0/24 dev wlan0 proto kernel scope link src 192.168.0.14

To access hosts in subnet 192.168.0.0/24 use interface wlan0 and src IP 192.168.0.14

10.0.0.0/24 dev eth0 proto kernel scope link src 10.0.0.5

To access hosts in subnet 10.0.0.0/24 use interface eth0 and src IP 10.0.0.5

default via 192.168.0.1 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 192.168.0.1

  • 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
0

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.