Updated: May 11, 2011
After reading my introduction tutorial from last week, you now know that KVM is not a dreadful monster, but a friendly and powerful virtualization software for Linux. It has both GUI and command line management tools, so you can choose whichever suits you best. Today, we'll expand our knowledge a bit. We will talk about network setups, although staying just short of bridged networking, which merits its own article.
We will learn how to add new virtual adapters, configure networks and IP addresses range using DHCP, learn the difference between NAT and Routed modes, toggle networks on and off, and a few more things besides. I'd like to warn you upfront this won't be the most existing tutorial, but it sure is useful.
Network management
Open the Virtual Machine Manager (VMM). Click Edit > Host Details > Virtual Networks tab.
This will open the Network section. By default, you will have one network configured, active and autostarting on boot. The device name will tell you how you can identify the network adapter.
In the IPv4 Configuration section, you will see the network details, including the IP address, subnet mask, the start and end of the DHCP address range, as well as the type of forwarding. We will talk more about these in a moment.
Add network
Say you want to create a separate pool of virtual machines, which are going to run their own services and must be isolated from your other guests. Firewalling will do, but you can also create a new network, with its own range of IP addresses. Let's add a new network.
Click on the green plus icon in the left bottom corner:
P.S. The Action buttons are fairly intuitive, but we will discuss them a little more after we create a new network. Clicking on the green plus will launch the virtual network creation wizard.
You will have to name your new network, select its IP range and configure the DHCP allocation. Fairly trivial so far.
Now comes the interesting part. You need to decide whether this is going to be an isolated network with no outside access or one that can see the external traffic. This is similar to what we did with VirtualBox networking.
Forwarding will allow KVM to send and receive packets to and from external networks. In the Destination dropdown list, you can choose with device you want to forward your virtual network to. For instance, on my HP Pavilion laptop, I have a whole lot of devices. eth0 is the wired adapter, eth1 is the Wireless adapter.
The mode field is more interesting. Without bridged networking configured, you won't be able to lease IP addresses from external DHCP servers, like your router. This means your guests will have only NAT. This is not a bad thing, but if you must have externally facing services running inside virtual machines, you might need to consider bridged networking.
Once you're ready, review the summary and create the new network:
Using new networks
Now, you have an extra adapter, which you can choose in the virtual machine creation wizard. This allows you to separate virtual machines any which way. Furthermore, you can start, stop or delete network adapters, using the Play/Stop buttons.
Well, that would be all. Not really too exciting, but useful. And of course, all of these commands and options are also available from the command line. But that's for another time.
Conclusion
Managing networks in KVM is just as easy as any other virtualization product. If you're not comfortable using the command line, you can achieve desired results via VMM. The GUI lets you add, remove, activate, and deactivate virtual adapters, change their mode and connection, setup the IP addresses and masks and DHCP ranges. Fairly easy, overall.
Bridged networking is far spicier and more interesting than plain NAT, but we will talk about it in a dedicated tutorial. Anyhow, you have now mastered another aspect of KVM, making it that much friendlier and simpler to use. Next, we will talk about Storage, then address the famous VirtualBox conflict, and then get back to bridged networking.
Cheers.