How to choose network path with two internet connection
Jeffrey Ross
jeff at bubble.org
Sun Jun 5 15:19:04 UTC 2011
On 06/02/2011 10:51 AM, Armelius Cameron wrote:
> Hello,
> Suppose I have a laptop that has both Wired and Wireless connection.
> The Wired connection would be connected to LAN only. The Wireless
> connection would have full internet access. Obviously the two
> connections will have two different IP: a local IP address (e.g.
> 192.168.x.x) for the Wired, and a public IP address for the Wireless.
>
> How does an application know which network path to use ?
>
> For example, I want to be able to run SSH or Synergy to other machine
> on the LAN, so SSH would have to use the LAN network. But I also want
> to be able to run mail client that is connected to an IMAP server in
> the outside world, so my mail client have to use the Wireless network.
> How does something like this work ?
>
> Thanks.
> AC
>
The application(s) don't care which path you take they network stack
makes the decision first on what I refer to as the "longest match wins"
and then if there are multiple identical routes then route metrics can
come into play.
Lets say for example your two interfaces are:
int1 - 192.168.0.2/24
int2 - 192.168.1.2/24
and your default gateway is 192.168.0.1
You attempt to talk to a machine at 172.16.1.5, your machine will check
its routing table for the best match to reach the remote IP, in this
case 0.0.0.0 or the default is the only match.
lets say you add a static route to your system saying to reach
172.16.0.0/16 use the gateway 192.168.1.1
(actual syntax to add the route: "route add -net 172.16.0.0/16 gw
192.168.1.1") now when going to anything in the 172.16.0.0/16 subnet
you'll route your traffic via the 192.168.1.1 gateway since
172.16.0.0/16 is a better (longer) match than 0.0.0.0.
Say you want to reach all 172.16.0.0/16 traffic through the 192.168.1.1
gateway except the 172.168.1.5 host which needs to go through the
192.168.0.1 gateway, in that case you need to add a host route (syntax
"route add -host 172.168.1.5 gw 192.168.0.1)
notice the host route (or /32 bit network route) is more specific than
the "network" route so the more specific route always wins.
You can go so far as to say to reach the address range of
192.168.1.128/25 which is on a directly connected interface go via
192.168.0.1 with a simple network route.
hope that helps,
Jeff
More information about the users
mailing list