Tim*_*Tim 17 ssh port-forwarding
我试图了解“本地端口转发”和“动态端口转发”之间的区别。
在“本地端口转发”的ssh命令中,是否总是需要指定目的主机?
“动态端口转发”中的“动态”是否意味着,在“动态端口转发”的ssh命令中,不需要指定目的主机?如果是,何时指定目的地?
mur*_*uru 18
是的,使用本地转发时必须指定目标 IP 和端口。来自man ssh
:
-L [bind_address:]port:host:hostport
Specifies that the given port on the local (client) host is to be
forwarded to the given host and port on the remote side.
Run Code Online (Sandbox Code Playgroud)
显然,只有绑定地址是可选的。
不,在使用动态转发时不能指定目标主机或端口。在动态转发中,SSH 充当 SOCKS 代理。再次从联机帮助页(强调我的):
-D [bind_address:]port
Specifies a local “dynamic” application-level port forwarding.
This works by allocating a socket to listen to port on the local
side, optionally bound to the specified bind_address. Whenever a
connection is made to this port, the connection is forwarded over
the secure channel, and the application protocol is then used to
determine where to connect to from the remote machine. Currently
the SOCKS4 and SOCKS5 protocols are supported, and ssh will act
as a SOCKS server.
Run Code Online (Sandbox Code Playgroud)
使用-L
,SSH 不会尝试了解流量。它只是将它在本地端口上接收到的所有内容发送到目标端口 - 您在建立连接时确定目标端口。使用-D
,SSH 充当代理服务器,因此可以处理来自多个端口的连接(例如,配置为将其用作 SOCKS 代理的浏览器可以通过同一连接访问 HTTP、HTTPS、FTP 等)。与其他代理服务器一样,它将使用流量来确定目的地。