博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ssh 隧道
阅读量:2062 次
发布时间:2019-04-29

本文共 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/

你可能感兴趣的文章
【python】re模块常用方法
查看>>
剑指offer 19.二叉树的镜像
查看>>
剑指offer 20.顺时针打印矩阵
查看>>
剑指offer 21.包含min函数的栈
查看>>
剑指offer 23.从上往下打印二叉树
查看>>
剑指offer 25.二叉树中和为某一值的路径
查看>>
剑指offer 26. 数组中出现次数超过一半的数字
查看>>
剑指offer 27.二叉树的深度
查看>>
剑指offer 29.字符串的排列
查看>>
剑指offer 31.最小的k个树
查看>>
剑指offer 32.整数中1出现的次数
查看>>
剑指offer 33.第一个只出现一次的字符
查看>>
剑指offer 34.把数组排成最小的数
查看>>
剑指offer 35.数组中只出现一次的数字
查看>>
剑指offer 36.数字在排序数组中出现的次数
查看>>
剑指offer 37.数组中重复的数字
查看>>
剑指offer 38.丑数
查看>>
剑指offer 39.构建乘积数组
查看>>
剑指offer 57. 删除链表中重复的结点
查看>>
剑指offer 58. 链表中环的入口结点
查看>>