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:
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.
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,
NAME = "Blue LAN" TYPE = FIXED # We have to bind this network to ''virbr1'' for Internet Access BRIDGE = vbr1 LEASES = [IP=220.127.116.11] LEASES = [IP=18.104.22.168, MAC=50:20:20:20:20:21] LEASES = [IP=22.214.171.124] LEASES = [IP=126.96.36.199] # Custom Attributes to be used in Context GATEWAY = 188.8.131.52 DNS = 184.108.40.206 LOAD_BALANCER = 220.127.116.11
And red.net file:
NAME = "Red LAN" TYPE = RANGED # Now we'll use the host private network (physical) BRIDGE = vbr0 NETWORK_SIZE = C NETWORK_ADDRESS = 192.168.0.0 # Custom Attributes to be used in Context GATEWAY = 192.168.0.1 DNS = 192.168.0.1 LOAD_BALANCER = 192.168.0.3
Once the files have been created, we can create the VNets executing:
$ onevnet create blue.net ID: 0 $ onevnet create red.net ID: 1
onevnet can be used to query OpenNebula about available VNets:
$ onevnet list ID USER GROUP NAME CLUSTER TYPE BRIDGE LEASES 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
onevnet command help or the reference guide for more options to list the virtual networks.
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 18.104.22.168 $ onevnet addleases 0 22.214.171.124 50:20:20:20:20:31 $ $ onevnet addleases 0 126.96.36.199 [VirtualNetworkAddLeases] Error modifiying network leases. Error inserting lease, IP 188.8.131.52 already exists
To remove existing leases from the network, they must be free (i.e., not used by any VM).
$ onevnet rmleases 0 184.108.40.206
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" 220.127.116.11 $ onevnet hold 0 18.104.22.168
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:
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:
dns = "$NETWORK[DNS, NETWORK_ID=3]"
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 ... PERMISSIONS OWNER : um- GROUP : --- OTHER : --- $ onevnet chmod 0 640 $ onevnet show 0 ... PERMISSIONS 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 ... PERMISSIONS OWNER : um- GROUP : um- OTHER : u--
A lease from a virtual network can be obtained by simply specifying the virtual network name in the
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:
You can also request a specific address just by adding the
IP attributes to
NIC = [ NETWORK_ID = 1, IP = 192.168.0.3 ]
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 : - PERMISSIONS OWNER : um- GROUP : --- OTHER : --- VIRTUAL MACHINE MONITORING NET_TX : 0 NET_RX : 0 USED MEMORY : 0 USED CPU : 0 VIRTUAL MACHINE TEMPLATE NAME=server NIC=[ BRIDGE=vbr1, IP=22.214.171.124, MAC=50:20:20:20:20:21, NETWORK="Blue LAN", NETWORK_ID=0, VLAN=NO ] NIC=[ BRIDGE=vbr0, IP=192.168.0.2, MAC=00:03:c0:a8:00:02, NETWORK="Red LAN", NETWORK_ID=1, VLAN=NO ] VMID=0
Now we can query OpenNebula with
onevnet show to find out about given leases and other VNet information:
$ onevnet list ID USER GROUP NAME CLUSTER TYPE BRIDGE LEASES 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 PERMISSIONS OWNER : um- GROUP : --- OTHER : --- VIRTUAL NETWORK TEMPLATE DNS=192.168.0.1 GATEWAY=192.168.0.1 LOAD_BALANCER=192.168.0.3 NETWORK_MASK=255.255.255.0 RANGE IP_START : 192.168.0.1 IP_END : 192.168.0.254 LEASES ON HOLD LEASE=[ IP=192.168.0.1, MAC=00:03:c0:a8:00:01, USED=1, VID=-1 ] LEASE=[ IP=192.168.0.3, MAC=00:03:c0:a8:00:03, USED=1, VID=-1 ] USED LEASES LEASE=[ IP=192.168.0.2, MAC=00:03:c0:a8:00:02, USED=1, VID=0 ]
IP 192.168.0.2 is in use by Virtual Machine 0
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.
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.