Difference between revisions of "Configuring a New Ubuntu 11.04 KVM Virtual Network"
(New page: When KVM virtualization is installed on an Ubuntu 11.04 system, a single virtual network is created by default. The goal of this chapter is to provide an overview of virtual networks in th...) |
(No difference)
|
Revision as of 17:51, 23 June 2011
When KVM virtualization is installed on an Ubuntu 11.04 system, a single virtual network is created by default. The goal of this chapter is to provide an overview of virtual networks in the context of KVM, and to explain the steps involved in adding additional virtual networks to the host environment.
Ubuntu 11.04 KVM Guest Networking Options
KVM based virtual machines running on an Ubuntu 11.04 host are provided two choices in terms of network connectivity. One option is to use a network bridge allowing the guest operating system to share one of the host system’s network connections. This connection option is also referred to as a shared physical device since both the host operating system and guest OS are utilizing a physical network adaptor to gain network access. Details on the creation of network bridges were provided in the chapter entitled Creating an Ubuntu 11.04 KVM Networked Bridge Interface.
In this shared physical device scenario, the guest operating system appears on the external network in the same way as any other systems directly connected to the network. It will need, for example, an IP address within the address space of the external network, or will be assigned an IP address from a DHCP server in the same way as all other systems on the network.
The second option involves connecting the virtual machine to a virtual network. A virtual network is essentially a software based network that runs within the host Ubuntu operating system. The virtual network has its own range of IP addresses and operates a DHCP server to assign IP addresses to connected virtual machines. Connection to the external network, if enabled, is typically provided using Network Address Translation (NAT), whereby the guest OS connects using the IP address of the host system. By default a single virtual network is created when KVM is installed on an Ubuntu 11.04 system. It is named default and uses a virtual networking device called virbr0.
Identifying the Settings of an Existing Ubuntu 11.04 KVM Virtual Network
The best way to identify the settings of a KVM virtual network is to use the virt-manager tool. This tool may be launched pressing Alt-F2 and entering virt-manager in the Run a command text box. Once loaded, select the Edit -> Connection Details menu option and on the resulting dialog, select the Virtual Networks tab as illustrated in the following figure:
As we can see from the information provided by virt-manager, the only virtual network currently available is named default. It uses the virtual device named virbr0, has an IP address space defined by 192.168.122.0 with a subnet mask of 24. The DHCP server is configured to allocate IP addresses between 192.168.122.2 and 192.168.122.254. Forwarding to the external network is handled using NAT. The virtual network is currently active and is configured to start on system boot.
The buttons beneath the list of networks can be used to start, stop or delete the currently selected network. In addition, the button displaying the + sign can be used to create a new virtual network, a topic that will be covered in the next section of this chapter.
Creating a New KVM Virtual Network on an Ubuntu 11.04 Host
To create a new KVM virtual network on an Ubuntu host, click on the + button located beneath the list of virtual networks on the Virtual Networks details screen outlined in the previous section. The Create a new virtual network wizard will appear. After reading the introductory screen, click on the Forward button and enter a name for the new virtual network. For the purposes of this example we will use the name virtualnet1. Having defined the name, click the Forward button to proceed to the address space configuration screen:
Either select the default setting, or specify an alternative if a specific address space is required before proceeding to the next screen where the DHCP address range must be defined:
The wizard will pre-populate start and end address for the DHCP server based on the IP address space specified on the preceding screen. Unless a guest OS is configured with a static IP address, it will be assigned an IP address from the range specified on this screen when it is started up.
On the next screen the network may be configured to be an isolated network or for data to be forwarded to a physical network. In the case of an isolated network, guests connected to this virtual network can see each other but have no connectivity to the external physical network.
If the Forwarding to a physical network option is selected a specific physical network device on the host system may be selected, or the system can be left to select any available networking device. Lastly, the forwarding mode may be configured to use NAT or Routed forwarding:
After the network connectivity options have been defined, the final screen displays a summary of the selections made on the preceding screens. Review the information provided and, assuming the settings match your requirements, click on Finish to create the new virtual network.
On returning to the main Host Details screen, select the new virtual network from the list to view the settings:
The new virtual network should reflect the specified configuration options. In addition we can see that it has been assigned virtual device virbr1, is already active and is configured to start when the host system boots.
Assigning the New Virtual Bridge during Virtual Machine Creation
During the virtual machine creation process the creation wizard will display a network configuration screen. In order to connect the virtual machine to the newly created virtual network, simply ensure that it is selected from the drop down menu. The following figure shows the Advanced options section of the final configuration screen set up to use the virtualnet1 network created in the preceding section:
Changing an Existing Virtual Machine to Use a new Virtual Network
An existing virtual machine may also be configured to use a new virtual network. To make this configuration change, select the virtual machine from the main screen of the virt-manager tool and click on the Open button located in the toolbar. When the virtual machine window appears, click on the blue information button to display the current configuration. In the list of hardware categories click on the NIC entry.
In order to configure the virtual machine to use the new virtual network it is necessary to first delete this NIC from the configuration by clicking on the Remove button located in the bottom right hand corner of the dialog. Once the old NIC has been deleted, click on the Add Hardware button to display the Add new virtual hardware wizard, select Network from the hardware type menu and click the Forward button. On the resulting network configuration screen, select the new virtual network from the Host device menu.
Click the Forward button, review the summary information and click Finish to commit the changes. When the virtual machine is next powered up it will be connected to the new virtual network.