reverse tunnel with automatic remote port selection

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I want to create a reverse tunnel with the -R option, but I don't want
to specify the port to be used on the remote server (because my client
application doesn't know which port is free on the server).  So I
would like e.g. that ssh automatically selects a free port on the
server, possibly within a specified range.

Is there any way to do this with SSH?

If not, is there another common way to do this?


Re: reverse tunnel with automatic remote port selection

Quoted text here. Click to load it

The SSH-2 protocol allows this (see RFC4254) -- when the forwarding it
set up, the client requests port 0, and the server responds to the
client telling it which port it chose.

However, many clients don't expose this -- I know PuTTY doesn't. OpenSSH
appears to have added it quite recently, in 5.2.

There's a design problem with implementing this feature -- how should
the SSH client (or indeed the server) get the assigned port number to
someone who can use the information?
Looking at the bug above, it looks like the OpenSSH client just prints
it out. I haven't looked to see whether other implementations have dealt
with this problem.

Site Timeline