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
  • 某些应用可能需要单独的代理配置。
  • 更改系统级代理可能会影响系统的各个方面,请谨慎操作。
  • 重启系统可能是必要的,以确保所有更改生效。
相关推荐
Hellc0071 分钟前
Nginx 高级 CC 与 DDoS 防御策略指南
运维·nginx·ddos
聽雨23710 分钟前
02每日简报20250704
linux·科技·金融·生活·社交电子·娱乐·媒体
feilieren17 分钟前
Docker 安装 Elasticsearch 9
运维·elasticsearch·docker·es
Maki Winster1 小时前
Peek-Ubuntu上Gif录制工具-24.04LTS可装
linux·ubuntu·peek
小皮侠1 小时前
nginx的使用
java·运维·服务器·前端·git·nginx·github
Maki Winster2 小时前
在 Ubuntu 下配置 oh-my-posh —— 普通用户 + root 各自使用独立主题(共享可执行)
linux·运维·ubuntu
守望时空332 小时前
Linux下KDE桌面创建自定义右键菜单
linux
l0sgAi2 小时前
vLLM在RTX50系显卡上部署大模型-使用wsl2
linux·人工智能
翻滚吧键盘2 小时前
debian及衍生发行版apt包管理常见操作
运维·debian
kfepiza3 小时前
CentOS-7的"ifupdown"与Debian的"ifupdown"对比 笔记250706
centos