-   Linux - Networking (
-   -   automatic static routes? (

eantoranz 07-19-2005 10:58 AM

automatic static routes?
Is there a way I can automatically add static routes once a network interface goes up?

cjcox 07-19-2005 06:05 PM

This will vary from distribution to distribution. Worst case, you can always find the init script that starts your network and hardcode your static routes (route add .. etc.) onto it.

What distribution are you using?

eantoranz 07-19-2005 08:08 PM

Oh... I know where to write stuff for the boot process..... but I mean if during normal operation, one link is brought down and back up.

(It's Ubuntu).

demian 07-19-2005 09:11 PM

I've never actually used ubuntu but since it's debian based I'm gonna assume it's the same as in debian proper. Put a line for each static route in /etc/network/interfaces. Eg let's say eth1 is connected through gateway to the network:


iface eth1 inet static
        up route add -net gw
        down route del -net gw

This will call the command on the line starting with up (sans the up itself) whenever the interface goes active.

eantoranz 07-19-2005 09:17 PM

But that will work if I use the /etc/init.d/networking script, right?

How about if I use ifconfig eth0 down; ifconfig eth0 up? will it work anyway?

demian 07-19-2005 09:30 PM

It works with /etc/init.d/networking and ifup/ifdown since these scripts read the interfaces file. It will not work when you use ifconfig.

All times are GMT -5. The time now is 10:06 AM.