Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers 2

up vote 6 down vote accepted

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 
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
add comment

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
add comment

Your Answer

 
discard

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.