LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   automatic static routes? (https://www.linuxquestions.org/questions/linux-networking-3/automatic-static-routes-344658/)

eantoranz 07-19-2005 09: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 05: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 07: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 08: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 192.168.1.254 to the 10.0.0.1/24 network:

Code:

iface eth1 inet static
        up route add -net 10.0.0.1/24 gw 192.168.1.254
        down route del -net 10.0.0.1/24 gw 192.168.1.254
        address 192.168.1.1
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255

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

eantoranz 07-19-2005 08: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 08: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 04:56 AM.