CentOS Stream 9 Repository Issue : All mirrors were tried

I recently downloaded and installed the CentOS Stream 9 from the official CentOS website and got errors when updating the repository. If you are having the same issue, refer to the below;

Actually the error is because of the server couldn’t connect to the mirror URLs mentioned in the repo configuration file. So, we need to change to a different repo. Here is my issue;

=
[root@localhost ~]# dnf update CentOS Stream 9 - BaseOS 0.0 B/s | 0 B 00:57 Errors during downloading metadata for repository 'baseos': - Curl error (7): Couldn't connect to server for http://mirrors.neusoft.edu.cn/centos-stream/9-stream/BaseOS/x86_64/os/repodata/repomd.xml [Failed to connect to mirrors.neusoft.edu.cn port 80: Connection refused] - Curl error (7): Couldn't connect to server for https://mirrors.neusoft.edu.cn/centos-stream/9-stream/BaseOS/x86_64/os/repodata/repomd.xml [Failed to connect to mirrors.neusoft.edu.cn port 443: Connection refused] - Downloading successful, but checksum doesn't match. Calculated: 135f3819271a0cd19525d8d906afc55dc271a86b4b224bfd6cec656415f8497961726bac7159e83937264ff223f59f77d26e5910bcaf9caf22e2930b7ecbe564(sha512) Expected: 9deaa3534643ee3a88147e71117c3c0a25b223b02d6e5b5d574347196b17c2fe926d8b980f703785c71c0e369901c4e055f1461ea6900fa66fd85fece8c17bb8(sha512) Error: Failed to download metadata for repo 'baseos': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried

To resolve this issue, go to the repository configuration file and edit with the following configuration.

=
[root@localhost ~]# vi /etc/yum.repos.d/centos.repo

Better if you could take a backup of the centos.repo original configuration file before proceeding with the changes. If you want to take a backup of your repo, Enter: cp /etc/yum.repos.d/centos.repo /etc/yum.repos.d/centos.repo.bkp

Change the repo file as below;

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

# change to local mirror server
[baseos]
name=CentOS Stream $releasever - BaseOS
#metalink=https://mirrors.centos.org/metalink?repo=centos-baseos-$stream&arch=$basearch&protocol=https,http
baseurl=https://mirror.stream.centos.org/9-stream/BaseOS/x86_64/os
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=1

[appstream]
name=CentOS Stream $releasever - AppStream
#metalink=https://mirrors.centos.org/metalink?repo=centos-appstream-$stream&arch=$basearch&protocol=https,http
baseurl=https://mirror.stream.centos.org/9-stream/AppStream/x86_64/os
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=1

[NFV]
name=Centos Stream $releasever - NFV
baseurl=https://mirror.stream.centos.org/9-stream/NFV/x86_64/os
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

[CRB]
name=Centos Stream $releasever - CRB
baseurl=https://mirror.stream.centos.org/9-stream/CRB/x86_64/os
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=1

[HighAvailability]
name=Centos Stream $releasever - High Availability
baseurl=https://mirror.stream.centos.org/9-stream/HighAvailability/x86_64/os
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=1

[RT]
name=Centos Stream $releasever - RT
baseurl=https://mirror.stream.centos.org/9-stream/RT/x86_64/os
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=1

[ResilientStorage]
name=Centos Stream $releasever - Resilient Storage
baseurl=https://mirror.stream.centos.org/9-stream/ResilientStorage/x86_64/os
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=1

After applying the configuration, we have to get the GPG key from the mirror mentioned in the repo configuration, because we have enabled the GPG check in the config file. To get the GPG key refer to the below steps;

Get the GPG key:

=
[root@localhost ~]# curl -o /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial https://www.centos.org/keys/RPM-GPG-KEY-CentOS-Official-SHA256

Import the GPG key:

=
[root@localhost ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

And verify whether the key has been applied successfully:

=
[root@localhost ~]# rpm -qi gpg-pubkey

Now you can update the packages by entering dnf update. If you are getting any errors after the above steps, just try clearing the cache by using the below commands.

=
[root@localhost ~]# dnf clean all [root@localhost ~]# rm -rf /var/cache/dnf [root@localhost ~]# dnf makecache

Hope you resolve this case. If you have any issues, feel free to comment and will answer as soon as possible. Thank you.

Author photo
Publication date:
Hi! I’m Shanuka, a skilled Network Engineer working for an IT-based company in Sri Lanka. I specialize in designing, implementing, and securing complex networks, with a keen interest in emerging technologies such as cloud computing, automation, and AI-driven system optimization.

One thought on “CentOS Stream 9 Repository Issue : All mirrors were tried

Leave a Reply

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