在日常工作过程中, 常常会因为受限网络而造成阻碍和困扰, 所以, 为解决这个问题, 通过以下方式, 可以让我们轻松实现本地能访问的网络, 服务器也能访问
PS: 我这里在本地加了一层proxyman用于方便监控服务器流量, 然后再通过其他代理软件去访问网络
本地操作
在~/.ssh/config
中添加以下配置
Host centos.company
HostName 183.0.1.196
User root
IdentityFile ~/.ssh/id_ed25519
ForwardAgent yes
# 作用: 在服务器中访问localhost:9090的流量将转发到本地电脑的localhost:9090中
RemoteForward 9090 localhost:9090
通过以下命令连接远程服务器
ssh centos.company
服务器操作
在远程服务器中执行以下命令, 将流量代理到本地电脑
export https_proxy=http://localhost:9090 http_proxy=http://localhost:9090
验证
# 应返回本地Mac的公网IP
curl -x http://localhost:9090 https://ifconfig.me
通过以上方式, 就能解决服务器不方便访问受限网络的问题了