Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
1  
How will Y know which packets it should forward to Z? And what layer are you trying to do this at? Is this NAT? Or proxying? Or what? (We could probably give you a much better answer if we knew what problem you were trying to solve.) –  David Schwartz May 4 '12 at 6:45
    
Y should forward tcp packets received on ports 9000 and 7000 to Z. –  user489152 May 4 '12 at 7:23
    
And should Z see them coming from Y so replies go back to Y? Or should Z them coming from X and send replies to X? –  David Schwartz May 4 '12 at 8:03
    
If system X is not under your control, do you actually have permission to hijack its IP traffic? –  pjc50 May 4 '12 at 8:55
    
@DavidSchwartz:Z should send it to Y which again forwards the replied back to X. This is just a small experiment. Eventually there will be another internal interface between Y and Z with a different subnet. But for now, I want this routing done.. –  user489152 May 4 '12 at 10:20

1 Answer 1

up vote 0 down vote accepted

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.
share|improve this answer
    
Of course X can talk directly to Z but like I said, I am trying to have a simple forwarding setup here. –  user489152 May 4 '12 at 10:23
    
Yes, but the important thing is that you cannot prevent X talking directly to Z instead of through Y unless you change one of "same IP network" or "same ethernet segment". –  pjc50 May 4 '12 at 11:02
    
what do u mean renumber Z? –  user489152 May 4 '12 at 14:11
    
COuld you please elaborate? I would like to try it. Y is a board and has only one eth interface. –  user489152 May 4 '12 at 14:12
    
Change Z to 192.168.1.7. Make sure that Y's interface has two addresses, 192.168.0.3 and 192.168.1.3. Tell X (or the dlink) that to route packets to the network 192.168.1.0/24, use gateway 192.168.0.3. Then traffic from X to Z will go via Y. –  pjc50 May 4 '12 at 14:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.