有勇气的牛排博客

ssh端口转发

有勇气的牛排 917 linux 2021-10-13 14:09:34

1 本地端口转发

本地计算机访问远程计算机

ssh -L local-port:target-host:target-port tunnel-host

-L:本地转发

local-port:本地端口

target-host:目标服务器

targe-port:目标服务器端口

tunnel-host:ssh跳板机

1.1 场景举例 web

有一个跳板机,现要将一个网站通过跳板机映射到自己的虚拟机linux的5566端口

ssh -L 5566:www.xx.net:8081 121.xx.xx.124 -N

此时访问本机5566就是目标主机所代理的站点

curl http://localhost:5566

本地端口转发采用 HTTP 协议,不用转成 SOCKS5 协议

2 远程端口转发

远程计算机访问本地计算机

ssh -R remote-port:target-host:target-port -N remotehost

-R:远程端口转发

remote-port:远程计算机端口

target-host:目标服务器

target-port:目标服务器端口

remotehost:远程计算机

2.1 内网穿透

场景:内网主机开了一个80端口的web服务,将这个端口映射到公网ip地址xx的8089端口,并访问此端口

ssh -R 80:www.920vip.net:80 -N 121.37.71.124
ssh -T -N -R 80:192.168.56.6:8888 -N 121.37.71.124

3 动态端口转发

参考地址:

https://wangdoc.com/ssh/port-forwarding.html


留言

专栏
文章
加入群聊