Letting a VM act as an HTTP server?

Dear ON forums,

I’m a CS student who is very new to OpenNebula and I ran into a problem that seems difficult to me. I downloaded a virtual image of CentOS with OpenNebula 5.2 installed (it’s the sandbox from the official website, this one specifically) and my host is VirtualBox on a Windows 10 machine.

What I’d like to do is create a VM (in ON) that can act as a simple HTTP server and is accessible from the Windows machine. I have successfully setup a Virtual Machine template (using Damn Small Linux, to spare resources) and it works pretty well, however I don’t know how to let VMs connect to the internet. I have tried adding 8.8.8.8 to resolv.conf on the Host machine, but this only allows the host to resolve outside addresses.

Research tells me that I’m somehow supposed to connect the the VMs to my computer through some sort of virtual network set up in OpenNebula, but the possibilities I’ve found were a bit convoluted to me.

How would someone go about configuring such a thing? Can I do this through Sunstone, or do I have to configure interface files?

Thank you in advance

Hello,

the OpenNebula sandbox appliance is mainly for testing purposes, to see how the Sunstone looks like and how to deploy and interact with very simple VM. Also, the VMs started inside the VirtualBox aren’t hardware accelerated (like the sandbox appliance itself), because the VirtualBox doesn’t support nested virtualization. That means the VMs inside are only hardware emulated and very slooooow. For anything serious, you need your own Linux virtualization host.

Traffic routing

The networking inside the sandbox doesn’t allow routing outside, but this can be easily fixed by masquerade (NAT):

  1. you should add the gateway/DNS information into the virtual network metadata
  • click on “Network - Virtual Networks”
  • click on cloud network with ID 0
  • add new attribute at the bottom, name GATEWAY with value 172.16.100.1
  • add new attribute, name DNS with value 8.8.8.8
  1. login the sandbox console and run following to enable NAT
iptables -t nat -A POSTROUTING -o enp0s3 -j MASQUERADE

If network interface inside the VM is configured with IP assigned by the OpenNebula and default route via 172.16.100.1, the external services should be working. You can try by ping 8.8.8.8.

Access sandbox

It’s more tricky to access the VMs from outside the sandbox.

One, simple and not very flexible approach, can be

  1. enable port forwarding between host (W10)/guest(sandbox) in the appliance settings, e.g. for port 8080
  2. inside the sandbox, route the port 8080 on the IP address and selected port of the VM running inside

The another, more flexible approach, would be

  1. in the VirtualBox appliance settings, add another network interface configured as “Host-only Adapter”
  2. in the sandbox console, configure this new interface and create another bridge
  3. in the OpenNebula, create new virtual network on this bridge
  4. add this new network also the VM template

Then, VMs should have 2 network cards. First for general public traffic, second for your direct communication with the VMs.

Hope it helps a little.

Best regards,
Vlastimil Holer

1 Like