Linux使用SSH端口转发

一、本地端口转发

 ssh -L [本地IP]:本地Port:目标IP:目标Port user@server

例如
在自己的电脑上使用

ssh -L 192.168.6.233:8080:baidu.com:80   test@云服务器

通过 云服务器 访问baidu.com80端口,然后再转给本机192.168.6.233
ssh断开,转发也断开

一、远程端口转发


需要私网服务器发起
并且云服务器需要开启ssh端口网关

vi /etc/ssh/sshd_config
    添加:
        GatewayPorts yes
重启sshd

私网服务器发起

ssh -R 云服务器:8080:192.168.7.11:80 test@云服务器

客户端访问 云服务器:8080即可

此方法可以用作跳板机转发ssh端口

远程端口实用性强

此文章参考bilibili的up主DavyCloud:
https://www.bilibili.com/video/BV1C7411P7Er?p=3

Comments

No comments yet. Why don’t you start the discussion?

发表评论

邮箱地址不会被公开。