Link to home
Start Free TrialLog in
Avatar of smotbd
smotbd

asked on

500: basic port forwarding/mapping

Hi all,

This is an easy 500 points, especially if you've done it before..!

I have 3 PCs (call them A, B and C)
A and C both have non-routable ip addresses so they can't talk directly to each other.
So I have set up a middle PC (i.e B) to port forward between A and B.

A will talk to B on say port 'x' and C will talk to B on say port 'y' so data can be transfered between A and C.

Problem is: I have looked at a couple of simple port forwarding commands but they all specify the ip addresses to be mapped. All I want is a command running on linux PC 'B' to forward anything sent to port 'x' to port 'y' (without specifying any ip address).
Can any one write a working example of this please.

Many thanks,
ASKER CERTIFIED SOLUTION
Avatar of Pablo Allietti
Pablo Allietti
Flag of Uruguay image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What kind of communication do you wish to establish between A and C?

If it is a simple protocol you could maybe slogin to computer B from computer A and from computer C. With appropriate tunnel forwarding commands you establish a one way (or two way) connection between machines A and C.

For more complex protocols you could establish a VPN connection from A to C and this would probably involve the SSH tunneling mentioned before.

So if server A is a web server (on port 80) and you want to access it from computer C you would do:

on computer A:
slogin -N -R 8081:<computer_A_IP>:80 user@<computer_B_IP>

on computer C:
slogin -N -L 8082:<computer_B_IP>:8081 user@<computer_B_IP>

This commands are for establishing the tunnels. It is posible to establish this in startup scripts without entering passwords etc.

Then on computer C run:
lynx http://localhost:8082/

And you should get the default web page from server A.
so ???? you try this helps?
Avatar of smotbd
smotbd

ASKER

I found that the following works:

/sbin/iptables -t nat -I PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
is the same like i post in the first message...  exactly the same
Avatar of smotbd

ASKER

Not quite "exactly" the same but close enough I guess- see below!!

-t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
-t nat -I PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

Many thanks