I made a port SSH local forwarding on a remote machine:
ssh -N -L 127.0.0.1:3388:127.0.0.1:22 localhost
it works on the remote machine itself:
telnet localhost 3388
returns
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.4
However, when I use this forwarding from the local machine:
telnet remote.ip 3388
it fails:
Trying remote.ip...
telnet: Unable to connect to remote host: Connection refused
One may think the 3388 port of the remote machine is blocked by the firewall or something from the network, so I turned off the SSH forwarding and tested a http server listening on port 3388 on the remote machine:
python3 -m http.server 3388
then I connect to this port from my local machine:
telnet remote.ip 3388
The result gives
Trying remote.ip...
Connected to remote.ip.
Escape character is '^]'.
quit
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Error response</title>
</head>
<body>
<h1>Error response</h1>
<p>Error code: 400</p>
<p>Message: Bad request syntax ('quit ').</p>
<p>Error code explanation: HTTPStatus.BAD_REQUEST - Bad request syntax or unsupported method.</p>
</body>
</html>
Connection closed by foreign host.
which means the port 3388 on the remote machine is accessible to my local machine. So why both the SSH forwarding and the network work properly by individual, but it fails when they are combined? Somebody knows how to fix this? Thanks.