Eric B.
2008-Apr-15 16:36 UTC
[CentOS] How to create static routes on startup with CentOS4?
Hi, I'm working with the iproute2/iptables toolset on my CentOS4 server to create custom routing rules. However, I'm a bit at a loss how to create these permanently so that they are automatically reloaded upon reboot of the server. I know that iptables has a config file in /etc/sysconfig/iptables that is loaded by /etc/init.d/iptables startup script. 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. Any ideas/suggestions? Do I have to create my own custom startup script for this? Or is there somewhere already existant I can put iproute2 commands? Thanks! Eric
Filipe Brandenburger
2008-Apr-15 18:15 UTC
[CentOS] How to create static routes on startup with CentOS4?
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