Linux代理

Linux 全局代理

涉及wget,curl等,docker拉取需要另外配置

操作系统中代理变量的配置:

环境变量 描述 值示例
http_proxy 为http变量设置代理;默认不填开头以http协议传输 http://10.0.0.51:8080 http://user:pass@10.0.0.10:8080 socks4://10.0.0.51:1080 socks5://192.168.1.1:1080
https_proxy 为https变量设置代理; 同上
ftp_proxy 为ftp变量设置代理; 同上
all_proxy 全部变量设置代理,设置了这个时候上面的不用设置 同上
no_proxy 无需代理的主机或域名; 可以使用通配符; 多个时使用“,”号分隔; .aiezu.com,10...,192.168.., *.local,localhost,127.0.0.1

设置方式:

(1) 临时生效(当前shell下)

export proxy="http://127.0.0.1:7897"
export http_proxy=$proxy
export https_proxy=$proxy
export ftp_proxy=$proxy
export no_proxy="localhost, 127.0.0.1, ::1"

(2) 永久生效

# 针对上面变量的设置方法
1、在/etc/profile文件
2、在~/.bashrc
3、在~/.zshrc
4、在/etc/profile.d/文件夹下新建一个文件xxx.sh

# 例如
sudo tee /etc/profile.d/custom_proxy.sh <<'END'
export proxy="http://172.23.106.151:7897"
# export proxy="socks5://192.168.1.1:1080"
export http_proxy=$proxy
export https_proxy=$proxy
export ftp_proxy=$proxy
export no_proxy="localhost,127.0.0.1,172.0.0.0/8,192.168.0.0/8,10.0.0.0/8" 
END

不要用https链接代理!!!!!!!!!!

取消环境变量的设置:

unset http_proxy
unset https_proxy
unset ftp_proxy
unset no_proxy

Ubuntu-apt 代理配置

代理参数命令:

# 使用 Squid cache(简称为Squid)是一个流行的自由软件(GNU通用公共许可证)的代理服务器和Web缓存服务器。
export http_proxy=http://192.168.1.2:3128
export https_proxy=http://192.168.1.2:3128
sudo apt -o Acquire::http::proxy="http://192.168.1.2:3128/" update

CentOS-yum 代理配置

yum代理配置文件变量配置:

# 单独设置yum代理访问,如下文件的变量
echo "proxy=http://127.0.0.1:8080/" >> /etc/yum.conf