Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

# ip r s dev eth0  proto kernel  scope link  src 
default via dev eth0  metric 100 
default via dev eth0  metric 200 is the primary gateway, and is the backup gateway. Is there a way to configure /etc/network/interfaces to create this setup upon boot?

share|improve this question
up vote 6 down vote accepted

Sure, something like this may work

auto eth0
iface eth0 inet static
    up ip route add default via dev eth0  metric 100 
    up ip route add default via dev eth0  metric 200 
share|improve this answer
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

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|improve this answer
Since he only wants two commands he could just put the into the interfaces directly without an external script. – Zoredache Jan 14 '11 at 19:22
Well, I'm glad we agree :) – SmallClanger Jan 14 '11 at 19:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.