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

ssh port forwarding with permament connection between remote and destination

· 52CE 我爱测

I know you can use ssh to forward a local or remote port to another destination and port. So for example let's say I have this command: ssh -L *:8443:10.0.0.1:443 [email omitted] So this allow to open a listening socket on the ma…

问题原文

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

I know you can use ssh to forward a local or remote port to another destination and port. So for example let's say I have this command:

ssh -L *:8443:10.0.0.1:443 [email omitted]

So this allow to open a listening socket on the machine where the command is issued (let's say that its ip is 10.0.0.3) on port 8443. When some client connect to 10.0.0.3:8443 the packets flow through the ssh channel established between 10.0.0.3 and 10.0.0.2 then the ssh server on 10.0.0.2 forward the packets to the destination which is in this case 10.0.0.1:443.

I'm wondering if the server 10.0.0.2 can makes a permanent connection to 10.0.0.1:443 so that the connection 10.0.0.2:xxxxx -> 10.0.0.1:443 is opened once and never dropped. All the traffic coming from the clients connecting to 10.0.0.3:8443 should use this permanent channel.

So basically I don't want that when a new client connect to 10.0.0.3:8443 a new channel 10.0.0.2:xxxxx -> 10.0.0.1:443 is established. This prevent me from reusing the same session and invalidate a the request sent by another client after the first one.

已采纳解答

原帖链接 · Steffen Ullrich · CC BY-SA 4.0

One cannot do this with SSH. And such a generic approach would not be a good idea in the first place anyway.

TCP is a byte stream and not a message protocol. This means if multiple clients send messages in parallel, then the messages might be mixed up. The resulting data might start with the beginning of msgA from client A, continue with parts from msgB from client B, the continue with another part from msgA etc.

Thus, instead of a generic approach one would actually need a mixer which understands the specific application protocol spoken and would make sure that the message syntax in the merged data stream is preserved, no matter how the clients send the messages.

Note that this would be different with UDP since UDP is message based. But your use case seems to be TCP.

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

资料来源与适用范围

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

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

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