/etc/interfaces file for multiple gateways, same network? (linux)

7,724

Solution 1

Sure, something like this may work

auto eth0
iface eth0 inet static
    address 10.1.248.11
    netmask 255.255.255.0
    up ip route add default via 10.1.248.1 dev eth0  metric 100 
    up ip route add default via 10.1.248.3 dev eth0  metric 200 

Solution 2

Yep. Add your ip route add lines to a script called (for example) /usr/local/sbin/routes and then add the following to the interfaces file, alongside the normal directives for eth0:

    up /usr/local/sbin/routes

If you need to, you can add a similar pre-down directive, too, pointing to a different script, or invoking the script with an argument that deletes the routes, instead. (up and pre-down are invoked after the interface is brought up and before it is taken down, repsectively)

Share:
7,724

Related videos on Youtube

Mark Rose
Author by

Mark Rose

Updated on September 17, 2022

Comments

  • Mark Rose
    Mark Rose over 1 year

    I've got my ip routing table setup as I'd like it:

    # ip r s
    10.1.248.0/24 dev eth0  proto kernel  scope link  src 10.1.248.11 
    default via 10.1.248.1 dev eth0  metric 100 
    default via 10.1.248.3 dev eth0  metric 200 
    

    10.1.248.1 is the primary gateway, and 10.1.248.3 is the backup gateway. Is there a way to configure /etc/network/interfaces to create this setup upon boot?

  • Zoredache
    Zoredache over 13 years
    Since he only wants two commands he could just put the into the interfaces directly without an external script.
  • SmallClanger
    SmallClanger over 13 years
    Actually, if it's just those two rules, then this is cleaner. I'd probably only separate them out to a file if you plan to do anything more complicated.
  • SmallClanger
    SmallClanger over 13 years
    Well, I'm glad we agree :)
  • Mark Rose
    Mark Rose over 13 years
    Thanks! I didn't know if the gateway/metric options in the iface stanza were necessary or not.