Hello everyone,
I’m facing an issue with DNS resolution when using Vagrant and VirtualBox to set up a CentOS 7 VM, and I’m also experiencing a similar problem with an Ubuntu VM. The VMs can connect to the internet (I can ping external IP addresses), but they’re unable to resolve domain names, which is causing yum
and apt
commands to fail.
The Setup:
- Host OS: Debian 12
- Vagrant version: 2.4.1
- VirtualBox version: 7.0.20r163906
- Vagrant Box 1:
centos/7
(version 2004.01) - Vagrant Box 2:
ubuntu/bionic64
Problem Description:
-
On the CentOS 7 VM, I can ping external IP addresses (like
8.8.8.8
), but domain names (such asmirrorlist.centos.org
) fail to resolve, causingyum
to throw DNS resolution errors.Error message:
Could not resolve host: mirrorlist.centos.org; Unknown error
-
On the Ubuntu VM, I’m experiencing a similar issue where it cannot access
archive.ubuntu.com
, andapt-get update
fails.
Both issues started after I disabled Secure Boot on my host machine. Before that, everything worked perfectly, but I had to disable Secure Boot to resolve persistent VirtualBox driver problems (VirtualBox wasn’t working properly with Secure Boot enabled). Now, the VMs cannot resolve DNS even though they can still ping external IP addresses.
What I’ve Tried So Far:
- The VMs can ping
8.8.8.8
, so they have internet connectivity, but DNS resolution still fails. - I manually added Google’s DNS (
8.8.8.8
) to/etc/resolv.conf
, but it didn’t solve the issue, and the changes don’t persist after rebooting. - I’ve tried switching between NAT and bridged networking, but the DNS issue persists on both VMs.
- Updated the Vagrant box and VirtualBox Guest Additions to the latest versions.
- Installed the
vagrant-vbguest
plugin to ensure the Guest Additions are up to date.
Full Log Snippet (CentOS 7):
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos/7'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'centos/7' version '2004.01' is up to date...
==> default: Setting the name of the VM: ansible-book_default_1726614023339_36216
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: bridged
==> default: Forwarding ports...
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
[default] No Virtualbox Guest Additions installation found.
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=vag error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
One of the configured repositories failed (Unknown),
and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:
1. Contact the upstream for the repository and get them to fix the problem.
2. Reconfigure the baseurl/etc. for the repository, to point to a working
upstream. This is most often useful if you are using a newer
distribution release than is supported by the repository (and the
packages for the previous distribution release still work).
3. Run the command with the repository temporarily disabled
yum --disablerepo=<repoid> ...
4. Disable the repository permanently, so yum won't use it by default. Yum
will then just ignore the repository until you permanently enable it
again or use --enablerepo for temporary usage:
yum-config-manager --disable <repoid>
or
subscription-manager repos --disable=<repoid>
5. Configure the failing repository to be skipped, if it is unavailable.
Note that yum will try to contact the repo. when it runs most commands,
so will have to try and fail each time (and thus. yum will be be much
slower). If it is a very temporary problem though, this is often a nice
compromise:
yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true
Cannot find a valid baseurl for repo: base/7/x86_64
Skipping unmount of Virtualbox Guest Additions ISO, because it was not mounted.
==> default: Checking for guest additions in VM...
default: No guest additions were detected on the base box for this VM! Guest
default: additions are required for forwarded ports, shared folders, host only
default: networking, and more. If SSH fails on this machine, please install
default: the guest additions and repackage the box to continue.
default:
default: This is not an error message; everything may continue to work properly,
default: in which case you may ignore this message.
Additional Info:
- Networking: I’ve tried both NAT and bridged networks. Internet works (I can ping
8.8.8.8
), but DNS resolution fails. - DNS Configuration: I’ve added Google DNS (
8.8.8.8
) to/etc/resolv.conf
, but it doesn’t persist after reboots. - The DNS issues started after I disabled Secure Boot on my host machine to fix VirtualBox driver issues.
Has anyone experienced this issue or have any suggestions to resolve DNS resolution problems in Vagrant VMs? I suspect it’s somehow related to Secure Boot being disabled, but I’m not sure how that would affect DNS resolution in the VMs.
Thanks in advance for any help!