Score:0

How to setup ubuntu VirtualBox VM so it can receive UDP data?

tr flag

On a windows 10 machine with IP address 192.168.200.5 I want to set up a VirtualBox with Ubuntu so Ubuntu can receive UDP data sent from a hardware device (on IP 192.168.200.10) on port 9001.

So far I tried the following:

  • NAT Adapter with port forwarding 9001 -> 9001
  • Bridged Adapter
  • Host-only

I also tried to configure the IP of the Ubuntu VM to be 192.168.200.6 using a file /etc/sysconfig/network-scripts/ifcfg-enp0s3 and restarting the network with sudo systemctl restart systemd-networkd, but this also did not work.

Windows itself DOES receive UDP data on port 9001 as verified using wireshark.

So what else can I try? Or is this impossible to do?

in flag
VirtualBox needs to have the adapter set as Bridged and the connection needs to be in “Promiscuous Mode” to allow all traffic to come in.
tr flag
I just tried that with “Promiscuous Mode” = "Allow All", but neither a ping to 8.8.8.8 nor a ping to 192.168.200.10 does work...
Score:1
ru flag

If the data can reach your port on the host, you don't need to change any IP settings. Normal port forwarding over NAT will do.

Disclaimer: Tested this successfully with VirtualBox 6.1 on an Ubuntu-Host/Ubuntu-VM.

First, configure port forwarding rules for your VM under Settings > Network. Ensure network is enabled and set to Attached to: NAT. Next, under the Advanced drop-down, select Port Forwarding and create a new rule. Select UDP as your protocol and set your desired ports. Leave the IP Address settings blank for now.

port_config


You need to start/restart your VM for these changes to take effect. From your host, ensure that the VirtualBox VM settings is working and listening on your desired port. From a Linux host, you can see open ports with netstat -ln | grep udp. For Windows, use netstat -an | find "UDP".


netstat


Go to your Ubuntu VM to verify you can receive incoming data. Run the netcat utility to listen for incoming UDP data on your desired port with nc -ulk 9001. Once running, go back to your host and use this simple Python script from your host to test if you can send data over to the VM:

import socket

UDP_IP = "0.0.0.0"      # Broadcast over any address
UDP_PORT = 9001         # Send to this port
MESSAGE = "Hello World! Here's a Datagram!\n"

sock = socket.socket(
               socket.AF_INET,     # Internet
               socket.SOCK_DGRAM   # UDP
       )

sock.sendto(bytes(MESSAGE, "utf-8"), (UDP_IP, UDP_PORT))

If everything is fine, the message will be passed from the Host to the VM.

verify_udp_receipt


If you'd like, you can now go change the IP settings in the port forwarding rule to narrow down the source. When left blank as before, it will listen on all addresses for that port, which could be a potential security risk.

Note, however, that if any service on your host is already listening or later starts a service to listen on that same port, it will intercept the data and it will not be passed on to your VM. Ensure that the port is exclusively used to pass messages to your VM.

Hope this helps!

tr flag
Thanks for the help, but it still does not seem to work. I was able to send a message from the windows host to the Ubuntu VM but adjusting the IP address in the python script, but still all the other messages the windows host receives on port 9001 are ignored/not printed out.
ChrisK avatar
ru flag
@Alex please clarify what you mean by "but adjusting the IP address in the python script"? And how do you know for certain that your windows host is actually receiving the data? Is there a listener that informs you, and how?
tr flag
I mentioned in the main post I checked with wireshark
Score:0
vg flag

Step 1: Set your VM to Bridged Adapter

This means your VM will directly see your LAN and talk to your router

enter image description here

Step 2: Assign Static Address to your Guest Ubuntu

I'm assuming that you installed Ubuntu Server. This is important because Ubuntu Server and Ubuntu Desktop configure their Static IP differently (Server uses netplan, Desktop doesn't).

sudo apt install tilde # to install a nice-to-use 
sudo tilde /etc/netplan/00-installer-config.yaml

And use this config:

# Make sure the address is VALID and the router address is correct!
network:
  ethernets:
    enp0s3:
      addresses:
      - 192.168.200.6/24
      nameservers:
        addresses:
        - 8.8.8.8
        - 8.8.4.4
        search: []
      routes:
      - to: default
        via: 192.168.200.1
  version: 2

Use Ctrl+W to save and Ctrl+Q to quit.

Note that enp0s3 is the name of my interface, it may be different in your machine, use the command ip a to list all interfaces while inside your guest VM.

In this configuration I assumed:

  1. You want the Guest VM to be at 192.168.200.6. That's where your HW device should talk to. Note that this is different from your Windows 10's IP address of 192.168.200.5. To everyone in the LAN, it's as if there's a 2nd physical computer present
  2. The router is at 192.168.200.1. If this is wrong, your VM guest won't have access to internet.

Windows Firewall will likely prevent you talking to your Ubuntu VM

By now, your HW device at 192.168.200.10 should be able to talk to your Ubuntu VM.

However your Windows 10 Host may not want to talk to your guest Ubuntu VM. If it already does, then you're done.

Whether Windows allows other computers in the LAN to talk to processes in Windows depends on:

  1. Your connection is set to Home / Work / Public. enter image description here
  2. Firewall rules allow incoming/outgoing UDP packets from/to your guest address (on Home it should work unless some rule is blocking it). enter image description here
    • This should be straightforward: click Add New Rule. It will ask you whether you want to open a port for all programs, or for a specific program, which port(s) and whether to block or allow the connection.

Cheers and good luck.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.