ssh 设置本地转发和远程转发

SSH 本地转发

192.168.0.10 mac 机器
192.168.0.101 虚拟机
mac 上运行

sudo python -m http.server 80

Serving HTTP on :: port 80 (http://[::]:80/) ...




登陆虚拟机ssh 执行

ssh -fNL 8089:192.168.0.10:80 yons@192.168.0.10


[root@localhost ~]# wget 127.0.0.1:8089
--2020-11-22 21:22:35--  http://127.0.0.1:8089/
正在连接 127.0.0.1:8089... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:20 [text/html]
正在保存至: “index.html.1”

100%[============================================================================================>] 20          --.-K/s 用时 0.04s   


[root@localhost ~]# cat index.html.1 
<h1> local web</h1>





远程代理

在mac 机器上执行

ssh -fNR 10023:192.168.0.10:80 root@139.224.211.0

登陆 阿里云主机 安全组要允许10023 进来,
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 2451 root 8u IPv4 34089 0t0 TCP localhost:10023 (LISTEN)

root@aliyun:~# curl 127.0.0.1:10023

local web

原文地址:https://www.cnblogs.com/ruhai/p/14021774.html