0

For those who worked with ssh port forwarding or for those who have an idea, I managed to create a remote tunnel from my PC to a remote machine(a camera that does not have a public address) through a ssh server ( has a public address ).

The goal is to forward the access of the camera to the public with ssh remote port forwarding,

The format of the command that I launched on my PC is:

  ssh -R sshServer_port:destination_address:destination_port sshServer_address

Example:

  ssh -R 3000:192.198.1.210:80 ubuntu@52.14.9.210

In the sshServer, I can access the remote machine through localhost:3000

and then, I set up a tcpproxy to make the access public with this command:

tcpproxy -lhost 0.0.0.0:8080 -rhost localhost:3000

With this,anyone from any network can access to the camera interface by typing 52.14.9.210:8080

What I want to do is create a tunnel that listens on two remote machine ports (80 for http and 8000 for the live streaming) with the format of the command:

ssh -R sshServer_port:destination_address:destination_port1 -R sshServer_port:destination_address:destination_port2 sshServer_address

Example:

ssh -R 3000:192.168.1.210:80 -R 3000:192.168.1.210:8000 ubuntu@52.14.9.210

I tried to run the command but I got this error: Warning: remote port forwarding failed for listen port 3000

Do you have an idea how to fix this.

1

What you want is not to create a tunnel that listens on two remote machine ports, you want two tunnels that listen on the same remote port.

That is not possible. How is ssh supposed to know to which port an incoming connection should be forwarded?

There are solutions that can distinguish between protocols, but none of them are generic. It the port 80 you use is an indication of http traffic, you can set up a reverse proxy, but it would be much easier to just use two different ports for the two destinations.

Edit

From your comments, it seems you are just missing the -g option to SSH to allow other hosts to connect to the tunnel.

  • Thanks for the answer, I already set up a reverse proxy (tcpproxy) that forward any request of the port 8080 to the localhost:80 of the ssh server. If I use two different remote ports for the two destinations, I cannot set up the reverse proxy. Do you know any other solution for that ? Could dynamic port forwarding solve the porblem ? – Wrath13 Oct 11 '18 at 14:32
  • You would have to provide more details. – RalfFriedl Oct 11 '18 at 14:33
  • okay, So the destination machine (192.168.1.210) is a camera that I can access to its interface by writing its address in the browser, the camera needs the port 80(http) and the port 8000(streaming). The camera doesn't have a public address, so what I did is creating tunnel(ssh -R 3000:192.198.1.210:80 ubuntu@52.14.9.210) to the public through a ssh server that has a public address. when I set up a tcpproxy (tcpproxy -lhost 0.0.0.0:8080 -rhost localhost:3000), anyone could access to the camera through the address of the public server but it needs the port 8000 to the live streaming works. – Wrath13 Oct 11 '18 at 14:46
  • Add that to the question, it allows proper formatting and for others to see at once. – RalfFriedl Oct 11 '18 at 14:47
  • Why don't you just forward port 80 to 80 and 8000 to 8000? Why port 3000 for both? – RalfFriedl Oct 11 '18 at 14:49
0

I fixed the issue, thanks to ralffriedl for the hints.

First step: I created the first remote port forwarding tunnel between the camera address on port 80 and the ssh server on port 2233, then I set up a tcpproxy between the localhost:2233 of the ssh server and the public ip address of the server(52.214.9.211) on port 4455

Second step: I created the second remote port forwarding tunnel between the camera address on port 8000 and the ssh server on port 2255, then I set up a tcpproxy between the localhost:2255 of the ssh server and the public ip address of the server(52.214.9.211) on port 8000

With this, when someone from an external network, put the server ip address on his browser with the port forwarded from the port 80 of the camera ip address, i.e:(52.214.9.211:4455), he is able to access to the camera and when a live streaming request is done on port 8000, ie:(52.214.9.211:8000), it's forwarded to the localhost:2255 of the server and then to the port 8000 of the camera.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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