backup static route on linux router

8,121

Solution 1

If you add 2 default routes with different metrics, this will switch the route only the case when main link is down and the other is up. The link is up (the interface status of the link) even if the router is not reachable. The link goes down only when the physical connection of the interface is down (e.g. no carrier detected, other out of band signaling).

What you really need is to detect when the remote router is down even if the link is up. This can be accomplished by using a dynamic routing protocol.

Another way would be to use a daemon or crontab script that will change the default route based on the reachability of the neighbor routers.

EDIT: The answer to your question is bellow. But this is not what you should configure to have redundancy.

ip route add default via R1 metric 100
ip route add default via R2 metric 200

If you need to make redundancy for the connection between R1 and R2 you should set LCAP as @growse wrote.

Solution 2

If you're just trying to achieve link resilience between your routers and your switch, then you're aiming at the wrong level in the OSI stack.

It sounds like you just need to bond the two NICs together on each router to make an ethernet trunk, and configure it on the switch. Either LACP or Etherchannel, depending on what the switch supports.

Share:
8,121

Related videos on Youtube

biggdman
Author by

biggdman

bigdinrock

Updated on September 18, 2022

Comments

  • biggdman
    biggdman over 1 year

    How do I set up a backup static route on a linux router. For example if I have 2 routers R1 and R2, connected through a switch, through two links:

     R1(eth1)->switch->R2(eth1)
     R1 (eth2)->switch->R2(eth2)
    

    Behind router R2 is a LAN(LAN A) How do I set two routes to LAN A from R1, one that uses a main next hop the eth1 from R2, and one that uses a secundary next hop the address from eth2 from R2. Something like when the main next hop is unavailable, the secondary route should be used. Could someone please help me? Thanks

    [EDIT] Should I use different metrics when creating the two routes?

    [EDIT2] Topology

  • biggdman
    biggdman over 12 years
    "If you add 2 default routes with different metrics, this will switch the route only the case when main link is down and the other is up"->that is exactly what I am trying to accomplish. Could you please help me out with what metric should I use and how. Thanks a lot
  • biggdman
    biggdman over 12 years
    I do not want a trunk connection, I just want when eth1 from R2 is down, the packet to travel using the second route(through eth2 of R2),and when eth1 of R2 is back up, to take that route
  • biggdman
    biggdman over 12 years
    I think the commands you wrote are exactly what i need. I edited and put an image of the topology i was trying to describe. I am trying to configure on R1 two routes to lan l: one that goes though eth1 of R2, and one that goes through eth2 of R2. By gets through i mean set the interface ip addr as the next hop