大网数据广告活动
服务器运维问答

Remote port forwarding on SSH server to access internal application server

· 52CE 我爱测

I am trying to figure out SSH port forwarding and have not found success from looking at different questions and tutorials, it seems that everything I have seen is just a little different than my situation and I can't quite figur…

问题原文

原帖链接 · Jtt3mr · CC BY-SA 4.0

I am trying to figure out SSH port forwarding and have not found success from looking at different questions and tutorials, it seems that everything I have seen is just a little different than my situation and I can't quite figure out how to apply it to mine.

I am running an application (A) from a Windows machine in an internal network (22.22.22.xx). This application must be hosted on this network. I also have a Linux SSH client/server (S) on a machine that has a network adapter card for the (22.22.22.xx) network as well as one for the (11.11.11.xx) network. I have an application client (C) running on Windows that has access to the SSH client but does not have access to the (22.22.22.xx) network therefore cannot access A directly. The set up is displayed below.

I am trying to set up port forwarding from the SSH server so that the application client can reach the application server.

So far, I have been able to get local port forwarding working using PuTTY on the application client. I used this command (entered on PuTTY's UI):

ssh -L 8888:22.22.22.5:5555 [email omitted]

From here I am able to go to localhost:8888 on 'C' and am tunneled through 'S' to reach the page being served on 'A'. However, in a perfect world, I would like to not have to open and run PuTTY on the client every time to access the page.

So, I am trying to find a way to set up remote port forwarding to forward a port, say 4444, on 'S' to 'A'. So that from 'C' I could simply go to 11.11.11.4:4444 and I am tunneled into 22.22.22.5:5555.

So far, I have tried running this on the command line in 'S':

ssh -R 4444:22.22.22.5:5555 user@localhost -o GatewayPorts=yes

When I ran this, it looked like I ssh-ed right back into the machine, I entered the credentials and tried going to 11.11.11.4:4444 from the client and I was not directed to the server. I also tried running this command (but from PuTTY) on 'A':

ssh -R 4444:localhost:5555 [email omitted] -o GatewayPorts=yes

From this I got a 'Remote port forwarding failed' message in the PuTTY event log.

I feel like I am very close to the solution and just have something confused in my commands or I am way off and don't understand what is going on at all.

已采纳解答

原帖链接 · RalfFriedl · CC BY-SA 4.0

You don't want a remote/reverse forwarding, although with the local version (your first example) there would be little difference, except it needs configuration on the server. The option GatewayPorts=yes is for the ssh server, not for the ssh client.

Try on the server S

ssh -g -L 4444:22.22.22.5:5555 user@localhost

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-08-22)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。