ssh隧道常用命令
ServerA:10.1.0.1
ServerB:10.1.0.2
ServerA中并不存在mysql服务。
ServerB中已经安装了mysql服务,mysql服务已经启动并监听了3306端口。
从serverA 上做SSH
本地转发
-
ssh -L 9906:10.1.0.2:3306 root@10.1.0.2
不可以关闭隧道的 ssh连接 -
ssh -f -N -L 9906:10.1.0.2:3306 root@10.1.0.2
-f -N配合一起,可以关闭第一次的 ssh连接 -
ssh -f -N -L 10.1.0.1:9906:10.1.0.2:3306 root@10.1.0.2
这个用法,会让serverA 的 IP 10.1.0.1的端口9906暴露在外 -
ssh -g -f -N -L 9906:10.1.0.2:3306 root@10.1.0.2
这个用法,会让serverA 的 所有IP 的端口9906暴露在外, -g是开启网关功能
远程转发
从serverB上做ssh
ssh -f -N -R 9906:10.1.0.2:3306 root@10.1.0.1
这样就行了,
ssh -f -N -R 10.1.0.1:9906:10.1.0.2:3306 root@10.1.0.1
在ServerB中执行上述命令时指定了IP或者开启了网关功能,ServerA的9906端口仍然只监听在127.0.0.1上,当然,如果你一心想要通过别的主机访问ServerA的9906端口,也可以使用其他程序去反代ServerA的9906端口,还有,我在实际的使用过程中,如果使用远程转发穿透到内网,ssh隧道将会非常不稳定,隧道会莫名其妙的消失或者失效,特别是在没有固定IP的网络内
详细的学习资料,请参考http://www.zsythink.net/archives/2450
相关文章
- vscode remote-ssh 远程开发
- ssh(Spring+Spring mvc+hibernate)——EmpDaoImpl.java
- ssh(Spring+Spring mvc+hibernate)——Dept.hbm.xml
- git: windows git ssh keys生成
- linux中解决SSH连接慢问题 关键点GSSAPIAuthentication
- ssh的tunnel设置+autossh设置
- ssh配置连接
- ubuntu使用ssh登入不执行.bashrc解决方法
- Permissions 0644 for ‘/root/.ssh/id_rsa’ are too open处理
- 遇到问题之-一次诡异的ssh远程时断时续问题
- 05-rsync与ssh访问流程区别
- 【大数据开发运维解决方案】做SSH免密通信后仍需输入密码问题解决
- [Azure - VM] 解决办法:无法通过SSH连接VM 解决错误 This service allows sftp connections only.