9

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

2 Answers 2

7

This blog entry explains how to setup multiple routes for Linux in some detail.

1
  • 2
    The 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
    Mar 6, 2021 at 23:32
0

Just set a second default gateway, linux will do the failover by itself.

5
  • 3
    You can't have two default gateways, by definition of default. You can set multiple routes however, and weight them.
    – dunxd
    Jan 25, 2011 at 11:48
  • 1
    @dunxd: that's semantics. It's a route for the entire internet, and it's set in exactly the same manner as a default gateway.
    – Joris
    Jan 25, 2011 at 20:12
  • 3
    Not 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.
    – dunxd
    Jan 27, 2011 at 8:57
  • 3
    @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."""
    – madumlao
    Nov 6, 2017 at 8:44
  • 1
    The 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.
    – rwfbc
    Mar 6, 2021 at 23:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .