从 Windows PC 向 VMware 计算机发送 UDP 消息时要使用的网络连接?

Network connection to use when sending UDP messages from Windows PC to VMware machine?

我在做一点套接字编程,遇到了一个我不明白的网络行为;我希望有人能阐明正在发生的事情。

我在 PC 上 运行ning Windows 7 Professional。我已经安装了 VMware 并将 运行ning QNX Neutrino RTOS 作为 VMware 会话中的目标。所以 Windows PC 是主机 PC,来宾 OS 是 QNX Neutrino RTOS。我将虚拟机配置为使用 NAT 网络连接。

好的,现在开始 IP 和接口配置。 运行 'ipconfig' 在我的 Windows 机器上给出以下内容:

Windows IP Configuration

Ethernet adapter Local Area Connection:

  Connection-specific DNS Suffix  . :
  IPv4 Address. . . . . . . . . . . : 192.168.1.100
  Subnet Mask . . . . . . . . . . . : 255.255.255.0
  Default Gateway . . . . . . . . . : 192.168.1.1

Ethernet adapter VMware Network Adapter VMnet1:

  Connection-specific DNS Suffix  . :
  Link-local IPv6 Address . . . . . : fe80::c558:ae9f:e58e:e005%24
  IPv4 Address. . . . . . . . . . . : 192.168.184.1
  Subnet Mask . . . . . . . . . . . : 255.255.255.0
  Default Gateway . . . . . . . . . :

Ethernet adapter VMware Network Adapter VMnet8:

  Connection-specific DNS Suffix  . :
  Link-local IPv6 Address . . . . . : fe80::fce2:d22f:9ec:bd005%25
  IPv4 Address. . . . . . . . . . . : 192.168.248.1
  Subnet Mask . . . . . . . . . . . : 255.255.255.0
  Default Gateway . . . . . . . . . :

(** Other entries omitted for brevity **)

当我在 VMware QNX 系统上 运行 'ifconfig' 时,我得到以下信息:

lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33192
        inet 127.0.0.1 netmask 0xff000000
ni0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        capabilities rx=7<IP4CSUM,TCP4CSUM,UDP4CSUM>
        capabilities tx=3f<IP4CSUM,TCP4CSUM,UDP4CSUM,TCP6CSUM,UDP6CSUM,TSO4>
        enabled=0
        address: 00:0c:29:04:00:ae
        media: Ethernet autoselect (1000baseT full-duplex)
        status: active
        inet 192.168.184.15 netmask 0xffffff00 broadcast 192.168.184.255
ni1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        capabilities rx=7<IP4CSUM,TCP4CSUM,UDP4CSUM>
        capabilities tx=3f<IP4CSUM,TCP4CSUM,UDP4CSUM,TCP6CSUM,UDP6CSUM,TSO4>
        enabled=0
        address: 00:0c:29:04:00:b8
        media: Ethernet autoselect (1000baseT full-duplex)
        status: active
        inet 192.168.248.15 netmask 0xffffff00 broadcast 192.168.248.255

到目前为止,还不错。现在,我在 VMware 机器上的套接字程序 运行ning 可以成功地从 VMware IP 地址 192.168.184.15(端口 65527)向 Windows PC 192.168.1.100(端口 2023)发送 UDP 消息,并且我的Windows 套接字程序收到消息。但是,当我尝试从 IP 地址为 192.168.1.100(端口 2044)的 Windows 机器向地址为 192.168.248.15(端口 2045)的 VMware 机器发送 UDP 消息时,不知何故消息没有到达目的地.我确实使用 Wireshark 验证了 UDP 消息在具有预期 IP 源地址和 IP 目标地址的线路上,但即便如此,VMware 机器上的套接字程序 运行ning 只是没有收到 UDP 消息。

不过,我能做的是从 IP 地址为 192.168.248.1 的 Windows 机器向 192.168.248.15 发送一条 UDP 消息。当我这样做时,VMware 机器上的套接字程序 运行ning 收到 UDP 消息。但是我想知道的是,为什么我不能从192.168.1.100向192.168.248.15发送消息成功?除了 NAT,我是否需要使用其他类型的网络连接?

NAT 是您能够从您的 VMWare 机器发送和接收而不是反向的原因。

原因是在发送时,NAT 会构建一个包含原始 IP 地址和端口的转换 table,然后使用不同的 IP 地址和端口。收到答复时,将查询此 table 并将答复委托回原始 IP 地址和端口。

如果收到的消息在翻译中没有条目 table,则该消息将被丢弃。这就是为什么你不能发送消息说你的邻居在那些也使用 NATPAT 的典型家用路由器后面的原因。

您可以通过使用隔离区或端口转发来解决这个问题。但是我不知道如何在 vm 中做到这一点。