科学上网-让终端走代理

介绍

在终端环境下,常会遇到要下载某个文件巨慢,甚至无法连接,急需一个方案来拯救.

过程

  1. 临时

    # 协议填http或socks5
    export http_proxy="http://127.0.0.1:10809"
    export https_proxy="https://127.0.0.1:10809"
    export http_proxy="socks5://127.0.0.1:10808"
    export https_proxy="socks5://127.0.0.1:10808"
    # 让环境生效
    source /etc/profile
    # ping是ICMP报文,代理不转发
    # 检查终端是否处于代理状态
    curl cip.cc 
  2. 或使用 alias

    alias setproxy='export ALL_PROXY=socks5://127.0.0.1:10808'
    alias unsetproxy='unset ALL_PROXY'
  3. ssh走代理 新增 ~/.ssh/config ::: code-group

    # github socks5 
    Host github.com
        HostName github.com
        User git
        Port 22
        IdentityFile ~/.ssh/id_ed25519
        ProxyCommand nc -v -x 127.0.0.1:10808 %h %p
    
    # github http
    Host github.com
        HostName github.com
        User git
        Port 22
        IdentityFile ~/.ssh/id_ed25519
        ProxyCommand corkscrew 127.0.0.1:10809 %h %p
    # linux需要单独安装 `corkscrew`
    # sudo apt install corkscrew
    # 测试 SSH 连接(看到下面提示说明成功)
    ssh -T git@github.com
    # 成功提示:
    # Hi 用户名! You've successfully authenticated, but GitHub does not provide shell access.
    
    git clone --depth 1 https://github.com/用户名/项目名.git

    ::: code-group

  4. curl走代理 新增 ~/.curlrc

    proxy = http://127.0.0.1:10809

在windows WSL中配置代理

在windows CMD中配置代理

参考

Last updated

Was this helpful?