VirtualBox提供程序在仅主机网络上E_ACCESSDENIED失败



VirtualBox更新vagrant up失败后,在Ubuntu上出现以下错误:

There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.
Command: ["hostonlyif", "ipconfig", "vboxnet2", "--ip", "10.160.0.1", "--netmask", "255.255.255.0"]
Stderr: VBoxManage: error: Code E_ACCESSDENIED (0x80070005) - Access denied (extended info not available)
VBoxManage: error: Context: "EnableStaticIPConfig(Bstr(pszIp).raw(), Bstr(pszNetmask).raw())" at line 242 of file VBoxManageHostonly.cpp

使用版本:

  • 的流浪汉2.2.14
  • virtualbox - 6.1 6.1.28-147628 ~ Ubuntu ~集团
  • Ubuntu 20.04.3 LTS

从VirtualBox 6.1.28开始,默认情况下,仅主机网络适配器的ip地址限制在192.168.56.0/21范围内(192.168.56.1 ->192.168.63.254)。

你可以通过配置/etc/vbox/networks.conf告诉VirtualBox允许额外的IP范围。例如,要允许10.x.x. xml文件中的任何内容。您可以使用:

* 10.0.0.0/8

有关更多信息,请参阅https://www.virtualbox.org/manual/ch06.html#network_hostonly

文档

浏览完VirtualBox在纯主机网络上的文档后,您将看到Solaris、Linux和MacOS的纯主机网络允许的ip范围发生了变化。VirtualBox现在只接受在192.168.56.0/21范围内分配的IP地址。上面的错误显示Docker正在尝试创建和分配192.168.99.1/24地址和掩码。

现在有两个明显的解决方案,一个是改变docker创建您的机器的方式,使其适合VirtualBox现在使用的"新"地址空间:

docker-machine create --driver virtualbox --virtualbox-memory "2048" --virtualbox-hostonly-cidr 192.168.56.1/21 default

我们也可以在问题的另一边解决这个问题,那就是改变VirtualBox的行为。为了做到这一点,我们需要在/etc/vbox中创建文件networks.conf:

sudo mkdir /etc/vbox
sudo nano /etc/vbox/networks.conf

在networks.conf中我们可以告诉VirtualBox我们允许的网络:

* 10.0.0.0/8 192.168.0.0/16

* 2001: 64:/

我设法通过降级到VirtualBox 6.1.26来解决这个错误:

# check the available versions
apt-cache showpkg virtualbox
# stop VirtualBox machines
# downgrade VirtualBox version
sudo apt-get install virtualbox=6.1.26-dfsg-3~ubuntu1.20.04.2

上面的最后一个命令不会删除虚拟机的数据。

我需要我的Vagrantfile在多台机器(Ubuntu和Mac)上开箱工作,所以修改/etc/vbox/networks.conf对我不起作用。

相反,我将所有的Vagranfile IP地址更改为192.168.56.0/21,正如Paul Parker所描述的和对重复问题的回答。

根据ChrisR的回答和VirtualBox文档,我首先尝试了192.68.56.0/21,它在Linux上工作。但是Mac上的VirtualBox只接受另一个范围(用168代替68)。

相关内容