Answer the question
In order to leave comments, you need to log in
How to set up an SSH server to forward a local port to the outside via ssh -R?
Familiar with port forwarding via SSH.
There is a remote server on Ubuntu 20.04, there is Windows 10 in the local network.
The net is full of information describing the -R, -L and -D options for ssh, but not everywhere there is a mention of the need to make changes to the config on the server.
Actually, there were no problems with the proxy (-D) and forwarding the remote port to the local one (-L) - everything worked as described in numerous instructions, etc.
However, there is a problem with forwarding a local port to a remote port (-R).
Command in general: ssh -R 8000:localhost:3000 remoteserv
On Windows in ~/.ssh/config there is an alias remoteserv with IP, user and key
The connection is successful - no error messages come out. I have a terminal session on the server.
I run the command ss -tunl
and see that TCP is listening on 0.0.0.0:8000
On Windows, I run a web server on port 3000. The web server is spinning at 0.0.0.0:3000 - there are no problems accessing it from other devices on the local network. I address the server by IP:8000 - logically, the request should be forwarded via ssh to local port 3000, and, accordingly, return the response from Windows port 3000 to server port 8000.
However, unfortunately this does not happen and in the browser I get ERR_EMPTY_RESPONSE
In the same terminal session on the server I start curl 0.0.0.0:8000
and get a trace. result: curl: (52) Empty reply from server
UPD: I received a remark from one of my friends thatcurl 0.0.0.0:8000
doesn't work because 0.0.0.0 is a meta address. In this regard, the clarification - localhost instead gave the same result.
Clarification: when a request is made from another device on the local network, the local web server records the incoming request. When an attempt is made to reach the forwarded port (remote server and port 8000), no requests are recorded on the local server.
While flipping through all these intros, in several cases I came across information about the config, in particular about the parameters:
Answer the question
In order to leave comments, you need to log in
The solution to the problem was found here: localhost.run/docs/cli
In particular, the following notice:
NOTE
Some operating systems set localhost to the ipv6 address [::1] while some frameworks listen on 127.0.0.1 , try 127.0.0.1 instead of localhost if there are connection issues.
ssh -R 8000:127.0.0.1:3000 remoteserv
the forwarding finally worked and the request from the outside to the ubuntu server still reached the local device with the web server. There were no problems with the answer either. As it turned out, everything was in order with the SSH server configuration. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question