ssh remote forward 監聽 0.0.0.0 端口;How to make SSH remote port forward that listens 0.0.0.0


今天使用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默認的一種安全保護。

修改后,查看服務器端口號如下:

可見,修改生效。前面的*,表示當前接收所有目的ip的,相應端口的數據包;祝你使用愉快!

# 如果沒有選項,可以手動添加:2022年04月11日11:55:55

GatewayPorts yes

參考鏈接:

How to make SSH remote port forward that listens 0.0.0.0


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM