[CentOS] How to create static routes on startup with CentOS4?

Filipe Brandenburger

filbranden at gmail.com
Tue Apr 15 18:15:00 UTC 2008


On Tue, Apr 15, 2008 at 12:36 PM, Eric B. <ebenze at hotmail.com> wrote:
>  Is there anything that works similarly for the iproute2 ruleset?  I can't
>  seem to find anything in /etc/init.d/network except for references to static
>  routes using /sbin/route, which isn't good enough if one wants to use
>  multiple routing tables.  Nor can I find anything in /etc/init.d/ that would
>  seem applicable to the iproute2 system.

You should put it in /etc/sysconfig/network-scripts/route-eth0 (change
"eth0" to the name of the interface the routes apply to). For every
line in this file, when the interface goes up, it will run "/sbin/ip
route add $line" (see /etc/sysconfig/network-scripts/ifup-routes
script if you want to understand exactly what it's doing).

Apparently there's also a new syntax for
/etc/sysconfig/network-scripts/route-eth0, in which you specify
several variables, the same you do in ifcfg-eth0, then you set
something like:

ADDRESS0=1.2.3.0
NETMASK0=255.255.255.0
GATEWAY0=4.3.2.1

And then you go ADDRESS1, ADDRESS2, ..., as you need more routes.

There used to be a /etc/sysconfig/static-routes for this purpose but,
as I understand, now the way to do it is per interface with the
route-${ifname} files.

To test if your file is working, do a "service network restart" and
check if the routes are up as expected. You can also do "ifdown eth0"
and "ifup eth0" if you want to restart only one interface (for
instance if you're remotely connected through another interface).

HTH,
Filipe



More information about the CentOS mailing list