6

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?

Mark Rose
  • 314
  • 1
  • 3
  • 9

2 Answers2

7

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 
Zoredache
  • 128,755
  • 40
  • 271
  • 413
  • 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 Jan 14 '11 at 19:22
  • Thanks! I didn't know if the gateway/metric options in the iface stanza were necessary or not. – Mark Rose Jan 14 '11 at 20:55
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)

SmallClanger
  • 8,947
  • 1
  • 31
  • 45