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
  • 某些应用可能需要单独的代理配置。
  • 更改系统级代理可能会影响系统的各个方面,请谨慎操作。
  • 重启系统可能是必要的,以确保所有更改生效。
相关推荐
yaoxin52112310 分钟前
第十二章 I 开头的术语
运维·服务器
ProgramHan12 分钟前
1992-2025年中国计算机发展状况:服务器、电脑端与移动端的演进
运维·服务器·电脑
马立杰3 小时前
H3CNE-33-BGP
运维·网络·h3cne
云空4 小时前
《DeepSeek 网页/API 性能异常(DeepSeek Web/API Degraded Performance):网络安全日志》
运维·人工智能·web安全·网络安全·开源·网络攻击模型·安全威胁分析
深度Linux4 小时前
Linux网络编程中的零拷贝:提升性能的秘密武器
linux·linux内核·零拷贝技术
没有名字的小羊5 小时前
Cyber Security 101-Build Your Cyber Security Career-Security Principles(安全原则)
运维·网络·安全
千夜啊5 小时前
Nginx 运维开发高频面试题详解
运维·nginx·运维开发
存储服务专家StorageExpert6 小时前
答疑解惑:如何监控EMC unity存储系统磁盘重构rebuild进度
运维·unity·存储维护·emc存储
太阳伞下的阿呆7 小时前
排查定位jar包大文件
java·centos·jar
chian-ocean8 小时前
从理论到实践:Linux 进程替换与 exec 系列函数
linux·运维·服务器