Add ip rule to routing policy database at startup

I need to route all traffic from host A via gateway B. I use iproute2: “ip rule add from A lookup B”. Is there already existant script where I can put “ip rule add” command or do I have to create my own custom startup script for this?

I do not even have a iproute2 program, so I may misunderstand you completely. But it seems to me that B is your default router. You can configure that in YaST > Network devices > Network cards and the tab Routing. Put the ip address of B in the default route field and Finish.

B is not my default router, my default router is C. iproute2 commands let you send traffic from different host or different kinds of traffic through different routers. I can not do this with Yast.

I did a quick grep in the /etc directory and could not find a reference in an existing script. You could create a script to add and remove the command in /etc/sysconfig/network/scripts. Then in /etc/sysconfig/network/if-up.d and if-down.d symbolic links to that scripts.

I did Google a bit about iproute2. It seems to be a replacement for several long existing network configuration statedments that still exist. So in this case I suppose that you use iproute2 to do the same as good old route add. But in that case I do not understand that you do not simply use YaST to configure the route. YaST will place the correct definition in */et/sysconf/network/routes *so that it is used at every boot.

Doesn’t that work for you?

Thanks. I’ll do that.

You are not quite right. iproute2 is more powerfull tool than ifconfig, route, etc. I use it to forward traffic from different hosts via different gateways. You can not do this with route command. Alas yast can not work with iproute2

Thanks for the explanation.

What about an extra script in /etc/init.d/ (based on /etc/init.d/skeleton)? I think the skeleton gives you ideas on how to let it be run after the script network and before other scripts that start services that may rely on it being run earlier.