7

I am trying to make a tunnel between a server and laptop with Putty. The problem is, since the laptop has no public IP address, I have to make a reverse connection. But I really don't know how to do that.

Let me demonstrate what I want:

SERVER(PORT:6000) ----------> LAPTOP(PORT:7000)

but since the laptop has no public IP address I have to make like

SERVER(PORT:6000) <---------- LAPTOP(PORT:7000)

Can you please tell me what should I write as source port, destination etc.

2 Answers 2

8

Depends on which setup you want:

SETUP 1) server is listening

                              ssh tunel             LAN destination   
SERVER (listen on port 6000) ==========> LAPTOP -----> ip:port

(LAN destination could also be localhost:port to connect laptop itself)

PUTTY SETUP: right click on putty window title, choose Change settings / Tunnels and fill in:

source port: 6000
destination: ip:port (or hostname:port)
select "Remote"

SSH: ssh -R 6000:hostname:port

SETUP 2) laptop is listening

                              ssh tunel              destination   
LAPTOP (listen on port 7000) ==========> SERVER -----> ip:port

again, the destination could be localhost:port to connect to server itself.

PUTTY setup:

source port: 7000
destination: ip:port (or hostname:port)
select "Local"

SSH: ssh -L 7000:hostname:port

In both cases, you can also specify (in putty by a checkbox) if the listening LAPTOP/SERVER also accepts connection from other hosts.

0

The direction of your arrows has no relationship to which machine has publicly routable IP addresses -- you need to know which direction you want your arrow to go based on the problem you're trying to solve. The connection will always be initiated from your laptop (because it cannot be directly addressed from the other machine) but you will use one or the other connection forwarding arguments based on how you want the port forwarding to work.

Since I don't know putty, I'll give the corresponding commands from OpenSSH; hopefully it'll be easy to find the corresponding options in the GUI config boxes of putty.

If you want connections made to laptop:7000 to be forwarded to server:6000, then you could use ssh -L 7000:server:6000. If the connections originate on your laptop then you could slightly amend this to: ssh -L localhost:7000:server:6000. This restricts the port on your laptop to connections initiated on the laptop itself.

With this command, a program on the server must be listening to port 6000 for connections. Programs on your laptop (or elsewhere on your local network) must be able to connect to your localhost:7000 (or your machine's non-routable address, port 7000) to initiate the connection.

If you want connections made to server:6000 to be forwarded to laptop:7000, then you could use ssh -R 6000:localhost:7000. By default this is only open to connections initiated on the server machine. If you wanted it to be open to all machines that can contact the server, then you could use ssh -R *:6000:localhost:7000.

With this command, a program on the laptop must be listening to port 7000 for connections. Programs on your server (or elsewhere on the server's network) must be able to connect to server:6000 (or server's routable address, port 6000) to initiate the connection.

It took me years to get the hang of the difference between -L and -R connection forwarding. The -L says that programs will attempt to connect Locally, and the -R says that programs will attempt to connect Remotely. (Don't worry about the difference; I have to look it up in the manual every single time I need it.)

You must log in to answer this question.