将本地主机上的端口转发到某个远程主机:端口

Har*_*ald 2 port-forwarding

假设有一些服务器在remotehost.some.where:4444上运行。我有一个软件坚持连接到 localhost:5555。我可以将其转发ssh

ssh -L 5555:remotehost.some.where:4444 myuser@localhost
Run Code Online (Sandbox Code Playgroud)

但这需要与本地主机建立不必要的 ssh 连接,而添加-N不会阻止这种连接。如何在不登录的情况下(可能使用其他工具)进行此端口转发?

lar*_*sks 8

最简单的解决方案是运行某种 TCP 代理。您可以使用socat,例如:

socat tcp-listen:5555,bind=127.0.0.1,fork tcp:remotehost.some.where:4444
Run Code Online (Sandbox Code Playgroud)

当它运行时,到5555本地主机上端口的连接将被转发到4444上的端口remotehost.some.where

我在这里使用的命令仅侦听127.0.0.1. 如果您确实想在 port 上接受来自其他主机的连接5555,则可以删除该bind=127.0.0.1选项。