【问题标题】:Port tunnelling from behind firewall to remote server via VNC'd laptop? [closed]通过 VNC 笔记本电脑从防火墙后面到远程服务器的端口隧道? [关闭]
【发布时间】:2017-11-22 06:16:26
【问题描述】:

我在 linux 上有一个命令行应用程序,它使用特定端口与远程服务器通信。不幸的是,在工作中,那个端口被阻塞了。

我能够通过 VNC 将我的笔记本电脑连接到网络,并且笔记本电脑处于无线连接上,确实可以访问远程服务器的端口。连接后,我可以从安全网络通过 ssh 连接到我的笔记本电脑。

有没有办法使用 ssh 端口隧道来解决这个问题?我可以将隧道移植到我的笔记本电脑并让我的笔记本电脑充当防火墙网络和远程服务器之间的中间人吗?

非常感谢。

【问题讨论】:

  • 这可能会在SuperUser 或Unix&Linux SE 站点中获得更多帮助。
  • 好的,感谢您指出这一点。

标签: linux networking ssh firewall


【解决方案1】:

如果我理解你是正确的,你可以从你所在的地方调用 ssh 来访问你的笔记本电脑。然后你应该可以做这样的事情:

ssh -f -N -L <local port>:<remote server ip or hostname>:<remote server port> <laptop ip or hostname>

这将在 ssh 发起的主机上创建一个 tcp 侦听端口,该端口通过您 ssh 到的机器转发到您的远程主机和端口。

摘自https://man.openbsd.org/ssh

-L [bind_address:]port:host:hostport
-L [bind_address:]port:remote_socket
-L local_socket:host:hostport
-L local_socket:remote_socket
Specifies that connections to the given TCP port or Unix socket on the local
(client) host are to be forwarded to the given host and port, or Unix
socket, on the remote side. This works by allocating a socket to listen to
either a TCP port on the local side, optionally bound to the specified
bind_address, or to a Unix socket. Whenever a connection is made to the
local port or socket, the connection is forwarded over the secure channel,
and a connection is made to either host port hostport, or the Unix socket
remote_socket, from the remote machine.
Port forwardings can also be specified in the configuration file. Only the
superuser can forward privileged ports. IPv6 addresses can be specified by
enclosing the address in square brackets.
By default, the local port is bound in accordance with the GatewayPorts
setting. However, an explicit bind_address may be used to bind the
connection to a specific address. The bind_address of “localhost” indicates
that the listening port be bound for local use only, while an empty address
or ‘*’ indicates that the port should be available from all interfaces.

-f
Requests ssh to go to background just before command execution. This is
useful if ssh is going to ask for passwords or passphrases, but the user
wants it in the background. This implies -n. The recommended way to start
X11 programs at a remote site is with something like ssh -f host xterm.
If the ExitOnForwardFailure configuration option is set to “yes”, then a
client started with -f will wait for all remote port forwards to be
successfully established before placing itself in the background.

-N
Do not execute a remote command. This is useful for just forwarding ports.

【讨论】:

  • 感谢您的回复。我已经尝试过了,但到目前为止还没有成功。一个直接的问题是,当它使用 ipv6(默认情况下)时甚至不建立连接,因此需要 -4 选项。
  • ssh 是否打开了本地监听端口,但它无法访问或根本无法连接到 127.0.0.1 上的端口?
  • 嗨@nissefors。感谢您的评论,我刚刚意识到我误解了 ssh 命令的作用。它打开一个可以在 localhost 访问的端口。问题是(AFAIK)我不能告诉命令行应用程序使用 localhost 而不是服务器。所以端口隧道工作,我只是不能告诉命令行工具。
  • 所以你有一个命令行工具,你不能指示它去以外的任何地方。它是通过ip还是通过主机名绑定的?如果是主机名,您可以在本地主机文件中创建一个指向 127.0.0.1 的条目
  • 谢谢@nissefors,是的,应该可以。
猜你喜欢
  • 2010-11-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-06
  • 2012-02-06
  • 2011-01-17
  • 1970-01-01
相关资源
最近更新 更多