知道如果一个远程端口转发成功? [英] Knowing if a remote port forward was successful?

查看:2562
本文介绍了知道如果一个远程端口转发成功?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立一些反向SSH隧道进行这样我就可以通过反弹一些服务器公网IP访问我的家庭网络。

I am trying to setup some reverse ssh tunnels so I can access my home network by bouncing off some server with a public IP.

当我运行以下命令:
SSH -R:[port_XX]:本地主机:22 some_user @ my_server的

When I run this command: ssh -R :[port_XX]:localhost:22 some_user@my_server

即使port_XX在使用中,它仍然会成为一个成功的ssh连接到my_server的。

Even if "port_XX" is in use, it will still make a successful ssh connection to "my_server".

如果我直接运行此命令,我可以看到这个问题时,它给了我一个警告:
警告:远程端口转发失败监听端口[port_XX]

If I am running this command directly, I can see the problem when it gives me a warning: "Warning: remote port forwarding failed for listen port [port_XX]"

不过,我开始这个SSH会话的屏幕会话中使用cron作业。

However, I am starting this ssh session inside a screen session using a cron job.

如何可以以编程方式检查远程端口转发成功?

屏幕会话可以用画面-ls,SSH会话也容易检查,但远程端口转发检查...?

The screen session can be checked with "screen -ls", the ssh session is also easily checked, but the remote port forwarding...?

(请让我知道,如果这个问题不够清楚!我做我的研究,但还没有找到一个简单的解决方案。)

(Please let me know if this question is not clear enough! I've done my research but haven't found a simple solution.)

推荐答案

尝试添加 -o ExitOnForwardFailure = YES

完整的命令将是这样的:

The full command will be something like:

ssh -N -R [port_XX]:localhost:22 -o ExitOnForwardFailure=yes user@host

-N 是只转发端口有用,而无需打开一个远程shell,你也可以添加 -f 在后台发送过程中,没有必要,如果你在屏幕上运行,但..)

(-N is useful to just forward port, without opening a remote shell; you can also add -f to send process in background, no need if you are running under screen, though..)

这篇关于知道如果一个远程端口转发成功?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆