SSH 端口转发配置问题

2015-06-29 18:54:45 +08:00
 uutoto

SSH端口转发,想把http://hostA:3555 映射到hostB的 http://127.0.0.1:8090

hostA的用户名是:tt
hostA上SSH服务器端口号为:44444

hostB上执行:

ssh -C -f -N -g -R 3555:127.0.0.1:8090 -p 44444 tt@hostA

可就是没法通过http://hostA:3555访问到127.0.0.1:8090的一个网页啊。。
网页代码是:

import tornado.web
import tornado.ioloop
import time

class MainHandle(tornado.web.RequestHandler):
    def get(self):
        print("hello!",time.asctime())
        self.write("hello!")

if __name__ == "__main__":
    app = tornado.web.Application([(".*", MainHandle)])
    app.listen(8090)
    tornado.ioloop.IOLoop.instance().start()

本地都可以访问的

指点一下,万分感激!

2417 次点击
所在节点    Linux
8 条回复
nekoyaki
2015-06-29 19:00:21 +08:00
HostA的ssh配置文件里加一条: GatewayPorts yes
uutoto
2015-06-30 10:03:58 +08:00
@nekoyaki O(∩_∩)O谢谢啦,昨天没有root权限,改不了。后来在本地装了虚拟机试了。
yingluck
2015-06-30 18:59:53 +08:00
楼主 这个映射是不会暴露到公网上的

你去 HostA 上面 curl 一下 127.0.0.1:3555 就知道了
cattyhouse
2015-07-01 20:58:41 +08:00
Host A:

ssh -N -q -R 8090:hostA:44444 user@hostB

然后在hostB上:

ssh tt@127.0.0.1 -p 44444 就能进入hostA,3555不需要是摆设。
cattyhouse
2015-07-01 21:00:52 +08:00
修改:
在host B上 :

ssh tt@127.0.0.1 -p 8090
cattyhouse
2015-07-01 21:03:16 +08:00
你到底要映射ssh还是映射端口?如果映射ssh的话,就像楼上的,
映射端口的话,不需要ssh了,在hostB上运行iptables就可以了
cattyhouse
2015-07-01 21:27:38 +08:00
我觉得ssh应该在hostA上执行吧?试试这个:

在HostA上执行:
ssh -NT -q -R 8090:ip_of_hostA:3555 username_of_hostB@ip_of_hostB
然后在HostB上:
telnet 127.0.0.1 8090
cattyhouse
2015-07-01 21:38:03 +08:00
Sorry 忽略我以上的回答:


-R
.....
By default, the listening socket on the server will be bound to the loopback interface only. This may be overridden by specifying a bind_address. An empty bind_address, or the address `*', indicates that the remote socketshould listen on all interfaces. Specifying a remote bind_address will only succeed if the server's GatewayPorts option is enabled (see sshd_config(5)).
.....
根据以上的man ssh的信息:所以楼主要做的就是:

1,编辑HostA的 /etc/ssh/ssd_config 然后加入
GatewayPorts yes

2. 在HostB上执行:

ssh -N -T -q -R *:3555:127.0.0.1:8090 -p 44444 tt@hostA
或者
ssh -N -T -q -R :3555:127.0.0.1:8090 -p 44444 tt@hostA
或者
ssh -N -T -q -R hostA_ip_address:3555:127.0.0.1:8090 -p 44444 tt@hostA

注意要在3555前面加上 *: 或者只加 : 或者将 * 替换成 hostA的IP地址,因为不加这个的话,默认绑定到hostA的127.0.0.1上。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/201985

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX