I have three systems A,B,C. I want to configure A in such a way that all packets from A to C goes via B.
I tried:
ip route add 'ip of C' via 'ip of B'
route add -net 'net address' netmask gw 'ip of B'
These commands work initially when I try a ping or traceroute and expire after attempting ping twice or thrice.
A's IP Address: 192.168.0.130
B's IP Address: 192.168.0.150
C's IP Address: 192.168.0.140
In Windows systems we achieve routing A's and B's traffic via C by running the following commands in A and C:
route delete 192.168.0.0
route add 192.168.0.0 mask 255.255.255.0 192.168.0.150
After executing the above commands, all network traffic from A and C will be routed via B.
It looks as the three hosts are on the same subnet. In this case you cannot use "static routes" because any route - static or else - just defines a way to get from one subnet to another, not to get somewhere on the same subnet.
You may want to define a "proxy" server, but you will have to install additional software (which one depends on which protocols you want to be affected by the proxy) on at least the B-server where you want to route the traffic through.
Another possibility is to put the systems on different subnets: A goes to one subnet, C goes to another subnet and B has one interface in in both these networks AND has "IP-forwarding" enabled. This way you can enforce all packets between A and C to go through B and - using a firewall software, you can even apply additional rules for which packets to allow and which to drop (forbid).