SSH Tunnel结合本地代理案例
通过本地电脑作为代理给远程服务器访问
可以通过本地电脑作为代理,帮助远程服务器访问外网。常见的方法是使用 SSH 隧道(SSH Tunnel)结合本地代理来实现。以下是一个实现思路:
# 操作步骤
以 7890 作为端口转发为例子
ssh -R 7890:localhost:7890 ubuntu@<hostname/ip>: 将远程服务器(<hostname/ip>)的 7890 端口,通过 SSH 隧道映射到本地机器的 7890 端口。这样,远程服务器上的任何发往端口 7890 的流量都会通过 SSH 隧道被转发到你本地机器的端口 7890
-R 7890:localhost:7890: This is the option to set up a reverse tunnel. It tells SSH to forward the port on the remote server back to the local machine.-R: The reverse tunnel option. It forwards a port from the remote server back to the local machine.7890:localhost:7890: This means:- Forward traffic from port 7890 on the remote server (
<hostname/ip>). - To
localhost:7890on the local machine (i.e., localhost is the machine from which you're initiating the SSH connection).
- Forward traffic from port 7890 on the remote server (
- 在 remote 端,使网络走端口 7890:
export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890
# issue
# 远程服务器拒绝了连接
ssh -R 7890:localhost:7890 ubuntu@VM-4-9-ubuntu
kex_exchange_identification: Connection closed by remote host
Connection closed by 127.0.0.1 port 7890
1
2
3
2
3
上次更新: 2024/12/01, 17:09:08