一、配置环境变量(适用于终端和大多数 CLI 工具)
编辑当前用户的 shell 配置文件(以 bash 为例):以代理IP:192.168.100.6:20171为例
nano ~/.bashrc添加以下内容:
export http_proxy="http://192.168.100.6:20171"
export https_proxy="http://192.168.100.6:20171"
export ftp_proxy="http://192.168.100.6:20171"
export no_proxy="localhost,127.0.0.1"然后执行:
source ~/.bashrc如果你使用的是 root,需要编辑 /root/.bashrc
二、配置 apt 使用代理
编辑 apt 配置:
sudo nano /etc/apt/apt.conf.d/95proxies添加内容:
Acquire::http::Proxy "http://192.168.100.6:20171/";
Acquire::https::Proxy "http://192.168.100.6:20171/";然后执行:
sudo apt update三、配置 wget使用代理
编辑配置文件:
nano ~/.wgetrc添加:
http_proxy = http://192.168.100.6:20171/
https_proxy = http://192.168.100.6:20171/四、配置 curl使用代理
编辑配置文件:
nano ~/.curlrc添加:
proxy = "http://192.168.100.6:20171"五、测试代理是否生效
测试代理能否访问互联网(例如 Google):
curl -I -x http://192.168.100.6:20171 http://www.google.com六、取消代理(恢复原样)
如果你之后不想走代理,可以执行:
unset http_proxy https_proxy ftp_proxy no_proxy并从 ~/.bashrc 或 /etc/apt/apt.conf.d/95proxies 中删除相关行即可。
评论区