ssh 端口转发

本地端口转发

本地 3000 端口流量转发到远程

1
2
-L 本地网卡地址:本地端口:目标地址:目标端口
ssh -L 3000:localhost:3000 root@server

远程端口转发

远程 3000 端口流量转发到本地

1
2
-R 远程网卡地址:远程端口:目标地址:目标端口
ssh -R 2000:192.168.3.200:3000 root@server

动态端口转发

本地 3000 端口流量转发到服务器对应端口

1
2
-D 本地网卡地址:本地端口
ssh -D localhost:3000 root@server

参数:

1
2
3
4
5
-q :- be very quite, we are  acting only as a tunnel.
-T :- Do not allocate a pseudo tty, we are only acting a tunnel.
-f :- move the ssh process to background, as we don’t want to interact with this ssh session directly.
-N :- Do not execute remote command.
-n :- redirect standard input to /dev/null.