Get linux to change default route if one path goes down?
25,540
This blog entry explains how to setup multiple routes for Linux in some detail.
Related videos on Youtube
Author by
askvictor
Updated on September 17, 2022Comments
-
askvictor almost 2 years
I'm configuring a gateway/router linux box. It is performing masquerading/NAT. The primary Internet interface is a 3G modem, but if that goes down, I would like it to try a different interface automatically. How would I go about doing this? Can the routing rules automatically cater for this, or should I get it to periodically check if the 3G connection is up, and if not, try the other?
Cheers,
Victor
-
dunxd over 13 yearsYou can't have two default gateways, by definition of default. You can set multiple routes however, and weight them.
-
dunxd over 13 yearsNot semantics at all. Default routes and default gateways are configured differently. If you used the right terms, or linked to some useful information then your answer would be more helpful. By the way, I didn't down vote your answer.
-
madumlao over 6 years@dunxd, um "default" simply means the 0.0.0.0 route in linux, so he's correct in that you can have 2 (or any number of) default gateways. And in ip route terms, gateway = router so he's exactly correct. In route (8): """Genmask The netmask for the destination net; '255.255.255.255' for a host destination and '0.0.0.0' for the default route."""
-
rwfbc over 3 yearsThe blog is a different scenario. The blog uses policy-based routing to ensure that replies to inbound packets go out the same interface. The original question is how to use an alternate gateway for outbound packages when the primary interface is down. BTW, I know this is an old thread.
-
rwfbc over 3 yearsThe secondary gateway / default route needs to have a higher metric. The default route with the lowest metric is considered first. If that interface is down, the route with the next higher metric will be used.