ssh remote forward 监听 0.0.0.0 端口;How to make SSH remote port forward that listens 0.0.0.0

  • A+
所属分类:linux技术
摘要

今天使用ssh转发内网服务的时候,发现remote forward 转发到远程,监听的端口都是localhost。

今天使用ssh转发内网服务的时候,发现remote forward 转发到远程,监听的端口都是localhost。

之前还没发现这种情况,因为都是在所转发的目的主机使用服务。今天,我进行转发内网私有云服务,到网关主机的时候,不管怎么设置都是监听localhost。

而我的需求是能够监听0.0.0.0地址,接收通过域名和ip的方式的访问。

通过查找网络,我很快发现了解决方案:

Enable GatewayPorts in sshd_config (by default it is disabled).
Enabling it will instruct sshd to allow remote port forwardings to bind to a non-loopback address.
AskUbuntu has a similar question about Reverse Port Tunneling that goes into more details.

主要思路是,修改sshd配置文件 的 GatewayPorts 为yes, 并重启sshd 服务即可。我想这应该是sshd默认的一种安全保护。

修改后,查看服务器端口号如下:

ssh remote forward 监听 0.0.0.0 端口;How to make SSH remote port forward that listens 0.0.0.0

可见,修改生效。前面的*,表示当前接收所有目的ip的,相应端口的数据包;祝你使用愉快!

参考链接:

How to make SSH remote port forward that listens 0.0.0.0