在Rocky Linux中配置网络代理,可通过环境变量临时设置(如export http_proxy='http://user:pass@proxy_ip:port')或永久写入/etc/profile.d/proxy.sh文件。对于dnf包管理器,需在/etc/dnf/dnf.conf添加proxy=http://proxy_ip:port。
延伸知识点:Systemd服务代理配置
若需要为systemd管理的服务(如docker、cron)配置代理,需创建/etc/systemd/system/service_name.service.d/proxy.conf目录及文件,内容为:
[Service]
Environment="http_proxy=http://proxy_ip:port"
Environment="https_proxy=http://proxy_ip:port"
执行systemctl daemon-reload和systemctl restart service_name生效。此配置优先级高于系统环境变量,且能精准控制特定服务的网络出口。