简体   繁体   English

无法使用UDP从我的VirtualBox debian linux VM发送或接收数据包

[英]Cannot send or receive packets from my VirtualBox debian linux VM using UDP

For the sake of simplicity, I will refer you to http://en.wikipedia.org/wiki/Berkeley_sockets and the UDP server and client source code there. 为了简单起见,我将带您参考http://en.wikipedia.org/wiki/Berkeley_sockets以及那里的UDP服务器和客户端源代码。

I am trying to send a packet using UDP protocol to a linux VirtualMachine server program. 我正在尝试使用UDP协议向Linux VirtualMachine服务器程序发送数据包。 Both my host and VM ping well; 我的主机和虚拟机都ping通; all packets sent are received in both directions. 所有发送的数据包都在两个方向上接收。 However my server program is either not receiving any packets, or it is simply not printing. 但是,我的服务器程序没有收到任何数据包,或者根本就没有打印。 Either way, it isn't printing the confirmation or contents of any packets I send to it from the host. 无论哪种方式,它都不会打印我从主机发送给它的任何数据包的确认或内容。

I do not have another PC handy, but both programs communicate well enough if I stage them on the same computer and Wireshark reports that the packets are being sent. 我没有另一台PC,但是如果我将它们放在同一台计算机上并且Wireshark报告正在发送数据包,则这两个程序可以很好地通信。

Mine is a three part question: first, how can I fix this. 我的问题分为三个部分:首先,我该如何解决。 Second, why would the host and VM receive each others ping messages, but not pass these on to the open sockets of both ends of my UDP system? 其次,为什么主机和VM会互相接收ping消息,而不将它们传递给UDP系统两端的开放套接字? Finally, do you have any suggestions about the form or intent of this question? 最后,您对这个问题的形式或意图有什么建议吗?

EDIT: I've tried running my VM with the NAT and bridged adapter network setups. 编辑:我尝试使用NAT和桥接适配器网络设置运行我的VM。 However, I can't conceptualize the relationship between those setups and my problems right now. 但是,我现在无法概念化这些设置和我的问题之间的关系。

With NAT networking, the VM gets a private IP address (usually 192.168.xy) and the host does NAT translation of outgoing packets, and translates reply packets back to the VM. 通过NAT网络,VM会获得一个专用IP地址(通常为192.168.xy),并且主机会对传出数据包进行NAT转换,并将回复数据包转换回VM。 In this mode, all communication must be initiated by the VM -- outside machines can only send packets to the VM in reply to packets the VM sent to them. 在这种模式下,所有通信都必须由VM启动-外部计算机只能向VM发送数据包,以回复VM发送给它们的数据包。 On the network, the packets will look like they're coming from/going to the host on some unrelated port. 在网络上,数据包看起来好像是从某个不相关的端口上来往主机的。

With bridged networking, the VM gets a device that connects directly to the host's network device. 通过桥接网络,VM获得直接连接到主机网络设备的设备。 In this mode, the VM appears as a separate machine on the same network LAN as the host, with its own IP address. 在这种模式下,VM会显示为与主机位于同一网络LAN上的独立计算机,并具有自己的IP地址。 You need to allocate an IP address for it, the same as the host get allocated an IP address (usually via DHCP). 您需要为其分配IP地址,就像为主机分配IP地址一样(通常通过DHCP)。

In either case, to debug what is going on, use tcpdump/wireshark on the host to monitor the host's network device. 无论哪种情况,要调试正在发生的情况,请在主机上使用tcpdump / wireshark监视主机的网络设备。 Send packets from the VM, and you should see them in the trace -- they'll appear to come from the host and a different port in the NAT case, and will appear to come from the VM's IP address (and unchanged ports) in the bridged case. 从VM发送数据包,您应该在跟踪中看到它们-在NAT的情况下,它们似乎来自主机和其他端口,并且看起来来自VM的IP地址(以及未更改的端口)。桥接的情况。

Once you see that, you should be able to send packets back to the VM, though in the NAT case, they must come FROM the address/port the original packet(s) were sent to. 一旦看到,您应该能够将数据包发送回VM,尽管在NAT的情况下,它们必须来自原始数据包发送到的地址/端口。

There are known issues with VirtualBox bridged networking not working properly on wifi devices; 存在VirtualBox桥接网络无法在wifi设备上正常运行的已知问题; in general you can only use bridged networking with wired networks. 通常,您只能将桥接网络与有线网络一起使用。

Oracles VB manual page clear all the terminology used in settings. Oracle VB手册页清除了设置中使用的所有术语。

I've had similar problem, where my VB program didn't receive any packets, which I solved by setting "Bridged Networking" and setting up proper source/destination IP address in my program by analyzing WLAN interface with wireshark and using ifconfig (or ipconfig) in terminal. 我遇到了类似的问题,我的VB程序没有收到任何数据包,我通过设置“桥接网络”并在程序中通过使用Wireshark分析WLAN接口并使用ifconfig(或ipconfig)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM