ssh -D -L -R 差异

需要sshd的host,执行命令时就要输入host的密码,或者host上有登陆机的公钥。

yes 表示ssh会自动监听,listen表示需其他主动监听。

1. ssh -D port host

记执行命令的机器为local。

port sshd
local yes no
host no yes

相当与在local:port有一个代理,实际请求由host发出,host不涉及监听port问题。

记三台机器分别为host1,host2,host3。目标为通过host3将host1:port1的数据转发给host2:port2。

2. ssh -L port1:host2:port2 host3

port1 port2 sshd run forward
host1 yes no no yes no
host2 no listen no no no
host3 no no yes no yes

命令必须在host1上执行,host3必须有sshd。

3. ssh -R port1:host2:port2 host1

port1 port2 sshd run forward
host1 yes no yes no no
host2 no listen no no no
host3 no no no yes

yes

命令必须在host3上执行,host1必须有sshd。

实际情况中,可能某2台host相同,或者3台host全部相同,或者2端口相同。

应根据需要监听的端口,需要转发的端口,以及sshd的位置,选择合适的命令。

其他可能用到的选项为

-f 后台运行

-N 不开shell

-T 不分配tty

例:

  ssh -fNTL 8000:127.0.0.1:8000 192.168.1.3

若以host3 为转发机host1 host2 指向以host3为准。

此例中,假定执行机host为192.168.1.2,

实际效果为将192.168.1。2:8000的数据转发给192.168.1.3:8000。

因为192.168.1.3为实际转发机,无论实际监听为127.0.0.1:8000还是0.0.0.0:8000,

192.168.1.2:8000的数据均能正确到达192.168.1.3:8000。

即访问192.168.1.2:8000等同于在192.168.1.3访问127.0.0.1:8000。

posted @ 2013-10-19 23:36  国超  阅读(10431)  评论(0编辑  收藏  举报