LinuxOpen Source SoftwareSecurityTutorials

How to use HTTP proxy for specific YUM repo

Tutorial for all EL distributions

This tutorial applies to all Enterprise Linux (EL) compatible Linux distributions, which use dnf or yum as package/software installation command.

Depending on your network setup, you might be able to access some (internal) repositories, but not public repositories. Although the YUM configuration (/etc/yum.conf) supports a global HTTP proxy setting, the use of an outgoing http proxy can also be defined for specific repositories.

specific yum repository using a (http) proxy
Specific yum repository using a (http) proxy

Couldn't connect to server

When dnf or yum is unable to connect to a repository server, the typical error message is the following:

[root@el8 ~]# dnf search alloy
Updating Subscription Management repositories.
grafana                                                                                                                           0.0  B/s |   0  B     00:00
Errors during downloading metadata for repository 'grafana':
  - Curl error (7): Couldn't connect to server for https://rpm.grafana.com/repodata/repomd.xml [Failed to connect to rpm.grafana.com port 443: Connection refused]
Error: Failed to download metadata for repo 'grafana': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried

Add proxy option to repo configuration

Let's adjust the configuration for the "grafana" repository, which is in this situation located under /etc/yum.repos.d/grafana.repo:

[root@el8 ~]# cat /etc/yum.repos.d/grafana.repo
[grafana]
name=grafana
baseurl=https://rpm.grafana.com
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://rpm.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt

We can add the "proxy" option which points to the outgoing HTTP proxy in our local network.

[root@el8 ~]# echo "proxy=http://myproxy.example.com:8080" >> /etc/yum.repos.d/grafana.repo

The new line can now be found at the end of the grafana.repo configuration file:

[root@el8 ~]# cat /etc/yum.repos.d/grafana.repo
[grafana]
name=grafana
baseurl=https://rpm.grafana.com
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://rpm.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
proxy=http://myproxy.example.com:8080

Finding and installing packages from the repo via proxy

dnf is now able to connect to the grafana repository using the defined HTTP proxy. All other repositories are still accessed without using a proxy.

[root@el8 ~]# dnf search alloy
Updating Subscription Management repositories.
grafana                                                                  2.3 MB/s | 149 MB     01:05
Last metadata expiration check: 0:01:18 ago on Wed 08 Jan 2025 03:16:12 PM CET.
========================== Name & Summary Matched: alloy ==========================
alloy.x86_64 : Grafana Alloy is an OpenTelemetry Collector distribution with programmable pipelines.
alloy.aarch64 : Grafana Alloy is an OpenTelemetry Collector distribution with programmable pipelines.
alloy.ppc64le : Grafana Alloy is an OpenTelemetry Collector distribution with programmable pipelines.
alloy.s390x : Grafana Alloy is an OpenTelemetry Collector distribution with programmable pipelines.
Claudio Kuenzler
Claudio has been writing way over 1000 articles on his own blog since 2008 already. He is fascinated by technology, especially Open Source Software. As a Senior Systems Engineer he has seen and solved a lot of problems - and writes about them.

You may also like

Leave a reply

Your email address will not be published. Required fields are marked *

More in:Linux