本文共 1167 字,大约阅读时间需要 3 分钟。
假定有三台服务器host1,host2,host3.想要通过host1达到不了host3服务器,host2可以到达host3,这个时候host2作为ssh隧道的forward也就是转发服务器.为方便理解port对应服务器.
ssh 命令
-p 端口-i -F 秘钥文件-N 不打开shell-f 后台开启-R 远程-L 本地T 不分配tty
首先设置host2隧道转发
vim /etc/ssh/sshd_config设置PermitTunnel yes #允许隧道转发GatewayPorts yes #允许端口转发PasswordAuthentication yes #允许使用密码登入服务器本地转发
ssh -fNL port1:host3:port3 root@host2本地转发本地端口,目标服务器ip,目标服务器端口使用root链接forward服务器注:必须是在host1上执行这条命令
port1 | port2 | sshd | run | forward | |
---|---|---|---|---|---|
host1 | yes | no | no | yes | no |
host2 | no | no | yes | no | yes |
host3 | no | listen | no | no | no |
远程转发
ssh -RNf port1:host2:host2 root@host1远程转发host1的端口,目标服务器ip,目标服务器端口使用root链接客户端服务器相当于反向代理注:必须是在host2上执行这条命令,host1必须有sshd,这里前提是host1和host2能相互访问.
port1 | port2 | sshd | run | forward | |
---|---|---|---|---|---|
host1 | yes | no | yes | no | no |
host2 | no | no | no | yes | yes |
host3 | no | listen | no | no | no |
实战
假设host1和host3分别在不同内网,想通过host1直接访问host3第一步host3 链接forwardssh -NfR 0.0.0.0:port2:127.0.0.1(host3):port3 root@host2host3上执行,forward的port2在公网监听,通过port2转发到host3服务端口port3在host1上执行 ssh -p port2 host2,可以直接访问到host2第二步在host1上执行ssh -NfL port1-1:127.0.0.1(host1):port1-2 root@host2这一步某些时候有用只是在本地端口port1-1 相当于在host1上执行ssh -p port1-1 host1
开启目标服务器所有端口
ssh -D :1116 && \ ssh -RNf 9999(forword):127.0.0.1:1116 host(forword)
转载地址:http://bzelf.baihongyu.com/