DNS 在命令行上不起作用

voi*_*ter 5 networking windows dns virtualbox vagrant

我最近在我的机器上组合了 Vagrant + VirtualBox 的东西,试图让虚拟化的 Ubuntu 安装工作。但是,我没有运气,所以我只是卸载了所有东西。从那时起,我在主机上使用命令行应用程序时遇到了一些问题。

我在 Windows 7 x64 上。通过 Chrome 浏览器和其他基于 GUI 的工具,DNS 解析和网络连接似乎没问题。但是,当我启动 cmd.exe 时,我注意到各种命令行工具的奇怪行为。

nslookup

执行nslookup导致无法找到基本域名的IP地址。

C:\>nslookup google.com
Server:  UnKnown
Address:  10.3.1.1

*** UnKnown can't find google.com: No response from server
Run Code Online (Sandbox Code Playgroud)

10.3.1.1是我的路由器,它通过 DHCP 将自己作为 DNS 服务器提供给客户端。路由器将 DNS 请求转发到 Google DNS 服务器。正如我所说,DNS 解析在我的浏览器和许多其他应用程序中工作,所以我怀疑我的路由器设置或 DNS 服务器是问题所在。为了使主题简单,我将在此处省略这些细节。

ping 适用于物理 IPv4 地址,但不适用于主机名。

C:\>ping google.com
Ping request could not find host google.com. Please check the name and try again.
Run Code Online (Sandbox Code Playgroud)
C:\>ping 8.8.8.8
Pinging  with 32 bytes of data:
Reply from 8.8.8.8: bytes=32 time=29ms TTL=52
Reply from 8.8.8.8: bytes=32 time=29ms TTL=52
Reply from 8.8.8.8: bytes=32 time=30ms TTL=52
Reply from 8.8.8.8: bytes=32 time=29ms TTL=52

Ping statistics for _`&:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 29ms, Maximum = 30ms, Average = 29ms
Run Code Online (Sandbox Code Playgroud)

网络统计

现在这就是它变得有趣的地方。当我运行netstat命令时,该Local Address字段为空,尽管 IPv6 地址仍然显示。只有 IPv4 没有。这之前工作正常!

C:\>netstat -ano

Active Connections

  Proto  Local Address          Foreign Address        State           PID
  TCP                                                  LISTENING       4
  TCP                                                  LISTENING       544
  TCP                                                  LISTENING       904
  TCP                                                  LISTENING       616
  TCP                                                  LISTENING       4556
  TCP                                                  LISTENING       6756
  TCP                                                  LISTENING       1080
  TCP                                                  LISTENING       4
  TCP                                                  LISTENING       3612
  TCP                                                  LISTENING       3436
  TCP                                                  LISTENING       3436
  TCP                                                  LISTENING       4
  TCP                                                  ESTABLISHED     4
  TCP                                                  ESTABLISHED     5196
  TCP                                                  ESTABLISHED     2944
  TCP                                                  ESTABLISHED     1444
  TCP                                                  ESTABLISHED     3436
  TCP                                                  ESTABLISHED     2944
  TCP                                                  ESTABLISHED     2944
  TCP                                                  ESTABLISHED     2944
  TCP                                                  ESTABLISHED     2944
  TCP                                                  CLOSE_WAIT      3612
  TCP                                                  CLOSE_WAIT      3612
  TCP                                                  CLOSE_WAIT      3612
  TCP                                                  CLOSE_WAIT      3612
  TCP                                                  CLOSE_WAIT      3612
  TCP                                                  CLOSE_WAIT      3612
  TCP                                                  ESTABLISHED     3612
  TCP                                                  ESTABLISHED     2944
  TCP                                                  ESTABLISHED     2944
  TCP                                                  ESTABLISHED     2944
  TCP                                                  ESTABLISHED     2944
  TCP                                                  ESTABLISHED     2944
  TCP                                                  ESTABLISHED     2944
  TCP                                                  ESTABLISHED     2944
  TCP                                                  TIME_WAIT       0
  TCP                                                  ESTABLISHED     2944
  TCP                                                  ESTABLISHED     2944
  TCP                                                  ESTABLISHED     2944
  TCP                                                  ESTABLISHED     2944
  TCP                                                  TIME_WAIT       0
  TCP                                                  ESTABLISHED     2944
  TCP                                                  LISTENING       3320
  TCP                                                  LISTENING       4576
  TCP                                                  LISTENING       5196
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  TIME_WAIT       0
  TCP                                                  ESTABLISHED     4556
  TCP                                                  ESTABLISHED     4556
  TCP                                                  ESTABLISHED     6756
  TCP                                                  ESTABLISHED     6756
  TCP                                                  ESTABLISHED     3612
  TCP                                                  ESTABLISHED     3612
  TCP                                                  ESTABLISHED     3612
  TCP                                                  LISTENING       3612
  TCP                                                  LISTENING       3612
  TCP                                                  ESTABLISHED     3612
  TCP                                                  LISTENING       2960
  TCP                                                  LISTENING       2044
  TCP                                                  LISTENING       1420
  TCP                                                  LISTENING       4
  TCP                                                  LISTENING       4
  TCP    [::]:445               [::]:0                 LISTENING       4
  TCP    [::]:1025              [::]:0                 LISTENING       544
  TCP    [::]:1026              [::]:0                 LISTENING       904
  TCP    [::]:1038              [::]:0                 LISTENING       616
  TCP    [::]:3389              [::]:0                 LISTENING       1080
  TCP    [::]:3587              [::]:0                 LISTENING       5700
  TCP    [::]:5357              [::]:0                 LISTENING       4
  TCP    [::]:32400             [::]:0                 LISTENING       3436
  TCP    [::]:32401             [::]:0                 LISTENING       3436
  TCP    [::1]:1028             [::]:0                 LISTENING       1768
  UDP                           *:*                                    1000
  UDP                           *:*                                    964
  UDP                           *:*                                    964
  UDP                           *:*                                    1568
  UDP                           *:*                                    1568
  UDP                           *:*                                    1000
  UDP                           *:*                                    1080
  UDP                           *:*                                    3612
  UDP                           *:*                                    3172
  UDP                           *:*                                    3436
  UDP                           *:*                                    3436
  UDP                           *:*                                    3436
  UDP                           *:*                                    3172
  UDP                           *:*                                    2944
  UDP                           *:*                                    3436
  UDP                           *:*                                    1568
  UDP                           *:*                                    2944
  UDP                           *:*                                    2944
  UDP                           *:*                                    964
  UDP                           *:*                                    4
  UDP                           *:*                                    4
  UDP                           *:*                                    1568
  UDP                           *:*                                    3436
  UDP                           *:*                                    3436
  UDP                           *:*                                    3436
  UDP                           *:*                                    3436
  UDP                           *:*                                    3436
  UDP                           *:*                                    1568
  UDP                           *:*                                    1568
  UDP                           *:*                                    2960
  UDP                           *:*                                    3436
  UDP                           *:*                                    3436
  UDP                           *:*                                    3436
  UDP                           *:*                                    3436
  UDP                           *:*                                    1420
  UDP                           *:*                                    1568
  UDP                           *:*                                    4
  UDP                           *:*                                    4
  UDP                           *:*                                    1568
  UDP                           *:*                                    3436
  UDP                           *:*                                    3436
  UDP                           *:*                                    4
  UDP                           *:*                                    4
  UDP                           *:*                                    1568
  UDP                           *:*                                    3436
  UDP                           *:*                                    3436
  UDP    [::]:500               *:*                                    1000
  UDP    [::]:3540              *:*                                    5700
  UDP    [::]:3702              *:*                                    964
  UDP    [::]:3702              *:*                                    1568
  UDP    [::]:3702              *:*                                    964
  UDP    [::]:3702              *:*                                    1568
  UDP    [::]:4500              *:*                                    1000
  UDP    [::]:5355              *:*                                    1080
  UDP    [::]:58964             *:*                                    1568
  UDP    [::]:64135             *:*                                    964
  UDP    [::1]:1900             *:*                                    1568
  UDP    [::1]:64131            *:*                                    1568
  UDP    [fe80::2923:9898:cce9:9b60%18]:1900  *:*                                    1568
  UDP    [fe80::41ba:5355:289f:f5fa%27]:1900  *:*                                    1568
  UDP    [fe80::8c37:8952:a3d5:ca0%20]:1900  *:*                                    1568
  UDP    [fe80::8c37:8952:a3d5:ca0%20]:64130  *:*                                    1568
Run Code Online (Sandbox Code Playgroud)

我已经做了一些事情来试图解决这个问题:

  • 重启
  • 卸载网卡驱动;从主板制造商处重新安装
  • ipconfig /flushdns
  • ipconfig /registerdns
  • 问得好

这些都没有奏效。任何人都知道问题是什么或我可以采取哪些步骤来诊断它?

Vagrant / VirtualBox 详细信息

我想把它放在底部,因为它很长而且可能无关紧要。但是,我想讨论它,因为我认为这是引发此问题的原因。

我运行了一系列 Vagrant 命令来在 Virtual Box 上安装 Ubuntu Trusty 32:

$ vagrant box add ubuntu/trusty64
$ vagrant init ubuntu/trusty64
$ vagrant up
Run Code Online (Sandbox Code Playgroud)

但是,它在来宾操作系统中存在 DNS 解析问题。所以我在我的虚拟机上设置了一些标志来让它工作:

C:\Program Files\Oracle\VirtualBox>VBoxManage.exe modifyvm "Ubuntu Trusty 64" --natdnshostresolver1 on
C:\Program Files\Oracle\VirtualBox>VBoxManage.exe modifyvm "Ubuntu Trusty 64" --natdnsproxy1 on
Run Code Online (Sandbox Code Playgroud)

虽然这确实解决了 Ubuntu 来宾操作系统上的 DNS 解析,但端口转发仍然不起作用。所以因为它不起作用我完全放弃并在删除它安装/设置的虚拟机后卸载了 Vagrant 和 VirtualBox。在此之后,我注意到命令行的东西,甚至命令运行虽然 msys 不再工作。我的主机操作系统中现在存在 DNS 解析问题!

编辑

我将根据以下评论的要求修改我的问题。

适配器 IPv4 下的设置: IPv4 设置

根据ipconfig /all命令,我的系统上所有可用的适配器都在下面(命名的适配器Ethernet adapter Local Area Connection是我连接到 LAN 的真实物理网络适配器)。

另请注意,我将 DNS 服务器分别更改为8.8.8.88.8.4.4。通常我的网关是我的 DNS 服务器 ( 10.3.1.1)。我这样做是为了排除我的路由器和评论中某人的建议的任何问题。

C:\>ipconfig /all

Windows IP Configuration

   Host Name . . . . . . . . . . . . : Robert-PC
   Primary Dns Suffix  . . . . . . . :
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No
   DNS Suffix Search List. . . . . . : home

Ethernet adapter Local Area Connection:

   Connection-specific DNS Suffix  . : home
   Description . . . . . . . . . . . : Qualcomm Atheros AR8151 PCI-E Gigabit Ethernet Controller (NDIS 6.20)
   Physical Address. . . . . . . . . : 90-2B-34-57-0D-24
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::8c37:8952:a3d5:ca0%20(Preferred)
   IPv4 Address. . . . . . . . . . . : 10.3.1.38(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : Monday, May 25, 2015 9:35:57 PM
   Lease Expires . . . . . . . . . . : Tuesday, May 26, 2015 9:36:00 PM
   Default Gateway . . . . . . . . . : 10.3.1.1
   DHCP Server . . . . . . . . . . . : 10.3.1.1
   DNS Servers . . . . . . . . . . . : 8.8.8.8
                                       8.8.4.4
   NetBIOS over Tcpip. . . . . . . . : Enabled

Ethernet adapter Local Area Connection 3:

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Cisco Systems VPN Adapter for 64-bit Windows
   Physical Address. . . . . . . . . : 00-05-9A-3C-78-00
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::2923:9898:cce9:9b60%18(Preferred)
   Autoconfiguration IPv4 Address. . : 169.254.155.96(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.0.0
   Default Gateway . . . . . . . . . :
   DHCPv6 IAID . . . . . . . . . . . : 654312858
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-1A-03-8A-D9-90-2B-34-57-0D-24
   DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
                                       fec0:0:0:ffff::2%1
                                       fec0:0:0:ffff::3%1
   NetBIOS over Tcpip. . . . . . . . : Enabled

Tunnel adapter Local Area Connection* 11:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Teredo Tunneling Pseudo-Interface
   Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes

Tunnel adapter Reusable ISATAP Interface {D85DF6F3-7D47-4198-B7B9-DD5680A8A6E7}:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Microsoft ISATAP Adapter #4
   Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes
Run Code Online (Sandbox Code Playgroud)

将我的 DNS 手动设置为 Google 的 DNS 服务器后,我运行了nslookup(输出如下)。请注意,我仍然无法使用DNS 更改为 Google DNS 服务器nslookupping在 DNS 更改后解析主机名。

C:\>nslookup
Default Server:  UnKnown
Address:  8.8.8.8
Run Code Online (Sandbox Code Playgroud)