SSH Forwarding Question

31 views
Skip to first unread message

Sherlock

unread,
Sep 15, 2014, 10:18:19 AM9/15/14
to Shanghai Linux User Group
Dear all:
    有个非常有挑战的问题,有兴趣的朋友可以尝试下。
ssh 有个 forwarding功能可以转发数据包 并且是加密方式。实验内容大致是这样的
一共有4台机器 A,B,C,D 只有C有公网地址
A eth0 10.10.10.66
B eth0 10.10.10.44 eth1 192.168.100.2
C eth0 218.176.44.137 eth1 192.168.0.22
D eth0 192.168.0.21

A和B直连 , B的eth1 是通过3G 上网,只有内网地址 ,但可以访问internet (SNAT)
C是ssh server
D和C直连 192.168.0.0/24

原本实验打算在B机器上先做PREROUTING (DNAT) 这样可以让外网访问到A机器。
然后B的eth1通过3G网络 ssh 连接到C机器,同时在C机器上做端口转发
比如 在B机器上 ssh -g -R 1099:218.176.44.137:1099 -l us...@218.176.44.137
B机器上的ssh server listen 端口是 1099

现在实验做下来,在B机器上能成功建立转发到C机器上, 通过debug能提示端口转发的连接是成功建立的。
然后在D机器上访问 C的 公网1099端口,理论上会转发到B 机器上的1099,但实际操作的时候会提示connection refused
原来第一反应是防火墙之类的问题,把B和C机器上的iptables都关掉,host.deny 和host.allow都去掉。重新再试还是同样的结果。
难道是ssh port forwarding不支持 ssh ? 还是其他原因呢?

--
==========
      InitX
==========

Sherlock

unread,
Sep 15, 2014, 10:21:47 AM9/15/14
to Shanghai Linux User Group
sorry  补充一下
1099端口是 B机器的ssh server的listen端口
--
==========
      InitX
==========

李晓岚

unread,
Sep 15, 2014, 12:29:29 PM9/15/14
to sh...@googlegroups.com

-R参数local和remote需要按照转发的方向来理解,而不是ssh连接的方向,貌似你理解错了。在B机器上ssh -g -R 1099:localhost:1099 ...
这里的localhost是指B。

On Sep 15, 2014 10:18 PM, "Sherlock" <initx...@gmail.com> wrote:

Sherlock

unread,
Sep 15, 2014, 10:13:09 PM9/15/14
to Shanghai Linux User Group
我试了下,的确是。毫无挑战性可言 sigh
另外我试了下 ssh -g -R  C机公网IP:1099:B'IP:1099 好像还是只能从127.0.0.1进去,公网上没在listen

--
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN
---
您收到此邮件是因为您订阅了Google网上论坛中的“Shanghai Linux User Group”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到shlug+un...@googlegroups.com
要查看更多选项,请访问https://groups.google.com/d/optout



--
==========
      InitX
==========

李晓岚

unread,
Sep 15, 2014, 10:21:28 PM9/15/14
to sh...@googlegroups.com
不应该,你都指定C的公网IP了。
不过可以用-R 0.0.0.0:1099:B'IP:1099试试。


--
不学无术

Heiher

unread,
Sep 15, 2014, 10:26:16 PM9/15/14
to shlug
是的,很明显的就是地址绑定问题。
Best regards!
Heiher
http://hev.cc

李晓岚

unread,
Sep 15, 2014, 10:28:30 PM9/15/14
to sh...@googlegroups.com
刚看了下手册,Specifying a remote bind_address will only succeed if the server's GatewayPorts option is enabled (see sshd_config(5)).
应该是这个原因。

--
不学无术

2014-09-16 10:12 GMT+08:00 Sherlock <initx...@gmail.com>:

Sherlock

unread,
Sep 15, 2014, 10:47:28 PM9/15/14
to Shanghai Linux User Group
ok 搞定了,
C上要把Gateway Port 打开
从B连接到C ssh -g -R B'IP:port:A'IP:port 然后就可以从D访问A了,连DNAT也省了。
这个做内网穿透真心不错, linux的SSH果然是神器啊

Heiher

unread,
Sep 15, 2014, 10:55:17 PM9/15/14
to shlug
其实也不是很好,首先SSH遂道是加密、压缩的,CPU使用高,另外TCP端口转发是连接复用的。

2014-09-16 10:47 GMT+08:00 Sherlock <initx...@gmail.com>:

Sherlock

unread,
Sep 15, 2014, 11:16:19 PM9/15/14
to Shanghai Linux User Group
百兆网络,这点加密解密对如今的CPU来说应该不是太大的问题
何况snowden的事件出来以后,都恨不得所有数据都PGP一下。
TCP 端口转发复用 这个怎么理解?

您收到此邮件是因为您订阅了 Google 网上论坛的“Shanghai Linux User Group”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到shlug+un...@googlegroups.com
要查看更多选项,请访问 https://groups.google.com/d/optout



--
==========
      InitX
==========

Shell Xu

unread,
Sep 16, 2014, 6:36:39 AM9/16/14
to shlug

压缩可以关闭吧。加密协议也可以协商。只是一般服务器的默认ssh给这么一搞就不安全了。

from nexus 4

您收到此邮件是因为您订阅了 Google 网上论坛的“Shanghai Linux User Group”论坛。

依云

unread,
Sep 16, 2014, 8:39:05 AM9/16/14
to sh...@googlegroups.com
On Tue, Sep 16, 2014 at 10:47:24AM +0800, Sherlock wrote:
> ok 搞定了,
> C上要把Gateway Port 打开
> 从B连接到C ssh -g -R B'IP:port:A'IP:port 然后就可以从D访问A了,连DNAT也省了。
> 这个做内网穿透真心不错, linux的SSH果然是神器啊

还可以加上 autossh,这样不用担心 ssh 连接不小心断掉然后再也连不过去了。

--
Best regards,
lilydjwg
Reply all
Reply to author
Forward
0 new messages