Regarding routing packets via one computer to another

I am setting up packet routing via a host computer. In order to try out a simple case. I set up a small local network of 3 linux PCs X,Y,Z. These 3 get their IP from a DLink router that I have. X,Y, Z can ping each other.

I want to route packets coming from X to Z via Y.

This must not need NAT I guess.

But even getting this simple routing doesn’t seem to work.

Here are more details:

X: 192.168.0.100
y:192.168.0.3
Z:192.168.0.7

When X sends packets addressed to Y, Y should forward them to Z.

What iptable rules should I use?

Is it enough if I just setup a route command alone?

I tried on Y after setting ip_forward=1:

route add -host 192.168.0.7 gw 192.168.0.3

But I don’t achieve the result. Please advise.

Should I change something on my D-link router?

And oh btw the catch is I have to achieve this by not changing anything on system X as it is not under my control.

Thanks

Answer

If two machines are on the same IP “network” and on the same ethernet network, they will route packets directly to one another. In order to change this you need to either:

  • renumber Z, then set Y up as the gateway used by X
    OR
  • put 2 ethernet cards in Y, configure it as an ethernet bridge.

Attribution
Source : Link , Question Author : user489152 , Answer Author : pjc50

Leave a Comment