利用ssh反向代理使服务器能够访问外网
配置 .ssh/config:
Host 88
HostName {ip address of host}
User {your username}
Port {your port}
接着,在本地运行代理:
ssh -N -R 7890:localhost:7890 88
如果有 Warning: remote port forwarding failed for listen port 7890,那么需要重新配置一下服务器上的内容:
编辑 /etc/ssh/sshd_config:
sudo nano /etc/ssh/sshd_config
确保这几行存在并如下配置:
GatewayPorts yes
AllowTcpForwarding yes
PermitOpen any
然后重启 SSH 服务:
sudo systemctl restart sshd
也可能是服务器上有正在运行的占用7890端口的进程:
netstat -anp | grep 7890
如果有的话,就kill掉
接着,在服务器上运行:
export all_proxy=localhost:7890
(这步如果不行的话可以试试:
export https_proxy=http://127.0.0.1:7890
export http_proxy=http://127.0.0.1:7890
注意都是 http
)
可以测试一下:curl www.google.com

浙公网安备 33010602011771号