CentOS 7 中设置系统级代理

在 CentOS 7 中设置系统级代理需要几个步骤。以下是设置系统级代理的方法:

  1. 设置环境变量:

编辑 /etc/environment 文件:

bash 复制代码
sudo nano /etc/environment

添加以下行(替换 proxy_server 和 port 为您的实际代理服务器地址和端口):

复制代码
http_proxy="http://proxy_server:port"
https_proxy="http://proxy_server:port"
ftp_proxy="http://proxy_server:port"
no_proxy="localhost,127.0.0.1,::1"
HTTP_PROXY="http://proxy_server:port"
HTTPS_PROXY="http://proxy_server:port"
FTP_PROXY="http://proxy_server:port"
NO_PROXY="localhost,127.0.0.1,::1"
  1. 为 Yum 包管理器设置代理:

编辑 /etc/yum.conf 文件:

bash 复制代码
sudo nano /etc/yum.conf

在文件末尾添加:

复制代码
proxy=http://proxy_server:port
  1. 为 Wget 设置代理:

编辑 /etc/wgetrc 文件:

bash 复制代码
sudo nano /etc/wgetrc

取消注释并修改以下行:

复制代码
http_proxy = http://proxy_server:port
https_proxy = http://proxy_server:port
ftp_proxy = http://proxy_server:port
  1. 为 Shell 设置代理:

编辑 /etc/profile.d/proxy.sh 文件:

bash 复制代码
sudo nano /etc/profile.d/proxy.sh

添加以下内容:

bash 复制代码
export http_proxy="http://proxy_server:port"
export https_proxy="http://proxy_server:port"
export ftp_proxy="http://proxy_server:port"
export no_proxy="localhost,127.0.0.1,::1"
  1. 应用更改:

重新加载环境变量:

bash 复制代码
source /etc/environment
source /etc/profile.d/proxy.sh
  1. 验证设置:
bash 复制代码
echo $http_proxy
echo $https_proxy
  1. 如果使用 systemd 服务,可能需要为它们单独设置代理。编辑服务文件并添加环境变量。

注意事项:

  • 确保替换 proxy_serverport 为您实际的代理服务器地址和端口。
  • 如果代理需要认证,使用格式:http://username:password@proxy_server:port
  • 某些应用可能需要单独的代理配置。
  • 更改系统级代理可能会影响系统的各个方面,请谨慎操作。
  • 重启系统可能是必要的,以确保所有更改生效。
相关推荐
Zach_yuan12 分钟前
深入浅出 JSONCpp
linux·服务器·网络·c++
AtoposのCX33019 分钟前
Docker运行hello-world镜像失败或超时
运维·docker
北京迅为1 小时前
《【北京迅为】itop-3568开发板NPU使用手册》- 第 7章 使用RKNN-Toolkit-lite2
linux·人工智能·嵌入式·npu
Dragon~Snow1 小时前
Linux Centos9 安装 Elasticsearch
linux·elasticsearch·jenkins
熊延1 小时前
麒麟V10系统安装部署elasticsearch
linux·运维·服务器·elasticsearch·搜索引擎·全文检索
Jia ming1 小时前
跟踪器与事件使用举例
linux·事件·跟踪器
生活很暖很治愈2 小时前
Linux——基础IO&软硬链接
linux·ubuntu
2401_858936882 小时前
【Linux C 编程】标准 IO 详解与实战:从基础接口到文件操作实战
linux·c语言
Roc.Chang2 小时前
Ubuntu 下 VLC 无法启动(Segmentation fault)终极解决方案
linux·ubuntu·vlc·媒体播放
松涛和鸣2 小时前
72、IMX6ULL驱动实战:设备树(DTS/DTB)+ GPIO子系统+Platform总线
linux·服务器·arm开发·数据库·单片机