Chinaunix

标题: 请教关于SSH端口转发 [打印本页]

作者: bikkuri    时间: 2014-08-21 14:08
标题: 请教关于SSH端口转发
大家好!
我有一个问题向大家请教。
假如我有两台Linux服务器,一台位于互联网上,名为internet_host,另一台位于公司,名为office_host。
office_host位于公司防火墙后面,从internet无法访问office_host。但是从office_host可以访问internet。
我想把office_host上在80端口的Web服务转发到internet_host上的64646端口。
我在office_host上执行下面这条命令以后:
  1. ssh -f -N -L 80:internet_host:64646 -l user internet_host
复制代码
在internet_host上用lynx http://localhost:64646/可以看到位于http://office_host/上的网页。
但是用lynx http://internet_host:64646/却显示无法连接。
然后从internet上别的机器上用浏览器访问http://internet_host:64646/也显示无法连接。
请问我应该怎么做,才能直接访问http://internet_host:64646/就显示位于http://office_host/上的网页呢?
谢谢。
作者: chengchow    时间: 2014-08-21 14:19
为什么不做反向代理,两台服务器不互通吗?
作者: Shell_HAT    时间: 2014-08-21 14:19
用的什么web服务器?
Apache? Ngnix?
作者: HH106    时间: 2014-08-21 14:53
本帖最后由 HH106 于 2014-08-21 15:14 编辑

回复 1# bikkuri
  1. ssh -f -N -g -L 80:internet_host:64646 -l user internet_host
复制代码
  1. ssh -R *:64646:local_host:80 -l user internet_hosh
  2. internet_host 的shd_config中打开了GatewayPorts选项
复制代码

作者: bikkuri    时间: 2014-08-21 17:04
本帖最后由 bikkuri 于 2014-08-21 17:12 编辑

如果直接ssh连的话,office_host可以连接到internet_host,但反过来internet_host就连不上office_host。
反向代理怎么做?

chengchow 发表于 2014-08-21 14:19
为什么不做反向代理,两台服务器不互通吗?

作者: bikkuri    时间: 2014-08-21 17:04
web服务器是Apache。

Shell_HAT 发表于 2014-08-21 14:19
用的什么web服务器?
Apache? Ngnix?

作者: bikkuri    时间: 2014-08-21 17:11
  1. ssh -f -N -g -L 80:internet_host:64646 -l user internet_host
复制代码
报错:
  1. bind: Address already in use
  2. channel_setup_fwd_listener: cannot listen to port: 80
  3. Could not request local forwarding.
复制代码
  1. ssh -R *:64646:localhost:80 -l user internet_host
  2. internet_host 的shd_config中打开了GatewayPorts选项
复制代码
可以执行,但是在internet_host上执行lynx http://internet_host:64646/报错:
  1. Alert!: Unable to connect to remote host.


  2. Looking up internet_host:64646
  3. Making HTTP connection to internet_host:64646
  4. Alert!: Unable to connect to remote host.
复制代码
请问怎么打开GatewayPorts选项?

HH106 发表于 2014-08-21 14:53
回复 1# bikkuri

作者: Shell_HAT    时间: 2014-08-21 17:13
本帖最后由 Shell_HAT 于 2014-08-21 17:17 编辑

回复 6# bikkuri

Apache的ProxyPass可以吗?

在office_host上:
  1. NameVirtualHost *:80
  2. <VirtualHost *:80>
  3.         ProxyPass / http://internet_host:64646/
  4.         ProxyPassReverse / http://internet_host:64646/
  5. </VirtualHost>
复制代码
或者反过来在internet_host上:
  1. NameVirtualHost *:64646
  2. <VirtualHost *:64646>
  3.         ProxyPass / http://office_host:80/
  4.         ProxyPassReverse / http://office_host:80/
  5. </VirtualHost>
复制代码

作者: HH106    时间: 2014-08-21 18:03
本帖最后由 HH106 于 2014-08-21 18:04 编辑

回复 7# bikkuri
  1. 1 internet_host机器
  2. 修改/etc/ssh/sshd_config, 最后增加GatewayPorts on,然后重启sshd服务

  3. 2 office_host机器执行:
  4. ssh -gR *:64646:office_host:80 -l user internet_host

  5. 3 访问http://internet_host:64646即是访问http://office_host
复制代码

作者: bikkuri    时间: 2014-08-21 19:39
谢谢您的回答,但是我只在office_host上有root权限。
在internet_host上只有普通用户权限,因此是无法更改internet_hosts上的任何系统设置的。
如果只在office_host上修改virtual host的话,在公司里访问http://internet_host:64646/应该可以转到访问http://office_host/,但是离开公司就不行了。我希望的主要是在公司以外的地方可以通过访问http://internet_host:64646/来实际访问http://office_host/。


回复 8# Shell_HAT


   
作者: bikkuri    时间: 2014-08-21 19:40
谢谢您的回答,但是我只在office_host上有root权限。
在internet_host上只有普通用户权限,因此是无法更改internet_hosts上的任何系统设置的。



回复 9# HH106


   
作者: Shell_HAT    时间: 2014-08-21 22:24
回复 10# bikkuri


    internet_hosts的权限是必须的,没有权限什么方法都不好使。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2