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

askvictor
  • 854
  • 3
  • 15
  • 29

2 Answers2

7

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

dunxd
  • 9,632
  • 22
  • 81
  • 118
  • 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 06 '21 at 23:32
0

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

Joris
  • 5,969
  • 1
  • 16
  • 13
  • 3
    You can't have two default gateways, by definition of default. You can set multiple routes however, and weight them. – dunxd Jan 25 '11 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 '11 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 '11 at 08: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 06 '17 at 08: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 06 '21 at 23:36