E
E
Eugene2021-03-23 16:53:51
SSH
Eugene, 2021-03-23 16:53:51

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 -tunland 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:8000and 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:8000doesn'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:

  • GatewayPorts
  • AllowTcpForwarding

Both parameters are set to yes , after making changes, the ssh service was restarted via systemctl.

Specifications:
  1. Ports on Ubuntu are not blocked. Those. if I go to the server and there I raise the web server on a random port - it works correctly when accessed by ip: port
  2. In fact, the network has a https://localhost.run service that performs almost the same functionality. Unless the forwarding goes for the web and on the 80th port, and in the result of the connection something like motd and the address where you can see the forwarded web server are displayed.

Based on this, I make a (possibly erroneous) assumption that the problem is somewhere in the ssh server configuration, but unfortunately I don’t know where and in what exactly. Thanks in advance to everyone who will respond and tell you what's what.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2021-03-23
@RyoidenshiAokigahara

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.

To be honest, I don't remember seeing this moment mentioned. However, when using 127.1 directly instead of localhost, ssh -R 8000:127.0.0.1:3000 remoteservthe 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.
It will be necessary to look for a long time whether the tenth Windows localhost binds to the ipv6 address :/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question