LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   How to add a persistent route in Debian Linux (https://www.linuxquestions.org/questions/linux-networking-3/how-to-add-a-persistent-route-in-debian-linux-623771/)

LotharIrausquin 02-25-2008 02:46 PM

How to add a persistent route in Debian Linux
 
Dear LinuxQuestions.org

We have a server that runs CensorNet which is a Proxy Server and runs on Debian Linux.

We need to add persistent static routes to it so that when the server gets rebooted , the routes stay in and do not disappear.

Every time the server reboots we have to add the routes back in manually.

e.g. "route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.0.228"

Can you help us out?


Regards,

Lothar Irausquin
e-mail: IrausquinL@arubadigital.com

TigerOC 02-25-2008 03:13 PM

Edit your /etc/network interfaces;

auto ethX
iface ethX inet static
address 192.168.0.2
netmask 255.255.255.0
gateway 192.168.0.228

Where X=card # which starts at zero.

LotharIrausquin 02-27-2008 02:08 PM

Quote:

Originally Posted by TigerOC (Post 3069476)
Edit your /etc/network interfaces;

auto ethX
iface ethX inet static
address 192.168.0.2
netmask 255.255.255.0
gateway 192.168.0.228

Where X=card # which starts at zero.

Do you mean
address 192.168.2.0 <----
netmask 255.255.255.0
gateway 192.168.0.228?

In CensorNet we use a bridge br0 [eth0, eth1]and we have to add a persistent route to this bridge.

TigerOC 02-27-2008 04:04 PM

It cannot be a 0 configuration as in 192.168.2.0 as this is reserved it must be greater than zero and less than 255 i.e. between 1 and 254.

The iface above would be in the form eth0:0. Never used the bridge so you need to do some reading.

LotharIrausquin 02-28-2008 05:56 AM

Quote:

Originally Posted by TigerOC (Post 3071884)
It cannot be a 0 configuration as in 192.168.2.0 as this is reserved it must be greater than zero and less than 255 i.e. between 1 and 254.

The iface above would be in the form eth0:0. Never used the bridge so you need to do some reading.

I need to add the route :
route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.0.228

NOT 192.168.0.2 netmask 255.255.255.0 gw 192.168.0.228

That's what is confusing me.

Ricio 02-28-2008 07:53 AM

That network address 192.168.2.0 its for broadcasting the entire network, isnt it?

rupertwh 02-28-2008 08:16 AM

Hi Lothar,

I'm not aware of any config file that would make the system add the route, so I'd just add the route command to a script in /etc/network/if-up.d.
In that script, check for $IFACE, so your route isn't added whenever just any interface comes up.

LotharIrausquin 02-28-2008 10:15 AM

Quote:

Originally Posted by Ricio (Post 3072600)
That network address 192.168.2.0 its for broadcasting the entire network, isnt it?

Yes, the customers network is on a LAN with Network ID 192.168.0.0 Mask
255.255.255.0. The CensorNet Server on this LAN run Debian Linux and this server needs to be configured for routing:

One route is to the Network ID 192.168.2.0 Mask 255.255.255.0 over gateway 192.168.0.228 and the other route is to the Network ID 192.168.4.0 Mask 255.255.255.0 over gateway 192.168.0.229.

I have to add these routes manually every time the server restarts and I want the routes to stay in when the server restarts.

Ricio 02-28-2008 03:49 PM

Why dont you try bash scripting and run it at boot... I actually dont know how to start scripts at boot!

Or just add the same line you do at boot at etc/network/interfaces try and see what happens...

TigerOC 02-29-2008 02:04 AM

Edit /etc/network/interface to

auto eth0:0
iface eth0:0 inet static
address 192.168.2.1
netmask 255.255.255.0
gateway 192.168.0.228

Rem (#) anything else relating to ethX as there maybe a line relating to dhcp.

In a root consol do;

/etc/init.d/networking restart

Check for any errors. Unlike some other operating systems that shall remain nameless Linux systems do not have to be rebooted to restart services as they are running daemons and can be started, stopped and restarted at any time via this route. Most servers are never rebooted accept to do kernel updates or physical work. My server was last rebooted 3 months ago after a kernel upgrade.

yongitz 02-29-2008 02:28 AM

Quote:

Originally Posted by LotharIrausquin (Post 3069458)
Dear LinuxQuestions.org

We have a server that runs CensorNet which is a Proxy Server and runs on Debian Linux.

We need to add persistent static routes to it so that when the server gets rebooted , the routes stay in and do not disappear.

Every time the server reboots we have to add the routes back in manually.

e.g. "route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.0.228"

Can you help us out?


Regards,

Lothar Irausquin
e-mail: IrausquinL@arubadigital.com

For this, I'd try the /etc/rc.d/rc.local equivalent. I'd do the following:

1. Create a file named local in /etc/init.d/, for example:
#!/bin/bash

# your route command here
/sbin/route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.0.228

2. run "update-rc.d local defaults"

That should do it. Hope this helps.

LotharIrausquin 03-11-2008 09:18 AM

It Worked!
 
Quote:

Originally Posted by yongitz (Post 3073578)
For this, I'd try the /etc/rc.d/rc.local equivalent. I'd do the following:

1. Create a file named local in /etc/init.d/, for example:
#!/bin/bash

# your route command here
/sbin/route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.0.228

2. run "update-rc.d local defaults"

That should do it. Hope this helps.


Hi Yongitz!

Yes it worked!

Thanks a million!

You have a Very Nice Day!


Regards,

Lothar Irausquin


All times are GMT -5. The time now is 11:17 AM.