Skip to content
Advertisement

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.

I am trying to send a packet using UDP protocol to a linux VirtualMachine server program. Both my host and VM ping well; 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.

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? 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. However, I can’t conceptualize the relationship between those setups and my problems right now.

Advertisement

Answer

With NAT networking, the VM gets a private IP address (usually 192.168.x.y) and the host does NAT translation of outgoing packets, and translates reply packets back to the 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. 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. In this mode, the VM appears as a separate machine on the same network LAN as the host, with its own IP address. You need to allocate an IP address for it, the same as the host get allocated an IP address (usually via DHCP).

In either case, to debug what is going on, use tcpdump/wireshark on the host to monitor the host’s network device. 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.

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.

There are known issues with VirtualBox bridged networking not working properly on wifi devices; in general you can only use bridged networking with wired networks.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement