debian使用代理配置
1、apt 配置代理
仅限软件包管理
vim /etc/apt/apt.conf.d/99proxy
#添加账号密码、服务器、端口
Acquire::http::Proxy "http://username:password@proxyserver:port/";
Acquire::https::Proxy "http://username:password@proxyserver:port/";
centos的dnf直接编辑dnf.conf
vim /etc/dnf/dnf.conf
#在里面添加如下代理信息
[main]
proxy=http://你的代理IP:端口
proxy_username=你的用户名
proxy_password=你的密码
proxy_exclude=localhost,127.0.0.1,.local,.example.com
2、境变量设置代理
当前用户
vim ~/.bashrc
#添加账号密码、服务器、端口
export http_proxy="http://username:password@proxyserver:port/"
export https_proxy="http://username:password@proxyserver:port/"
保存并关闭文件,然后使改动生效:
source ~/.bashrc
或重新登录你的会话
全局变量
所有用户
vim /etc/environment
#添加账号密码、服务器、端口
export http_proxy="http://username:password@proxyserver:port/"
export https_proxy="http://username:password@proxyserver:port/"
保存并关闭文件,然后使改动生效:
source /etc/environment
环境变量区别
| 文件 | 作用范围 | 加载条件 | 适用场景 |
|---|---|---|---|
~/.bashrc | 当前用户 | 打开新终端窗口(非登录 shell) | 用户定制交互式终端的行为和环境变量 |
/etc/environment | 所有用户 | 系统启动(适用于所有程序,包括图形界面程序) | 简单的全局变量设置,不支持复杂语法 |
/etc/profile | 所有用户 | 用户登录(适用于登录 shell) | 定义全局登录 shell 的初始化环境变量 |
3、容器代理
为 Docker 配置 HTTP\SOCKS5 代理(拉取镜像)
创建或编辑 Docker daemon 配置
mkdir -p /etc/docker
#HTTP/HTTPS 代理
tee /etc/docker/daemon.json <<EOF
{
"proxies": {
"http-proxy": "http://user:pass@127.0.0.1:8080",
"https-proxy": "http://user:pass@127.0.0.1:8080",
"no-proxy": "localhost,127.0.0.1,.local"
}
}
EOF
#SOCKS5 代理
tee /etc/docker/daemon.json <<EOF
{
"proxies": {
"http-proxy": "socks5://user:pass@127.0.0.1:1080",
"https-proxy": "socks5://user:pass@127.0.0.1:1080",
"no-proxy": "localhost,127.0.0.1,.local"
}
}
EOF
重载并重启 Docker
systemctl daemon-reload
systemctl restart docker
为 Podman 配置 HTTP\SOCKS5 代理(拉取镜像)
创建 systemd 代理配置目录
mkdir -p /etc/systemd/system/podman.service.d/
创建代理配置文件
vim /etc/systemd/system/podman.service.d/proxy.conf
写入代理配置
#HTTP/HTTPS 代理
[Service]
Environment="HTTP_PROXY=http://127.0.0.1:7890"
Environment="HTTPS_PROXY=http://127.0.0.1:7890"
Environment="NO_PROXY=localhost,127.0.0.1,.localdomain"
#SOCKS5 代理
[Service]
Environment="HTTP_PROXY=socks5://127.0.0.1:7891"
Environment="HTTPS_PROXY=socks5://127.0.0.1:7891"
Environment="NO_PROXY=localhost,127.0.0.1,.localdomain"
重新加载 systemd 并重启 Podman
systemctl daemon-reload
systemctl restart podman