Error - Could not resolve host: mirrors.rockylinux.org
It happens at times when you are connected over some VPN or having network issues and are unable to use DNF package manager to install or update system packages. In such cases you can get errors such as
Errors during downloading metadata for repository 'baseos':
- Curl error (6): Couldn't resolve host name for https://mirrors.rockylinux.org/mirrorlist?arch=x86_64&repo=BaseOS-9 [Could not resolve host: mirrors.rockylinux.org]
Error: Failed to download metadata for repo 'baseos': Cannot prepare internal mirrorlist: Curl error (6): Couldn't resolve host name for https://mirrors.rockylinux.org/mirrorlist?arch=x86_64&repo=BaseOS-9 [Could not resolve host: mirrors.rockylinux.org]
Errors during downloading metadata for repository 'baseos':
- Curl error (28): Timeout was reached for https://mirrors.rockylinux.org/mirrorlist?arch=x86_64&repo=BaseOS-9 [Failed to connect to mirrors.rockylinux.org port 443: Connection timed out]
Error: Failed to download metadata for repo 'baseos': Cannot prepare internal mirrorlist: Curl error (28): Timeout was reached for https://mirrors.rockylinux.org/mirrorlist?arch=x86_64&repo=BaseOS-9 [Failed to connect to mirrors.rockylinux.org port 443: Connection timed out]
The solution for these errors can vary based on your environment, I will try to provide all possible solutions to overcome these errors
Solution-1: Check your internet connectivity
It is possible that your Linux box is not connected to internet or having connectivity issues. So you can try to ping the mirror URL and check the response:
[root@server ~]# ping -c2 mirrors.rockylinux.org
PING rockylinux.map.fastly.net (151.101.14.132) 56(84) bytes of data.
64 bytes from 151.101.14.132 (151.101.14.132): icmp_seq=1 ttl=52 time=227 ms
64 bytes from 151.101.14.132 (151.101.14.132): icmp_seq=2 ttl=52 time=334 ms
--- rockylinux.map.fastly.net ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 227.358/280.763/334.168/53.405 ms
If you are getting positive response means your connectivity is proper. In most cases you will get 100% packet loss due to which dnf was not working.
To fix this, check your nameserver inside /etc/resolv.conf
~]# cat /etc/resolv.conf # Generated by NetworkManager search example.com nameserver 172.20.10.1
If your nameserver is not working then try using Google DNS nameserver i.e. 8.8.8.8 and re-try the ping command followed by dnf command to install your package.
Solution-2: Create offline repository using DVD (Temporary)
If you are unable to solve your network connectivity issues then as a work around you can create offline repository using the official Rocky Linux DVD. In my case I have mounted the DVD on my server which can be seen using lsblk
command:
Here our DVD is accessible at /dev/sr0
so we will mount this on any mount point:
[root@server ~]# mount /dev/sr0 /mnt
mount: /mnt: WARNING: source write-protected, mounted read-only.
Next we need to remove existing repo files as they will cause issues when using this offline repository. Normally I take backup of all the default repo files so that I can use them once I am connected back to the internet.
[root@server ~]# mkdir /root/repo [root@server ~]# mv /etc/yum.repos.d/* /root/repo/
Create a new repo file:
[root@server ~]# cat /etc/yum.repos.d/custom.repo
[BaseOS]
name=BaseOS Source
baseurl=file:///mnt/BaseOS
enabled=1
gpgcheck=0
[AppStream]
name=AppStream Source
baseurl=file:///mnt/AppStream
enabled=1
gpgcheck=0
Here we have provided the path to BaseOS
and AppStream
repository which are available inside the Rocky Linux DVD. Then we have enabled both the repos and disabled the gpgcheck.
Next list the available repos:
So now our offline repository is ready to install packages. Let's try to install a new package:
[root@server ~]# dnf install tree
Last metadata expiration check: 0:37:47 ago on Tue 04 Oct 2022 06:02:43 PM IST.
Dependencies resolved.
========================================================================================
Package Architecture Version Repository Size
========================================================================================
Installing:
tree x86_64 1.8.0-10.el9 BaseOS 55 k
Transaction Summary
========================================================================================
Install 1 Package
Total size: 55 k
Installed size: 113 k
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : tree-1.8.0-10.el9.x86_64 1/1
Running scriptlet: tree-1.8.0-10.el9.x86_64 1/1
Verifying : tree-1.8.0-10.el9.x86_64 1/1
Installed:
tree-1.8.0-10.el9.x86_64
Complete!
So we have successfully installed a new rpm using offline repository.
Solution-3: Create offline repository using DVD (Permanent)
The Solution 2 we provided is a temporary solution as the changes will not be persistent across reboot. You can add your mount point entry in fstab
but I would NOT recommend it because if during boot up stage the DVD is missing then your Linux server will fail to boot. In such case if you want to go for permanent solution then I would recommend you to follow below steps
Create new directory on your Linux server
# mkdir -p /root/repo/{BaseOS,AppStream}
Next copy the content from DVD to these directories
# cp -rvf /mnt/BaseOS/* /root/repo/BaseOS/ # cp -rvf /mnt/AppStream/* /root/repo/AppStream/
Next create repository inside the newly created directories using createrepo
command. It is possible createrepo
tool may not be available on your server and since dnf is not working so you will have to install this rpm manually:
Execute this command to locate createrepo rpm inside your DVD:
[root@server ~]# find /mnt/ -name createrepo_c*.rpm
/mnt/AppStream/Packages/c/createrepo_c-0.17.7-4.el9_0.x86_64.rpm
/mnt/AppStream/Packages/c/createrepo_c-libs-0.17.7-4.el9_0.i686.rpm
/mnt/AppStream/Packages/c/createrepo_c-libs-0.17.7-4.el9_0.x86_64.rpm
Install createrepo_c and createrepo_c-libs rpm as per your Linux architecture. Mine is x86_64 so I will install them accordingly:
[root@server ~]# rpm -ivh /mnt/AppStream/Packages/c/createrepo_c-0.17.7-4.el9_0.x86_64.rpm /mnt/AppStream/Packages/c/createrepo_c-libs-0.17.7-4.el9_0.x86_64.rpm
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:createrepo_c-libs-0.17.7-4.el9_0 ################################# [ 50%]
2:createrepo_c-0.17.7-4.el9_0 ################################# [100%]
Now let's create the repository inside our newly created directories. It is IMPORTANT to be inside those directories while running this command:
[root@server ~]# cd /root/repo/BaseOS/
[root@server BaseOS]# createrepo .
Directory walk started
Directory walk done - 0 packages
Temporary output repo path: ./.repodata/
Preparing sqlite DBs
Pool started (with 5 workers)
Pool finished
Repeat the same for AppStream
directory:
[root@server BaseOS]# cd ../AppStream/
[root@server AppStream]# createrepo .
Directory walk started
Directory walk done - 0 packages
Temporary output repo path: ./.repodata/
Preparing sqlite DBs
Pool started (with 5 workers)
Pool finished
Next let's create our repo files inside /etc/yum.repos.d
:
[root@server ~]# cat /etc/yum.repos.d/custom.repo
[BaseOS]
name=BaseOS Source
baseurl=file:///root/repo/BaseOS
enabled=1
gpgcheck=0
[AppStream]
name=AppStream Source
baseurl=file:///root/repo/AppStream
enabled=1
gpgcheck=0
That's it. Now we have a permanent offline YUM repository which we can use even when there is no network connectivity. Once you are connected back to internet then you can change both the enabled
params to 0
to disable these repos and copy back all the repo files you took the backup earlier to /etc/yum.repos.d
.
Summary
In this tutorial we discussed different ways to overcome [Could not resolve host: mirrors.rockylinux.org]
and [Failed to connect to mirrors.rockylinux.org port 443: Connection timed out]
error in Rocky Linux. These issues are seen most of the time when we have a Rocky Linux in VirtualBox and we are connected to VPN so the network connectivity in VMs does not work so in such case as a temporary solution we can create offline YUM repository to install packages.