VirtualBox 网络适配器/DNS 与 Wi-Fi 的问题

VirtualBox 网络适配器/DNS 与 Wi-Fi 的问题

我在使用 VirtualBox 时遇到了一个非常奇怪的问题。

大多数情况下,我的笔记本电脑都硬连线到以太网连接。偶尔,当我离开办公桌时,除了 Wi-Fi 之外我别无选择。连接到 Wi-Fi 时,我的主机(Windows 10)几秒钟内即可获得网络访问权限,没有任何问题。但是,客户机(Windows XP SP3)将表现得好像它仍处于离线状态。

我在 VirtualBox 中的网络配置是NAT

奇怪的是,这种情况只发生在无线情况下。每当我硬连线计算机时,主机操作系统绝不任何获取网络连接时出现问题。我将其设置为 NAT,因为我需要客户操作系统能够访问互联网,但我不希望主机之外的客户端连接到它。我也不想将客户计算机绑定到有线网卡或无线网卡,因为这样它只能在其中一个上运行。

另一方面,每当我连接 Wi-Fi 时,总是访客连接互联网时出现问题。

有一次我遇到了问题,我输入了内容,ipconfig /flushdns突然一切就都正常了。从那以后,这还不够。刷新我的 DNS 不足以让 Wi-Fi 上的一切都正常工作。

我发现强制它工作的唯一方法是进入我的 VirtualBox 客户机设置并将网络适配器从 更改NATBridged。此时,它仍然无法工作。但是,现在如果我输入ipconfig /flushdns(在客户机上),一切都会突然正常工作:我有网络访问权限。更奇怪的是,我现在可以将其改回NAT。突然,它会停止工作,但如果我这样做ipconfig /flushdns 再次,它就会起作用。

换句话说,我又回到了原点,NAT终于回到了正常工作的状态。开始和结束状态是完全一样,所以我很困惑为什么客户机无法自行获得网络连接。如果我只需要在连接到 Wi-Fi 时键入,那将是一回事,但必须退出客户机并将适配器从更改为然后再更改回,然后键入命令,ipconfig /flushdns这真的很麻烦。NATBridgedNAT

为什么会发生这种情况?更重要的是,我该如何解决这个问题,以便它能像硬连线时一样无缝地工作?(ipconfig /flushdns例如,从 Wi-Fi 切换回以太网时,我从来不需要输入任何内容,也不需要调整任何适配器设置)。

以下是最近一次故障排除会话的命令提示符输出:

刚连接Wi-Fi,无网络访问:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\InterLinked>ping google.com
Ping request could not find host google.com. Please check the name and try again
.

C:\Documents and Settings\InterLinked>ping google.com
^C
C:\Documents and Settings\InterLinked>ipconfig /flushdns

Windows IP Configuration

Successfully flushed the DNS Resolver Cache.

C:\Documents and Settings\InterLinked>ping google.com
Ping request could not find host google.com. Please check the name and try again
.

更改NATBridged并重试:

C:\Documents and Settings\InterLinked>

C:\Documents and Settings\InterLinked>ping google.com

我提前终止了它,因此缺少输出,但是 ping 失败,直到我刷新 DNS:

^C
C:\Documents and Settings\InterLinked>ipconfig /flushdns

Windows IP Configuration

Successfully flushed the DNS Resolver Cache.

C:\Documents and Settings\InterLinked>ping google.com

Pinging google.com [172.217.7.14] with 32 bytes of data:

Reply from 172.217.7.14: bytes=32 time=15ms TTL=48
Reply from 172.217.7.14: bytes=32 time=13ms TTL=48
Reply from 172.217.7.14: bytes=32 time=15ms TTL=48
Reply from 172.217.7.14: bytes=32 time=20ms TTL=48

Ping statistics for 172.217.7.14:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 13ms, Maximum = 20ms, Average = 15ms

C:\Documents and Settings\InterLinked>

我改BridgedNAT

C:\Documents and Settings\InterLinked>ping google.com

Pinging google.com [172.217.7.14] with 32 bytes of data:

Reply from 172.217.7.14: bytes=32 time=15ms TTL=47
Destination host unreachable.
Destination host unreachable.
Destination host unreachable.

Ping statistics for 172.217.7.14:
    Packets: Sent = 4, Received = 1, Lost = 3 (75% loss),
Approximate round trip times in milli-seconds:
    Minimum = 15ms, Maximum = 15ms, Average = 15ms

C:\Documents and Settings\InterLinked>ipconfig /flushdns

Windows IP Configuration

Successfully flushed the DNS Resolver Cache.

C:\Documents and Settings\InterLinked>ping google.com

Pinging google.com [172.217.7.14] with 32 bytes of data:

Reply from 172.217.7.14: bytes=32 time=12ms TTL=47
Reply from 172.217.7.14: bytes=32 time=6ms TTL=47
Reply from 172.217.7.14: bytes=32 time=188ms TTL=47
Reply from 172.217.7.14: bytes=32 time=14ms TTL=47

Ping statistics for 172.217.7.14:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 6ms, Maximum = 188ms, Average = 55ms

C:\Documents and Settings\InterLinked>

答案1

正如暗示的那样,启用 VirtualBox DNS 解析器是解决方案。

具体步骤如下:

  1. 关闭虚拟机。机器处于开启状态时无法启动 DNS 解析器。
  2. 导航到 VirtualBox 目录主持人从命令提示符:cd C:\Program Files\Oracle\VirtualBox
  3. 运行以下命令:VBoxManage modifyvm "<VM name>" --natdnshostresolver1 on

<VM name>只是虚拟机的名称,VBoxManage list runningvms也可以通过运行找到。

相关内容