Two default gw in kernel routing table - Networking

This is a discussion on Two default gw in kernel routing table - Networking ; Hi, If I have two default gw in kernel routing table, in any given time, which rule will be used first? The same as displayed in route command? Or has a random order, each one will have the oppotunity to ...

+ Reply to Thread
Results 1 to 17 of 17

Thread: Two default gw in kernel routing table

  1. Two default gw in kernel routing table

    Hi,

    If I have two default gw in kernel routing table, in any given time,
    which rule will be used first? The same as displayed in route command?
    Or has a random order, each one will have the oppotunity to be used?
    Or each time both will be tried?

    Thanks.
    ABAI


  2. Re: Two default gw in kernel routing table

    On 12 Feb 2007, in the Usenet newsgroup comp.os.linux.networking, in article
    <1171277254.354482.118340@s48g2000cws.googlegroups. com>, Binary wrote:

    >If I have two default gw in kernel routing table, in any given time,


    you will run into problems.

    >which rule will be used first?


    The one with the lower metric. Assuming the metrics are the same, then
    the _last_ defined route will be used, because there kernel assumes you
    changed your mind and thought of a better solution. The other "default"
    routes will be ignored.

    >The same as displayed in route command? Or has a random order, each
    >one will have the oppotunity to be used? Or each time both will be tried?


    Rather than guessing - you _could_ try using a search engine, as this
    question is constantly asked again, and again, and again, and again, and...

    I'm guessing that English isn't your first language. The word "default"
    has a number of meanings - and the common dictionary meanings are not
    the one used in networking. Rather, the meaning is that of the programmer
    when given a choice or selection. If choice "A" is best, use choice "A".
    If choice "B" is best, use choice "B". If choice "C" is best, use choice
    "C". If neither "A", "B", or "C" is correct, use the "default". This
    means that there can only be _one_ default.

    Old guy

  3. Re: Two default gw in kernel routing table

    ibuprofin@painkiller.example.tld (Moe Trin) wrote:
    >On 12 Feb 2007, in the Usenet newsgroup comp.os.linux.networking, in article
    ><1171277254.354482.118340@s48g2000cws.googlegroups. com>, Binary wrote:
    >
    >>If I have two default gw in kernel routing table, in any given time,

    >
    >you will run into problems.


    Not really... ;-)

    >>which rule will be used first?

    >
    >The one with the lower metric. Assuming the metrics are the same, then
    >the _last_ defined route will be used, because there kernel assumes you
    >changed your mind and thought of a better solution. The other "default"
    >routes will be ignored.
    >
    >>The same as displayed in route command? Or has a random order, each
    >>one will have the oppotunity to be used? Or each time both will be tried?


    Use the "route" command to see what the kernel route table looks
    like. The route used for any given destination is the *first*
    one that matches as it scans down the routing table. Hence, if
    you have two "default" routes, one of the them will *never* be
    reached, because everything that makes it all the way to the
    first "default" will in fact be routed by that entry.

    --
    Floyd L. Davidson
    Ukpeagvik (Barrow, Alaska) floyd@apaflo.com

  4. Re: Two default gw in kernel routing table

    > >>If I have two default gw in kernel routing table, in any given time,
    >
    > >you will run into problems.

    >
    > Not really... ;-)
    >
    > >>which rule will be used first?

    >
    > >The one with the lower metric. Assuming the metrics are the same, then
    > >the _last_ defined route will be used, because there kernel assumes you
    > >changed your mind and thought of a better solution. The other "default"
    > >routes will be ignored.

    >
    > >>The same as displayed in route command? Or has a random order, each
    > >>one will have the oppotunity to be used? Or each time both will be tried?

    >
    > Use the "route" command to see what the kernel route table looks
    > like. The route used for any given destination is the *first*
    > one that matches as it scans down the routing table. Hence, if
    > you have two "default" routes, one of the them will *never* be
    > reached, because everything that makes it all the way to the
    > first "default" will in fact be routed by that entry.
    >
    > --
    > Floyd L. Davidson


    I'm wondering what U mean writing multiple default routes.
    Look here

    root@sdnet:~# ip r s
    default
    nexthop via 193.X.X.X dev eth2 weight 1
    nexthop via 80.Y.Y.X dev eth3 weight 1

    It's some snap form my running routing table.
    Metrics are the same, none of default routes is never, because both
    are added by one command.
    So what now?
    Route via dev eth2 will always be used? No!
    Linux will use both of then dividing traffic between links in
    proportion shown by weights.

    HF
    MR


  5. Re: Two default gw in kernel routing table

    "Binary" writes:

    >Hi,


    >If I have two default gw in kernel routing table, in any given time,
    >which rule will be used first? The same as displayed in route command?


    No first. There is only one. the last one implimented. There is never any
    other used.

    >Or has a random order, each one will have the oppotunity to be used?
    >Or each time both will be tried?


    HOw would it do that?


    >Thanks.
    >ABAI



  6. Re: Two default gw in kernel routing table

    On Mon, 12 Feb 2007, Floyd L. Davidson wrote:

    > Use the "route" command to see what the kernel route table looks
    > like. The route used for any given destination is the *first*
    > one that matches as it scans down the routing table. Hence, if
    > you have two "default" routes, one of the them will *never* be
    > reached, because everything that makes it all the way to the
    > first "default" will in fact be routed by that entry.


    I'm told (google) that the second one would get used if the first gateway
    drops dead. Is that wrong?

    -s

  7. Re: Two default gw in kernel routing table

    On 12 Feb 2007, in the Usenet newsgroup comp.os.linux.networking, in article
    <1171313418.808207.193600@h3g2000cwc.googlegroups.c om>, M4teK wrote:

    >>>> If I have two default gw in kernel routing table, in any given time,

    >>
    >>> you will run into problems.

    >>
    >> Not really... ;-)


    Web Results 1 - 10 of about 20,300,000 for Linux two+default. (0.12
    seconds)

    Web Results 1 - 10 of about 1,110,000 for Linux two+default+gateway.
    (0.14 seconds)

    Web Results 1 - 10 of about 1,130,000 for Linux two+default+route.
    (0.10 seconds)

    Yeah - no one EVER has problems with two default routes.

    >> Use the "route" command to see what the kernel route table looks
    >> like. The route used for any given destination is the *first*
    >> one that matches as it scans down the routing table.


    >I'm wondering what U mean writing multiple default routes.


    I'm wondering what you mean?

    >Look here
    >
    >root@sdnet:~# ip r s


    '/sbin/ip' is not the '/sbin/route' command. You'll want to re-read the
    ip-cref document.

    > nexthop via 193.X.X.X dev eth2 weight 1
    > nexthop via 80.Y.Y.X dev eth3 weight 1
    >

    >It's some snap form my running routing table.
    >Metrics are the same, none of default routes is never, because both
    >are added by one command.
    >So what now?
    >Route via dev eth2 will always be used? No!
    >Linux will use both of then dividing traffic between links in
    >proportion shown by weights.


    See the Advanced Routing HOWTO for additional details. Your routing
    table is lacking the policy information.

    Old guy


  8. Re: Two default gw in kernel routing table

    On Tue, 13 Feb 2007, in the Usenet newsgroup comp.os.linux.networking, in
    article , Steve Thompson
    wrote:

    >Floyd L. Davidson wrote:


    >> Use the "route" command to see what the kernel route table looks
    >> like. The route used for any given destination is the *first*
    >> one that matches as it scans down the routing table. Hence, if
    >> you have two "default" routes, one of the them will *never* be
    >> reached, because everything that makes it all the way to the
    >> first "default" will in fact be routed by that entry.

    >
    >I'm told (google) that the second one would get used if the first gateway
    >drops dead. Is that wrong?


    Only if you are using a routing daemon, such as 'routed' or 'gated' to
    manage your routing table. Of course, the Advanced Routing HOWTO can
    let you do "interesting" things in load-balancing, but that's not a
    very common setup.

    Old guy


  9. Re: Two default gw in kernel routing table

    Steve Thompson writes:

    >On Mon, 12 Feb 2007, Floyd L. Davidson wrote:


    >> Use the "route" command to see what the kernel route table looks
    >> like. The route used for any given destination is the *first*
    >> one that matches as it scans down the routing table. Hence, if
    >> you have two "default" routes, one of the them will *never* be
    >> reached, because everything that makes it all the way to the
    >> first "default" will in fact be routed by that entry.


    >I'm told (google) that the second one would get used if the first gateway
    >drops dead. Is that wrong?


    How does it "drop dead"? I have no idea if it would fall back, but I doubt
    it. Why not try it? choose as your second gateway some non-existant IP and
    see if there is any fallback.




  10. Re: Two default gw in kernel routing table

    ibuprofin@painkiller.example.tld (Moe Trin) writes:

    >On 12 Feb 2007, in the Usenet newsgroup comp.os.linux.networking, in article
    ><1171313418.808207.193600@h3g2000cwc.googlegroups.c om>, M4teK wrote:


    >>>>> If I have two default gw in kernel routing table, in any given time,
    >>>
    >>>> you will run into problems.
    >>>
    >>> Not really... ;-)


    > Web Results 1 - 10 of about 20,300,000 for Linux two+default. (0.12
    > seconds)


    > Web Results 1 - 10 of about 1,110,000 for Linux two+default+gateway.
    > (0.14 seconds)


    > Web Results 1 - 10 of about 1,130,000 for Linux two+default+route.
    > (0.10 seconds)


    >Yeah - no one EVER has problems with two default routes.


    >>> Use the "route" command to see what the kernel route table looks
    >>> like. The route used for any given destination is the *first*
    >>> one that matches as it scans down the routing table.


    >>I'm wondering what U mean writing multiple default routes.


    >I'm wondering what you mean?


    >>Look here
    >>
    >>root@sdnet:~# ip r s


    >'/sbin/ip' is not the '/sbin/route' command. You'll want to re-read the
    >ip-cref document.


    >> nexthop via 193.X.X.X dev eth2 weight 1
    >> nexthop via 80.Y.Y.X dev eth3 weight 1
    >>

    >>It's some snap form my running routing table.
    >>Metrics are the same, none of default routes is never, because both
    >>are added by one command.
    >>So what now?
    >>Route via dev eth2 will always be used? No!
    >>Linux will use both of then dividing traffic between links in
    >>proportion shown by weights.


    >See the Advanced Routing HOWTO for additional details. Your routing
    >table is lacking the policy information.


    > Old guy



    Just tried it. I added a second default route to my system with the gateway
    being a non-existant IP on my second network I thus had two routes. I now
    tried to get to some machine. I could not. It did NOT use the other default
    route. It tried to use the non-existant gateway, and told me it could not
    get to it. Using two default routes does not work. There is onlyone default
    route-- the last one added. And if it dies, your routing dies with it.


  11. Re: Two default gw in kernel routing table

    ibuprofin@painkiller.example.tld (Moe Trin) wrote:
    >On 12 Feb 2007, in the Usenet newsgroup comp.os.linux.networking, in article
    ><1171313418.808207.193600@h3g2000cwc.googlegroups.c om>, M4teK wrote:
    >
    >>>>> If I have two default gw in kernel routing table, in any given time,
    >>>
    >>>> you will run into problems.
    >>>
    >>> Not really... ;-)

    >
    > Web Results 1 - 10 of about 20,300,000 for Linux two+default. (0.12
    > seconds)
    >
    > Web Results 1 - 10 of about 1,110,000 for Linux two+default+gateway.
    > (0.14 seconds)
    >
    > Web Results 1 - 10 of about 1,130,000 for Linux two+default+route.
    > (0.10 seconds)
    >
    >Yeah - no one EVER has problems with two default routes.


    They *don't* have a problem with two default routes though!

    They just have a small problem of not understanding that in fact
    they only have *one* default route.

    --
    Floyd L. Davidson
    Ukpeagvik (Barrow, Alaska) floyd@apaflo.com

  12. Re: Two default gw in kernel routing table

    Steve Thompson wrote:
    >On Mon, 12 Feb 2007, Floyd L. Davidson wrote:
    >
    >> Use the "route" command to see what the kernel route table looks
    >> like. The route used for any given destination is the *first*
    >> one that matches as it scans down the routing table. Hence, if
    >> you have two "default" routes, one of the them will *never* be
    >> reached, because everything that makes it all the way to the
    >> first "default" will in fact be routed by that entry.

    >
    >I'm told (google) that the second one would get used if the
    >first gateway drops dead. Is that wrong?


    It will be used if and only if the first one is removed from the
    route table.

    --
    Floyd L. Davidson
    Ukpeagvik (Barrow, Alaska) floyd@apaflo.com

  13. Re: Two default gw in kernel routing table

    On Wed, 14 Feb 2007, in the Usenet newsgroup comp.os.linux.networking, in
    article , Unruh wrote:

    >(Moe Trin) writes:


    >> M4teK wrote:


    >>>Look here
    >>>
    >>>root@sdnet:~# ip r s

    >
    >>'/sbin/ip' is not the '/sbin/route' command. You'll want to re-read the
    >>ip-cref document.


    That goes for you too, Bill.

    >>> nexthop via 193.X.X.X dev eth2 weight 1
    >>> nexthop via 80.Y.Y.X dev eth3 weight 1
    >>>


    >>>Linux will use both of then dividing traffic between links in
    >>>proportion shown by weights.

    >
    >>See the Advanced Routing HOWTO for additional details. Your routing
    >>table is lacking the policy information.


    >Just tried it. I added a second default route to my system with the
    >gateway being a non-existant IP on my second network I thus had two
    >routes.


    And you added the second route exactly how? Did you use the 'ip' tool
    rather than '/sbin/route' ? Did you set up policy as it's detailed in
    the Advanced Routing HOWTO?

    >I now tried to get to some machine. I could not. It did NOT use the
    >other default route. It tried to use the non-existant gateway, and
    >told me it could not get to it. Using two default routes does not
    >work. There is onlyone default route-- the last one added. And if it
    >dies, your routing dies with it.


    -rw-rw-r-- 1 gferg ldp 297491 Sep 4 2003 Adv-Routing-HOWTO

    Any sunsite mirror - and should be on your system if you installed the
    HOWTO package. I'm not sure whether Mandriva includes the 'iproute'
    package, but if not, you can find it on sourceforge using a google
    search. Also: http://developer.osdl.org/dev/iproute2/

    Description:
    The iproute package contains networking utilities (ip and rtmon,
    for example) which are designed to use the advanced networking
    capabilities of the Linux 2.4.x and 2.6.x kernel.

    There is a document in the package called "ip-cref" which is the "IP
    Command Reference".

    Old guy

  14. Re: Two default gw in kernel routing table

    ibuprofin@painkiller.example.tld (Moe Trin) writes:

    >On Wed, 14 Feb 2007, in the Usenet newsgroup comp.os.linux.networking, in
    >article , Unruh wrote:


    >>(Moe Trin) writes:


    >>> M4teK wrote:


    >>>>Look here
    >>>>
    >>>>root@sdnet:~# ip r s

    >>
    >>>'/sbin/ip' is not the '/sbin/route' command. You'll want to re-read the
    >>>ip-cref document.


    >That goes for you too, Bill.


    >>>> nexthop via 193.X.X.X dev eth2 weight 1
    >>>> nexthop via 80.Y.Y.X dev eth3 weight 1
    >>>>


    >>>>Linux will use both of then dividing traffic between links in
    >>>>proportion shown by weights.

    >>
    >>>See the Advanced Routing HOWTO for additional details. Your routing
    >>>table is lacking the policy information.


    >>Just tried it. I added a second default route to my system with the
    >>gateway being a non-existant IP on my second network I thus had two
    >>routes.


    >And you added the second route exactly how? Did you use the 'ip' tool
    >rather than '/sbin/route' ? Did you set up policy as it's detailed in
    >the Advanced Routing HOWTO?


    Using route.

    route add default gw 192.168.0.7
    which is an IP on my internal network which does not exist.


    Exactly which policy do you recommend? Otherwise yours is a typical
    obfuscation-- "Here is a 2000 page book -- read it".
    Maybe there is something relevant there, but then it is also up to you to
    tell me how.

    So you are claiming exactly what of relevance to the OP problem?


    >>I now tried to get to some machine. I could not. It did NOT use the
    >>other default route. It tried to use the non-existant gateway, and
    >>told me it could not get to it. Using two default routes does not
    >>work. There is onlyone default route-- the last one added. And if it
    >>dies, your routing dies with it.


    >-rw-rw-r-- 1 gferg ldp 297491 Sep 4 2003 Adv-Routing-HOWTO


    >Any sunsite mirror - and should be on your system if you installed the
    >HOWTO package. I'm not sure whether Mandriva includes the 'iproute'
    >package, but if not, you can find it on sourceforge using a google
    >search. Also: http://developer.osdl.org/dev/iproute2/


    > Description:
    > The iproute package contains networking utilities (ip and rtmon,
    > for example) which are designed to use the advanced networking
    > capabilities of the Linux 2.4.x and 2.6.x kernel.


    >There is a document in the package called "ip-cref" which is the "IP
    >Command Reference".


    And? This is relevant how?



  15. Re: Two default gw in kernel routing table

    On Thu, 15 Feb 2007, in the Usenet newsgroup comp.os.linux.networking, in
    article , Unruh wrote:

    >ibuprofin@painkiller.example.tld (Moe Trin) writes:


    >> Unruh wrote:


    >>> (Moe Trin) writes:


    >>>>'/sbin/ip' is not the '/sbin/route' command.


    >>>Just tried it. I added a second default route to my system with the
    >>>gateway being a non-existant IP on my second network I thus had two
    >>>routes.

    >
    >>And you added the second route exactly how? Did you use the 'ip' tool
    >>rather than '/sbin/route' ? Did you set up policy as it's detailed in
    >>the Advanced Routing HOWTO?

    >
    >Using route.


    Ah, Bill... In a logical statement, when I write "'/sbin/ip' is not the
    '/sbin/route' command." as above, this means the converse is true as well.
    Please read the man page for "ip" NOT "route" and use the proper tool.

    [compton ~]$ whatis ip route
    ip (8) - show / manipulate routing, devices, policy routing and tunnels
    route (8) - show / manipulate the IP routing table
    [compton ~]$

    They really are separate tools with quite different capabilities.

    >Exactly which policy do you recommend? Otherwise yours is a typical
    >obfuscation-- "Here is a 2000 page book -- read it".
    >Maybe there is something relevant there, but then it is also up to you to
    >tell me how.


    -rw-rw-r-- 1 gferg ldp 297491 Sep 4 2003 Adv-Routing-HOWTO

    [compton ~]$ zwc /usr/share/HOWTO/Adv-Routing-HOWTO.gz
    6006 37363 296051
    [compton ~]$

    No Bill, it's not my job to tell you how. That's why it's called a HOWTO.
    Here's a hint:

    This document hopes to enlighten you on how to do more with Linux 2.2/2.4
    routing. Unbeknownst to most users, you already run tools which allow you
    to do spectacular things. Commands like route and ifconfig are actually
    very thin wrappers for the very powerful iproute2 infrastructure.

    The actual section you need to read is "4.2 Routing for multiple
    uplinks/providers" which is about 110 lines long including the ASCII art
    picture and several examples. For that matter, the man page for 'ip (8)'
    is only about a quarter of the size of the HOWTO, but it refers you to the
    'tc (8)' man page which is another 460 lines of text - including a "Theory
    of Operation" section. It's also part of the iproute package.

    [compton ~]$ whatis tc
    tc (8) - show / manipulate traffic control settings
    [compton ~]$

    >So you are claiming exactly what of relevance to the OP problem?


    Peruse the thread - it's not the O/P who was suggesting the 'ip' command
    which will allow multiple defaults. The O/P was posting a homework question
    which everyone correctly answered using conventional answers relating to the
    route command. A DIFFERENT POSTER brought up the 'ip' command which will
    permit multiple gateways.

    >>There is a document in the package called "ip-cref" which is the "IP
    >>Command Reference".

    >
    >And? This is relevant how?


    Well, you won't know until you look at the document, will you? Do you have
    it installed? Try 'rpm -qd iproute' and see what it returns.

    Old guy


  16. Re: Two default gw in kernel routing table

    "Binary" writes:

    >Hi,


    >If I have two default gw in kernel routing table, in any given time,
    >which rule will be used first? The same as displayed in route command?
    >Or has a random order, each one will have the oppotunity to be used?
    >Or each time both will be tried?


    The last one set up.


  17. Re: Two default gw in kernel routing table

    Steve Thompson writes:

    >On Mon, 12 Feb 2007, Floyd L. Davidson wrote:


    >> Use the "route" command to see what the kernel route table looks
    >> like. The route used for any given destination is the *first*
    >> one that matches as it scans down the routing table. Hence, if
    >> you have two "default" routes, one of the them will *never* be
    >> reached, because everything that makes it all the way to the
    >> first "default" will in fact be routed by that entry.


    >I'm told (google) that the second one would get used if the first gateway
    >drops dead. Is that wrong?


    It is wrong in general It can be set up something like that if you use the
    new ip command, not the route command. But others will need to tell you
    how. (Or apparently you can read the docs and burried in there somewhere
    may be the instructions/hints how to do so.)


    >-s


+ Reply to Thread