Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How does the kernel decide which route (of 2) to use?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
numerodix
l33t
l33t


Joined: 18 Jul 2002
Posts: 743
Location: nl.eu

PostPosted: Thu Jun 11, 2009 6:08 pm    Post subject: How does the kernel decide which route (of 2) to use? Reply with quote

Suppose you are connected to two networks on two interfaces. The networks are configured identically.
You get something like this:
Code:
$ /sbin/route  -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.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     2000   0        0 wlan0
127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
0.0.0.0         192.168.0.1     0.0.0.0         UG    2000   0        0 wlan0

So now a packet destined outside 192.168.{0,1} must travel either via 192.168.1.1 or 192.168.0.1, but the choice is arbitrary. It might turn out that one of them is a dead end, that past the gateway there's a network partition. Maybe that's why you're on two networks to begin with. So how does the kernel decide which gateway to use?
_________________
undvd - ripping dvds should be as simple as unzip
Back to top
View user's profile Send private message
Chaosite
Guru
Guru


Joined: 13 Dec 2003
Posts: 540
Location: Right over here.

PostPosted: Thu Jun 11, 2009 6:41 pm    Post subject: Reply with quote

When doing complex things with routing, you should use the iproute2 tools.

$ /sbin/ip route
10.0.0.0/24 dev eth2 proto kernel scope link src 10.0.0.127
127.0.0.0/8 dev lo scope link
default via 10.0.0.254 dev eth2

And the, suprising enough, answer is: the kernel uses the first route which is available to it. You can do more complex stuff than that, if you desire, though - there are several advanced routing HOWTOs on the net.
Back to top
View user's profile Send private message
Monkeh
Veteran
Veteran


Joined: 06 Aug 2005
Posts: 1656
Location: England

PostPosted: Thu Jun 11, 2009 6:46 pm    Post subject: Reply with quote

Uh, that's what the metric is for.
Back to top
View user's profile Send private message
Chaosite
Guru
Guru


Joined: 13 Dec 2003
Posts: 540
Location: Right over here.

PostPosted: Thu Jun 11, 2009 6:48 pm    Post subject: Reply with quote

Monkeh wrote:
Uh, that's what the metric is for.


... Really? What is the metric for, anyway?

manpage isn't very helpful with "set the metric field in the routing table (used by routing daemons) to M.".
Back to top
View user's profile Send private message
numerodix
l33t
l33t


Joined: 18 Jul 2002
Posts: 743
Location: nl.eu

PostPosted: Thu Jun 11, 2009 7:05 pm    Post subject: Reply with quote

manpage also says:

Code:
Metric The ’distance’ to the target (usually counted in hops). It is not  used
              by recent kernels, but may be needed by routing daemons.


@Chaosite
What makes iproute2 more worthwhile? Am I not getting the same info from "ip route" as I am from "route"?
_________________
undvd - ripping dvds should be as simple as unzip
Back to top
View user's profile Send private message
jdmulloy
Tux's lil' helper
Tux's lil' helper


Joined: 24 Dec 2004
Posts: 139
Location: Massachusetts, USA

PostPosted: Thu Jun 11, 2009 8:40 pm    Post subject: Reply with quote

So I'm thinking the question is basically, if both private networks have a gateway to say the public internet and one of them is down is the kernel smart enough to work around it?
_________________
Joe Mulloy | http://twitter.com/jdmulloy | Ron Paul in 2012! | 5-1-07 | Unban Playfool | Fire your "Too big to fail" bank http://moveyourmoney.info
Back to top
View user's profile Send private message
aidanjt
Veteran
Veteran


Joined: 20 Feb 2005
Posts: 1118
Location: Rep. of Ireland

PostPosted: Thu Jun 11, 2009 8:46 pm    Post subject: Reply with quote

It'll go by shortest (or only) route first. The kernel maintains different kinds of tables on the network state and make routing decisions based upon that.
_________________
juniper wrote:
you experience political reality dilation when travelling at american political speeds. it's in einstein's formulas. it's not their fault.
Back to top
View user's profile Send private message
numerodix
l33t
l33t


Joined: 18 Jul 2002
Posts: 743
Location: nl.eu

PostPosted: Thu Jun 11, 2009 9:12 pm    Post subject: Reply with quote

AidanJT wrote:
It'll go by shortest (or only) route first. The kernel maintains different kinds of tables on the network state and make routing decisions based upon that.

But before any traffic has been sent, it doesn't have any cached information. So what happens? Does it try one first, then the other if the first doesn't work?
_________________
undvd - ripping dvds should be as simple as unzip
Back to top
View user's profile Send private message
aidanjt
Veteran
Veteran


Joined: 20 Feb 2005
Posts: 1118
Location: Rep. of Ireland

PostPosted: Thu Jun 11, 2009 9:21 pm    Post subject: Reply with quote

numerodix wrote:
But before any traffic has been sent, it doesn't have any cached information. So what happens? Does it try one first, then the other if the first doesn't work?

Normally it sends out a RIP request first to update it's own tables, if it can't do that, then it falls back on the send'n'pray method and maintains routing tables by its sweet lonesome. But normally the route for a given network only has one interface path, unless we're talking about backbone routing of course.
_________________
juniper wrote:
you experience political reality dilation when travelling at american political speeds. it's in einstein's formulas. it's not their fault.
Back to top
View user's profile Send private message
bunder
Bodhisattva
Bodhisattva


Joined: 10 Apr 2004
Posts: 5947

PostPosted: Thu Jun 11, 2009 9:36 pm    Post subject: Reply with quote

shouldn't there be only one default gateway? :?
_________________
Neddyseagoon wrote:
The problem with leaving is that you can only do it once and it reduces your influence.

banned from #gentoo since sept 2017
Back to top
View user's profile Send private message
aidanjt
Veteran
Veteran


Joined: 20 Feb 2005
Posts: 1118
Location: Rep. of Ireland

PostPosted: Thu Jun 11, 2009 11:03 pm    Post subject: Reply with quote

bunder wrote:
shouldn't there be only one default gateway? :?

Nope, you can have multiple routes to the tubes.
_________________
juniper wrote:
you experience political reality dilation when travelling at american political speeds. it's in einstein's formulas. it's not their fault.
Back to top
View user's profile Send private message
Chaosite
Guru
Guru


Joined: 13 Dec 2003
Posts: 540
Location: Right over here.

PostPosted: Fri Jun 12, 2009 5:07 am    Post subject: Reply with quote

numerodix wrote:
@Chaosite
What makes iproute2 more worthwhile? Am I not getting the same info from "ip route" as I am from "route"?


http://lartc.org/howto/lartc.iproute2.html

Here's how to add a multipath route (google this term) using iproute2:

Code:
ip route add default nexthop via 10.0.0.1 dev eth0 nexthop via 10.1.0.1 dev wlan0


You can add weight to it too. Note that if your failures cause the interface to go down, you can just have 2 default routes, and once the interface goes down one of them will disappear. It's up to you to put it back once the interface goes back again.
Back to top
View user's profile Send private message
desultory
Bodhisattva
Bodhisattva


Joined: 04 Nov 2005
Posts: 9410

PostPosted: Fri Jun 12, 2009 7:52 am    Post subject: Reply with quote

Moved from Off the Wall to Networking & Security.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum