How to set static routes for packets, within the same Network?

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:

  1. ip route add 'ip of C' via 'ip of B'
  2. 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.

I am looking for a linux equivalent of the same.

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).

I hope this helps.

bakunin

Hi,

I was able to solve the problem by performing the following steps:

  1. Static IP address was set.
  2. Gateway IP was set to the IP of system B.
  3. Automatic DNS was turned off.
  4. Network was restarted.
  5. Default route entry of the Network Address has to be deleted.

After doing these steps in Systems A and C all packets were getting routed via B.