如何通过 ssh 连接到多个防火墙后面的远程服务器?

发布于 2024-10-09 19:19:41 字数 1459 浏览 6 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜未央樱花落 2024-10-16 19:19:42

您想要设置 SSH 隧道 以允许像这样的 SSH:

A => B
B => C

这是一个示例如何在 Linux 上通过 A 设置到 B 的隧道:

ssh -f myusername@hostA -N -L 4444:hostB:22

然后,您应该能够 ssh 到主机 A 上的端口 4444,并将其转发到主机 B 上的端口 22(通常运行 SSH)。运行上述命令后,尝试以下操作:

ssh -p 4444 hostA

这应该将您连接到 hostB。您可能必须更改端口才能使其正常工作,如果主机A 上的端口 4444 已被使用,您将必须选择其他端口。假设这可行,您可以使用相同的命令和不同的主机名来设置来自 B => 的隧道。 C:

ssh -f myusername@hostA -N -L 4444:hostB:4444
ssh -f myusername@hostB -N -L 4444:hostC:22

如果您想为网页浏览设置 SOCKS 代理,这也很有用。我这样做是为了让我的网络流量看起来像是来自我的大学,这样我就可以在线访问科学期刊。

参考文献:

You want to set up SSH tunnels to to allow SSH like this:

A => B
B => C

Here's an example of how to setup the tunnel to B through A on Linux:

ssh -f myusername@hostA -N -L 4444:hostB:22

Then, you should be able to ssh to port 4444 on hostA, and have that forwarded to port 22 (where SSH commonly runs) on hostB. After running the above command, try this:

ssh -p 4444 hostA

That should connect you to hostB. You may have to change ports for this to work, if port 4444 on hostA is already being used you'll have to pick a different port. Assuming that this works, you can use the same command with different hostnames to set up the tunnel from B => C:

ssh -f myusername@hostA -N -L 4444:hostB:4444
ssh -f myusername@hostB -N -L 4444:hostC:22

This is also useful if you want to set up a SOCKS proxy for web browsing. I do this so that my web traffic looks like it's coming from my university, so that I can use online access to scientific journals.

References:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文