SSH远程端口转发空响应

Aun*_*zvi 6 ssh portforwarding

我正在尝试在 Windows 电脑上使用 ssh 从本地网络中的 Raspberry pi 进行远程端口转发

ssh -R 5941:localhost:8000 pi@192.168.1.191
Run Code Online (Sandbox Code Playgroud)

因此,根据上面的命令,我尝试将连接从 Raspberry pi 服务器 (192.168.1.191) 上的端口 5941 转发到我的电脑 (localhost) 上的端口 8000,该电脑在端口 8000 上托管一个 Web 服务器

上面的 ssh 命令执行没有错误,但是当我尝试在 Raspberry Pi (192.168.1.191) 上访问 http://localhost:5941/ 时,我得到

ERR_EMPTY_RESPONSE
Run Code Online (Sandbox Code Playgroud)

我努力了

  1. 关闭了我的 Windows PC 上的防火墙
  2. raspberrypi 上的 netstat 给了我
$ sudo netstat -a | grep 5941
tcp        0      0 0.0.0.0:5941        0.0.0.0:*               LISTEN
tcp6       0      0 [::]:5941               [::]:*                  LISTEN
Run Code Online (Sandbox Code Playgroud)
  1. 当我在详细模式下运行 ssh 命令时, ssh -R 5941:localhost:8000 pi@192.168.1.191 -v 我得到了这个
debug1: Remote connections from LOCALHOST:5941 forwarded to local address localhost:8000
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: network
debug1: console supports the ansi parsing
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug1: Remote: Forwarding listen address "localhost" overridden by server GatewayPorts
debug1: remote forward success for: listen 5941, connect localhost:8000
debug1: All remote forwarding requests processed
Run Code Online (Sandbox Code Playgroud)

当我尝试在 Raspberry Pi (192.168.1.191) 上访问 http://localhost:5941/ 时,我在 ssh 控制台上得到了这个

debug1: client_input_channel_open: ctype forwarded-tcpip rchan 3 win 2097152 max 32768
debug1: client_request_forwarded_tcpip: listen localhost port 5941, originator ::1 port 58122
debug1: getsockopt TCP_NODELAY: Invalid argument
debug1: connect_next: host localhost ([::1]:8000) in progress, fd=7
debug1: channel 1: new [::1]
debug1: confirm forwarded-tcpip
debug1: channel 1: connected to localhost port 8000
debug1: channel 1: free: ::1, nchannels 2
Run Code Online (Sandbox Code Playgroud)

我应该如何进一步诊断我的问题?

Aun*_*zvi 15

解决这个问题的方法是127.0.0.1localhost

ssh -R 5941:127.0.0.1:8000 pi@192.168.1.191
Run Code Online (Sandbox Code Playgroud)

这会强制使用 ipv4 而不是 ipv6,由于某种原因,Windows 中的 ssh 端口转发无法在 ipv6 上工作,我可以在localhostLinux 上使用相同的命令。

我从这篇文章中找到了解决方案