Introduction
After following the below instructions, you should be able to deploy VMs that:
- Can be accessed by IP from the Host
- Can communicate with each other
- Can communicate to the external network
- Are not accessible beyond your Host
While these instructions were performed on a Fedora 25 machine, they should work on other supported versions and few other distros with minimal command modifications.
Package Installation and Services
- Make sure your system is up to date and restart if necessary:
sudo dnf update -y ; reboot
- Install the required packages:
sudo dnf install virt-manager qemu-kvm qemu-img libvirt-daemon libvirt-daemon-driver*
- Start the Libvirt Daemon:
sudo systemctl start libvirtd
Configure the Virtual Network
This network will be accessible within your Host environment only and will be service IP Addresses by DHCP to your VMs.
- Open virt-manager by searching for it in the Gnome search bar, by finding it under the KDE applications menu, or by launching it through terminal using
sudo virt-manager
. - Go to Edit – Connection Details.
- Click on the Virtual Networks tab and then click the plus (+) sign at the lower left corner of the window.
- For Network Name, choose something simple, such as “virtnet” and click Forward.
- Verify that Enable IPv4… and Enable DHCPv4 are both checked.
- Network: 192.168.100.0/24 (example)
- Start: 192.168.100.128 (example)
- End: 192.168.100.254 (example)
- Click Forward twice to skip IPv6 DHCP configuration unless you plan on needing it for another reason than deploying more than 4.3 billion VMs.
- Select Forward to physical network and leave other settings default.
- Click Finish.
You should now be able to deploy new VMs without much difficulty.
Deploying a Fedora 25 Server Guest VM (Exercise #1)
With Fedora, it is easy to deploy a VM using HTTP. This will ensure you are always deploying with the latest packages available.
- Within Virtual Machine Manager, go to File – New Virtual Machine, or click on the Create a new virtual machine icon _below_ File.
- Select Network Install and then click Forward.
- For URL, paste in the following link and then click Forward four times:
http://download.fedoraproject.org/pub/fedora/linux/releases/25/Server/x86_64/os/
Manually assigning an IP Address from the Host (Exercise #2)
Libvirt uses dnsmasq to manage the DHCP range of newly deployed VMs. Due to this, you are given some flexibility to have dnsmasq manually assign IP Addresses based off of the VM’s MAC Address.
For this example, I am using the VM I deployed from the first exercise.
- From terminal on the Host, grab the MAC address of the fedora25 VM that was deployed:
sudo virsh dumpxml fedora25 | grep 'mac address'
- Next, use the MAC address shown to give that VM a specific IP Address (192.168.100.21 in this example):
sudo virsh net-update virtnet add ip-dhcp-host "<host mac='######' name='fedora25' ip='192.168.100.#'/>" --live --config
- Finally, bounce the network adapter on the VM itself to grab the new IP. Example:
sudo ifdown eth0 ; sudo ifup eth0
Example:
====== Fedora 25 Host
striker host ~ $ sudo virsh dumpxml fedora25 | grep ‘mac address’
<mac address=’52:54:00:a9:37:f0’/>striker host ~ $ sudo virsh net-update virtnet add ip-dhcp-host “”<host mac=’52:54:00:a9:37:f0′ name=’fedora25′ ip=’192.168.100.21’/>” –live –config
Updated network virtnet persistent config and live state====== Fedora 25 VM
[root@fedora25 ~]# ip a | grep ‘inet 192’
inet 192.168.100.250/24 brd 192.168.100.255 scope global dynamic ens3[root@fedora25 ~]# ifdown ens3
Device ‘ens3’ successfully disconnected.[root@fedora25 ~]# ifup ens3
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/1)[root@fedora25 ~]# ip a | grep ‘inet 192’
inet 192.168.100.21/24 brd 192.168.100.255 scope global dynamic ens3
Adding a new Storage layer to a VM (Exercise #3)
This exercise will walk you through creating a virtual storage drive and attach it to your VM. For the purpose of the exercise, I will be using the Fedora 25 Server VM deployed above.
- Within Virtual Machine Manager, highlight the VM you wish to add a new storage drive to and then click Open.
- Within the VM window, click the Lightbulb icon labeled Show virtual hardware details.
- In the bottom-left corner, click Add Hardware.
- Storage should be selected within the next window. Choose the size you wish the new storage device to be and click Finish.
- Within the VM window, click on the Computer Monitor icon labeled Show the graphical console.
- You may need to restart the VM for the new storage device to show up. Since we are using the Fedora 25 VM deployed above, the device shows up immediately:
[root@fedora25 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vdb 252:16 0 20G 0 disk # <———————–
vda 252:0 0 20G 0 disk
├─vda2 252:2 0 19G 0 part
│ ├─fedora-swap 253:1 0 2G 0 lvm [SWAP]
│ └─fedora-root 253:0 0 15G 0 lvm /
└─vda1 252:1 0 1G 0 part /boot
Stay in touch!
You can stay in touch with libvirt specialists by joining the OFTC IRC network and then joining the #virt channel. Fedora’s IRC channel is #fedora on Freenode‘s IRC network. You can also join the libvirt mailing list discussion by following the below link: