使用 PuTTy 进行 SSH 反向端口转发 - 如何指定绑定地址

Dar*_*bio 21 ssh port-forwarding putty

使用 Putty,我设置了一个反向代理,它允许我在服务器的端口 8080 上连接server.tld到启动 SSH 连接的机器的端口 80。

服务器允许我连接localhost:8080并返回initiator:80我在服务器上连接时的结果。

这个问题说要启用 GatewayPorts 并绑定到所有地址。

使用 Putty,如何在服务器上公开端口 8080,以便当外部接口(例如 Web 请求)上的请求通过时,端口被转发到initiator:80?

在此处输入图片说明

Eig*_*ony 22

设置 PuTTY 隧道时有两个复选框,

  • 本地端口接受来自其他主机的连接
  • 远程端口做同样的事情(仅限 SSH-2)

其中的第二个做你需要的。

我刚刚测试了一下

PuTTY 隧道对话框,

  • 勾选远程端口...
  • 将 8080 放入源端口
  • 将 127.0.0.1:80 放入目标端口
  • 选择“远程”单选按钮
  • 点击添加
  • 连接

工作正常,这是生成的 netstat,

# netstat -an | grep 8080
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN
tcp6       0      0 :::8080                 :::*                    LISTEN
Run Code Online (Sandbox Code Playgroud)

您也可以使用 PuTTY 自带的 plink.exe,例如,

plink -R *:8080:localhost:80 user@remote.host.example
Run Code Online (Sandbox Code Playgroud)

这也很好用。

# netstat -an | grep 8080
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN
tcp6       0      0 :::8080                 :::*                    LISTEN
Run Code Online (Sandbox Code Playgroud)

如果您仍然在主机上收到 127.0.0.1:8080,则 sshd 配置中的 GatewayPorts 仍设置为 no。

另外,不要忘记更新目标服务器上的防火墙以允许外部连接到端口 8080。