centos7 设置网络代理

设置代理

这样设置后默认请求都会走代理,比如 curl和wget,但是 yum 和 docker 依旧不会走代理,他们的代理需要单独设置

export http_proxy=http://192.168.2.102:15732
export https_proxy=https://192.168.2.102:15732


#设置:无需代理的IP
export no_proxy="localhost, 127.0.0.1, ::1"

#更新环境文件使之生效
source /etc/profile

yum设置代理

在 /etc/yum.conf后面添加以下内容:
proxy=http://192.168.2.102:15732

更新一下环境文件:
source /etc/yum.conf

docker代理

很多时候即便在 /etc/docker/daemon.json 里面指定 国内的镜像源,还有有些资源访问不到,这时候只要你有任意可以上网的主机,并且走主机的代理上网就可以了请求到资源了

#创建一下目录和文件
mkdir /etc/systemd/system/docker.service.d/ 
vim /etc/systemd/system/docker.service.d/http-proxy.conf

#添加一下内容
[Service]
Environment="HTTP_PROXY=代理地址"
Environment="HTTPS_PROXY=代理地址"
Environment="NO_PROXY=localhost,127.0.0.1"

#重启
systemctl daemon-reload
systemctl restart docker

#检查代理
docker info | grep -i proxy


wget代理设置

这种方式只有wget有效

# vi /etc/wgetrc添加下面两行:
http_proxy=http://192.168.2.102:15732
https_proxy=https://192.168.2.102:15732

#更新一下环境文件:
source /etc/wgetrc

curl设置代理

curl -x https_proxy://代理地址 请求地址

curl -x  https_proxy://192.168.2.102:15732  https://www.google.com.hk/

#这样也可以,省略协议默认是hhttp 协议
curl -x  192.168.2.102:15732  https://www.google.com.hk/

posted on   zhangyukun  阅读(1558)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析

导航

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示