今天使用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的,相應端口的數據包;祝你使用愉快!
參考鏈接: