1

Currently I am using Alma-Linux, where I need to create 2 default gateways for the same NIC. Main intent of 2 default gateway configuration is.. when any one of the gateways is down then it will fall back to other working gateway

Gateway Configuration Below IPs are used for routing

  1. 11.12.13.2 (default gateway - with lower metric value 30)
  2. 11.12.13.1 (default gateway configured via static route - with higher metric value 40)

Both IPs are ping-able.

For testing fail over scenario, I disabled the gateway ip with lower metrics IP(11.12.13.2) and performed the traceroute command on a random remote host which is in different subnet.

command : traceroute 17.18.19.2

but traceroute result is destination unreachable.

In this scenario, I assume packets will go through default gateway route 11.12.13.1 ip as a fall back option. since configured gateway is down. It is not working as I expected.

Note: In windows, gateway fall back is happening irrespective of metric values.

  • Why ask a new question when there was https://serverfault.com/questions/1141388/alma-linux-static-route-configuration-is-not-working-as-fall-back-mechanism-wh ? – A.B Aug 19 '23 at 18:59
  • As I wrote in your other question, there's at least a mistake on the additional "default" route. But in this question you write no output from the result of a command, so any mistake like that one is now invisible. Fixing this mistake won't make it work though. – A.B Aug 19 '23 at 19:42
  • @A.B Yeah my last question you are talking about is resolved by using 0.0.0.0/0 as destination IP. This question is specifically asked in the context of metric value of gateways. – cpp_learner Aug 20 '23 at 11:25
  • I can't tell the difference between the two questions by reading them. Moreover you didn't answer to nor delete the other question while you tell it's solved. – A.B Aug 20 '23 at 11:27
  • @A.B Imagine two default gateways are assigned with metric values 10 and 20 respectively. When default gateway with lower value 10 is down then expectation is other gateway with value 20 is should come take over automatically without user interaction – cpp_learner Aug 20 '23 at 11:40
  • That's what you want, not what can be done (by a few clicks). Anyway fix the former question first. Btw, I have no answer to provide, but someone might. – A.B Aug 20 '23 at 11:43
  • But automatic fail over switch not happening in case of 2 different metric values. If 2 gateways have SAME value then it's working. Is it the expected behavior in linux – cpp_learner Aug 20 '23 at 11:46
  • Where did you read this? Are they on the same interface or on different interfaces (not your case with a single interface)? – A.B Aug 20 '23 at 11:46
  • I tried practically in my linux system with different combinations and came to this conclusion. When two gateways are up and running then communication is happening through the gateway with lower metric value. If I bring that gatewAy down other gateway with value 20 should take care of communication automatically. That's not happening it's my observation. I tried on same interface it's my use case. I tested the same in windows it's working fine – cpp_learner Aug 20 '23 at 11:52
  • Does this answer your question? [Alma Linux -Static route configuration is not working as fall back mechanism, when default gateway is down](https://serverfault.com/questions/1141388/alma-linux-static-route-configuration-is-not-working-as-fall-back-mechanism-wh) – Greg Askew Aug 20 '23 at 12:17
  • @GregAskew: Not answered yet. This question is variation of my previous question though both are related to gateway failover scenario but here question is related to it's expected behavior in case of 2 gateways configured with 2 different metrics on the same single interface – cpp_learner Aug 20 '23 at 12:27
  • In Linux, only the default route with the lowest metric will be considered, and if that fails, it will not automatically fall back to the next highest metric. However, you can achieve your desired behavior by using some more advanced routing tools and methods, such as iproute2 and routing tables. – Alexander Pavluchenko Aug 27 '23 at 13:36
  • Install iproute2. Configure the primary default route: sudo ip route add default via 11.12.13.2 dev eth0 metric 30 Configure the secondary default route: sudo ip route add default via 11.12.13.1 dev eth0 metric 40 Add routing tables: Edit /etc/iproute2/rt_tables: Add the following at the end: 10 rt1 20 rt2 Set up rules and routes: sudo ip rule add from all lookup rt1 prio 100 sudo ip rule add from all lookup rt2 prio 200 sudo ip route add default via 11.12.13.2 dev eth0 table rt1 sudo ip route add default via 11.12.13.1 dev eth0 table rt2 – Alexander Pavluchenko Aug 27 '23 at 15:31

1 Answers1

1

There is no fully automatic ready-made fall back in Linux and it was never there. You have wrong expectation of what Linux could do for you.

Routing code doesn't track the availability of the gateway. In case several similar routes with different metrics are present, numerically lower metric is always selected, with no additional logic that can consider the state of that gateway. It's because nothing checks whether gateway is still alive, the system doesn't care about the gateway. Even if the gateway specified in the route is down, nothing in the system will know about this, route will still exist and the system will use it.

You need some external mechanism which will ping or otherwise check gateways and torn down their routes if not available. Only then, without the route to the failed gateway, next best route will be considered.

Nikita Kipriyanov
  • 10,947
  • 2
  • 24
  • 45
  • How about the behaviour when we use 2 default gateways on 2 DIFFERENT interfaces in a same system? – cpp_learner Aug 30 '23 at 03:13
  • Nowhere in my answer I am saying anything about interfaces. Routing *includes* the stage of selection of outgoing interface, which implies when it is started there is no any knowledge of interfaces. So this simply doesn't matter. – Nikita Kipriyanov Aug 30 '23 at 04:31