linux - 通过 VNC 笔记本电脑从防火墙后面到远程服务器的端口隧道?

标签 linux networking ssh firewall

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

我能够通过 VNC 将笔记本电脑连接到网络,并且笔记本电脑使用 WiFi 连接,可以通过端口访问远程服务器。连接后,我可以从安全网络 ssh 到我的笔记本电脑。

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

非常感谢。

最佳答案

如果我理解正确,您可以从您所在的位置调用 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.

关于linux - 通过 VNC 笔记本电脑从防火墙后面到远程服务器的端口隧道?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47423321/

相关文章:

c - pthread_join() 如何确定被调用/等待线程已终止

linux - Bash - 终端错误 : "-bash: export: ` GOPATH~/usr/go': not a valid identifier"

c - snprintf 在被复制的字符串中使用格式说明符

Linux 临时模式

linux - ssh 隧道命令输出到文件

node.js - 格式化我的 Linux 分区后无法运行 Node 项目

networking - 无法使用端口 8080 访问在 Raspberry Pi 上运行的 Jenkins

networking - 此错误纠正方法的正确名称是什么(类似于汉明代码)

git - 如何告诉 Git(Windows 上的 msysgit)使用 ssh 而不是 pageant

shell - 使用expect、ssh、ant和mysqldump时正确转义引号和括号