Linux – backup static route on linux router

ipiptableslinuxnetworkingrouter

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

Best Answer

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.

Related Topic