Managing Virtual Networks 3.4

A host is connected to one or more networks that are available to the virtual machines through the corresponding bridges. OpenNebula allows the creation of Virtual Networks by mapping them on top of the physical ones


In this guide you'll learn how to define and use virtual networks. For the sake of simplicity the following examples assume that the hosts are attached to two physical networks:

  • A private network, through the virtual bridge vbr0
  • A network with Internet connectivity, through vbr1

This guide uses the CLI command onevnet, but you can also manage your virtual networks using Sunstone. Select the Network tab, and there you will be able to create and manage your virtual networks in a user friendly way.

Adding and Deleting Virtual Networks

To set up a virtual network you just need to know the name of the bridge to bind the virtual machines to, and decide the IP addresses (the leases) that the VNet will contain.

New Virtual Networks are defined in a Virtual Network template file. The onevnet command is used to create a VNet from that template.

As an example, we will create two new VNets, Blue and Red. Lets assume we have two files, and file:

NAME    = "Blue LAN"
# We have to bind this network to ''virbr1'' for Internet Access
BRIDGE  = vbr1
LEASES  = [IP=, MAC=50:20:20:20:20:21]
# Custom Attributes to be used in Context
DNS     =

And file:

NAME    = "Red LAN"
# Now we'll use the host private network (physical)
BRIDGE  = vbr0
# Custom Attributes to be used in Context
DNS     =

Once the files have been created, we can create the VNets executing:

$ onevnet create
ID: 0
$ onevnet create
ID: 1

Also, onevnet can be used to query OpenNebula about available VNets:

$ onevnet list
   0 oneadmin oneadmin Blue LAN        -             F   vbr1       0
   1 oneadmin oneadmin Red LAN         -             R   vbr0       0

In the output above, USER is the owner of the network and LEASES the number of IP-MACs assigned to a VM from this network.

To delete a virtual network just use onevnet delete. For example to delete the previous networks:

$ onevnet delete 2
$ onevnet delete 'Red LAN'

You can also check the IPs leased in a network with the onevnet show command

Check the onevnet command help or the reference guide for more options to list the virtual networks.

Managing Virtual Networks

Adding and Removing Leases

You can add and remove leases to existing FIXED virtual networks (see the template file reference for more info on the network types). To do so, use the onevnet addleases and onevnet rmleases commands.

The new lease can be added specifying its IP and, optionally, its MAC. If the lease already exists, the action will fail.

$ onevnet addleases 0
$ onevnet addleases 0 50:20:20:20:20:31
$ onevnet addleases 0
[VirtualNetworkAddLeases] Error modifiying network leases. Error inserting lease,
IP already exists

To remove existing leases from the network, they must be free (i.e., not used by any VM).

$ onevnet rmleases 0

Hold and Release Leases

Leases can be temporarily be marked “on hold” state. These leases are reserved, they are part of the network, but they will not be assigned to any VM.

To do so, use the 'onevnet hold' and 'onevnet release' commands. You see the the list of leases on hold with the 'onevnet show' command.

$ onevnet hold "Blue LAN"
$ onevnet hold 0

Lease management in Sunstone

If you are using the Sunstone GUI, you can then easily add, remove, hold and release leases from the dialog of extended information of a Virtual Network. You can open this dialog by clicking the desired element on the Virtual Network table, as you can see in this picture:

Update the Virtual Network Template

The TEMPLATE section can hold any arbitrary data. You can use the onevnet update command to open an editor and edit or add new template attributes. These attributes can be later used in the Virtual Machine Contextualization. For example:


Publishing Virtual Networks

The users can share their virtual networks with other users in their group, or with all the users in OpenNebula. See the Managing Permissions documentation for more information.

Let's see a quick example. To share the virtual network 0 with users in the group, the USE right bit for GROUP must be set with the chmod command:

$ onevnet show 0
OWNER          : um-
GROUP          : ---
OTHER          : ---

$ onevnet chmod 0 640

$ onevnet show 0
OWNER          : um-
GROUP          : u--
OTHER          : ---

The following command allows users in the same group USE and MANAGE the virtual network, and the rest of the users USE it:

$ onevnet chmod 0 664

$ onevnet show 0
OWNER          : um-
GROUP          : um-
OTHER          : u--

The commands onevnet publish and onevnet unpublish are still present for compatibility with previous versions. These commands set/unset

Getting a Lease

A lease from a virtual network can be obtained by simply specifying the virtual network name in the NIC attribute.

For example, to define VM with two network interfaces, one connected to Red LAN and other connected to Blue LAN just include in the template:

NIC = [ NETWORK_ID = 0 ]
NIC = [ NETWORK    = "Red LAN" ]

Networks can be referred in a NIC in two different ways, see the Simplified Virtual Machine Definition File documentation for more information:

  • NETWORK_ID, using its ID as returned by the create operation
  • NETWORK, using its name. In this case the name refers to one of the virtual networks owned by the user (names can not be repeated for the same user). If you want to refer to an NETWORK of other user you can specify that with NETWORK_UID (by the uid of the user) or NETWORK_UNAME (by the name of the user).

You can also request a specific address just by adding the IP attributes to NIC:

NIC = [ NETWORK_ID = 1, IP = ]

When the VM is submitted, OpenNebula will look for available IPs in the Blue LAN and Red LAN virtual networks. The leases on hold will be skipped. If successful, the onevm show command should return information about the machine, including network information.

$ onevm show 0
VIRTUAL MACHINE 0 INFORMATION                                                   
ID                  : 0                   
NAME                : server              
USER                : oneadmin            
GROUP               : oneadmin            
STATE               : PENDING             
LCM_STATE           : LCM_INIT            
START TIME          : 12/13 06:59:07      
END TIME            : -                   
DEPLOY ID           : -                   

OWNER          : um-
GROUP          : ---
OTHER          : ---

VIRTUAL MACHINE MONITORING                                                      
NET_TX              : 0                   
NET_RX              : 0                   
USED MEMORY         : 0                   
USED CPU            : 0                   

VIRTUAL MACHINE TEMPLATE                                                        

:!: Note that if OpenNebula is not able to obtain a lease from a network the submission will fail.

Now we can query OpenNebula with onevnet show to find out about given leases and other VNet information:

$ onevnet list
   0 oneadmin oneadmin Blue LAN        -             F   vbr1       3
   1 oneadmin oneadmin Red LAN         -             R   vbr0       3

Note that there are two LEASES on hold, and one LEASE used in each network

$ onevnet show 1
VIRTUAL NETWORK 1 INFORMATION                                                   
ID             : 1                   
NAME           : Red LAN             
USER           : oneadmin            
GROUP          : oneadmin            
TYPE           : RANGED              
BRIDGE         : vbr0                
VLAN           : No                  
PHYSICAL DEVICE:                     
VLAN ID        :                     
USED LEASES    : 3                   

OWNER          : um-
GROUP          : ---
OTHER          : ---

VIRTUAL NETWORK TEMPLATE                                                        

IP_START       :         
IP_END         :       

LEASES ON HOLD                                                                  
LEASE=[ IP=, MAC=00:03:c0:a8:00:01, USED=1, VID=-1 ]
LEASE=[ IP=, MAC=00:03:c0:a8:00:03, USED=1, VID=-1 ]

USED LEASES                                                                     
LEASE=[ IP=, MAC=00:03:c0:a8:00:02, USED=1, VID=0 ]

:!: IP is in use by Virtual Machine 0

Apply Firewall Rules to VMs

You can apply firewall rules on your VMs, to filter TCP and UDP ports, and to define a policy for ICMP connections.

Read more about this feature here.

Using the Leases within the Virtual Machine

Hypervisors can attach a specific MAC address to a virtual network interface, but Virtual Machines need to obtain an IP address. Please visit the contextualization guide to learn how to configure your Virtual Machines to automatically obtain an IP derived from the MAC.