![使用 socat,远程(服务器)主机上的给定端口将被转发到本地的给定主机和端口](https://linux22.com/image/615413/%E4%BD%BF%E7%94%A8%20socat%EF%BC%8C%E8%BF%9C%E7%A8%8B%EF%BC%88%E6%9C%8D%E5%8A%A1%E5%99%A8%EF%BC%89%E4%B8%BB%E6%9C%BA%E4%B8%8A%E7%9A%84%E7%BB%99%E5%AE%9A%E7%AB%AF%E5%8F%A3%E5%B0%86%E8%A2%AB%E8%BD%AC%E5%8F%91%E5%88%B0%E6%9C%AC%E5%9C%B0%E7%9A%84%E7%BB%99%E5%AE%9A%E4%B8%BB%E6%9C%BA%E5%92%8C%E7%AB%AF%E5%8F%A3.png)
是否可以使用 socat 实现以下操作,而无需使用 ssh?
> ssh -N -R 8080:localhost:1080 [email protected]
-R [bind_address:]port:host:hostport
Specifies that the given port on the remote (server) host is to be forwarded to the given host and port on the local side.
This works by allocating a socket to listen to port on the remote side, and whenever a connection is made to this port,
the connection is forwarded over the secure channel, and a connection is made to host port hostport from the local machine.
-N Do not execute a remote command. This is useful for just forwarding ports (protocol version 2 only).
答案1
可能不会。虽然socat
可以将本地系统上的端口 8080 转发到远程系统上的端口 1080,但它无法改变您的原点 - 您仍将从本地系统进行连接。
使用 ssh,连接通过 ssh 隧道转发,这样当某个东西连接到远程系统的 1080 端口时,它看起来也源自该系统。如果有防火墙阻止外部访问该端口(或者如果相应的进程只在环回接口上监听),这会产生重大影响。