通过设置 http_proxy 和 https_proxy 能够使当前机器访问外网时指向代理。

参考链接

  • How to set up proxy using http_proxy & https_proxy environment variable in Linux?,https://www.golinuxcloud.com/set-up-proxy-http-proxy-environment-variable/

    查看代理

    1. echo $http_proxy
    2. echo $https_proxy

    代理设置效果

    The http_proxy and https_proxy environment variable is used to specify proxy settings to client programs such as curl and wget.
    当设置了 https_proxyhttp_proxy 变量时,客户端程序如 curl 和 wget 都会使用该代理。

    代理语法

  • 没有密码:

    1. export http_proxy=http://SERVER:PORT/
  • 使用用户密码

  1. # export http_proxy=http://USERNAME:PASSWORD@SERVER:PORT/
  • 使用用户密码+域名
  1. # export http_proxy=http://DOMAIN\\USERNAME:PASSWORD@SERVER:PORT/

实战-设置代理

把当前机器指向另外的机器:

  1. #export proxy="http://swproxy:Qwe123456@47.101.143.53:80"
  2. #export all_proxy=$proxy
  3. #export http_proxy=$proxy
  4. #export https_proxy=$proxy
  5. #export no_proxy="localhost,127.0.0.1,0.0.0.0,::1"
  6. #export ALL_PROXY=$proxy
  7. #export HTTP_PROXY=$proxy
  8. #export HTTPS_PROXY=$proxy
  9. #export NO_PROXY="localhost,127.0.0.1,0.0.0.0,::1"