ssh隧道与端口转发

1、正向代理(Forward Proxy)
Lhost--》proxy--》Rhost
Lhost为了访问到Rhost,向proxy发送了一个请求并且指定目标是Rhost,然后proxy向Rhost转交请求并将获得的内容返回给Lhost,简单来说正向代理就是proxy代替了我们去访问Rhost。
2、反向代理(reverse proxy)
Lhost<--->proxy<--->firewall<--->Rhost
Lhost只向proxy发送普通的请求,具体让他转到哪里,proxy自己判断,然后将返回的数据递交回来
3、SSH隧道
3.1、正向隧道,监听本地port
ssh -qTfnN -L port:host:hostport -l user remote_ip
3.2、反向隧道,用于内网穿透防火墙限制之类
ssh -qTfnN -R port:host:hostport -l user remote_ip
3.3、直接进行socks代理
ssh -qTfnN -D port remotehost

参数备注:
-q Quiet mode. 安静模式
-T Disable pseudo-tty allocation. 不占用 shell 了
-f Requests ssh to go to background just before command execution. 后台运行,并推荐加上 -n 参数
-N Do not execute a remote command. 不执行远程命令,端口转发就用它了

4、SSH端口转发
4.1、本地转发
ssh -CfNg -L port1:127.0.0.1:port2 user@host
4.2、远程转发
ssh -CfNg -R port2:127.0.0.1:port1 user@host
参数备注:
-C 所有通过 SSH 发送或接收的数据将会被压缩
-g Allows remote hosts to connect to local forwarded ports