Module 0 - Lab 2 - KVM Virtual Network
Module 0 - Lab 2 - KVM Virtual Network
Requirements
QEMU/KVM
server1 KVM Guest Domain/VM created in Lab 1
A. Virtual Switch
libvirt implements virtual networking using a virtual network switch, which is logically equivalent to a virtual
network. A virtual network switch is a software component that runs on the virtualization host, which guests virtual
machines "plug in" to, and direct their traffic through. The traffic between guests attached to a specific virtual switch
stays within the confines of the associated virtual network. From a guest's operating system point of view, a virtual
network connection is the same as a normal physical network connection [1].
NAT mode (default) - Allows guest OSes outbound connectivity via NAT apart from LAN connectivity.
Routed mode - Routes traffic from the virtual network to the LAN without applying any NAT
Bridged mode - Operates on Layer 2 of the OSI model. When used, all of the guest virtual machines will appear
on the same subnet as the host physical machine.
Isolated mode - Allows virtual machines to communicate with each other only. They are unable to interact
with the physical network.
These virtual networks can be created by defining a network configuration in an xml file and then adding them to
libvirt. Management of this networks are then facilitated by libvirt clients such as virsh. In this lab, you'll see how this
is done with the default NAT-based virtual newtork and a custom routed virtual network. For more examples (eg,
creating an isolated, or using an existing host bridge) see [2].
To list which networks have been defined to the libvirt daemon for use by KVM guests, use the following command:
This shows us the generated UUID, and anything else that may be in effect (ie Spanning Tree Protocol, DHCP, etc).
<network>
<name>default</name>
<uuid>dfd26d2f-98b0-4774-84b7-3848c5f864e1</uuid>
<forward mode='nat'>
<nat>
<port start='1024' end='65535'/>
</nat>
</forward>
<bridge name='virbr0' stp='on' delay='0'/>
<mac address='52:54:00:4a:2f:3d'/>
<ip address='192.168.122.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.122.2' end='192.168.122.254'/>
</dhcp>
</ip>
</network>
This is specially useful if we are to setup a DMZ network or a Virtual Private Hosting [3]. Hence, this is what we'll be
using to implement our DMZ network in our virtual lab.
<network>
<name>dmz</name>
<bridge name="virbr1" />
<forward mode="route" />
<ip address="192.168.200.1" netmask="255.255.255.0" />
</network>
3. Verify if this network was created by checking the network interfaces in your KVM host:
ip address show
You should be able to see a new bridge interface named virbr1 whose IPv4 address is 192.168.200.1.
Another way to verify that the new network definition is added on libvirt is through virsh itself:
Note! Our new network will persist (won't be transient or deleted during reboots) but is not started yet nor set
to automatically start on boot.
b. Login to server1 and display its network interfaces (You can ssh, virsh console or virt-viewer to do this).
ip link show
You should now see two network interfaces in addition to the loopback interface. In my case, the newly added
interface was assigned enp6s0 as its name.
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group
default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT
group default qlen 1000
link/ether 52:54:00:23:ec:43 brd ff:ff:ff:ff:ff:ff
3: enp6s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default
qlen 1000
link/ether 52:54:00:36:01:41 brd ff:ff:ff:ff:ff:ff
# ssh glenn@192.168.122.121
# sudo virt-viewer server1
sudo virsh console server1
Modify the file to look like this one below (Note! The tab spaces are important):
ip address show
3. On your KVM host, open an new terminal, and run the following commands:
4. Take a screenshot of your terminal or your entire Desktop with the terminal shown (see image below for
reference). Save it as "Your Surname - Lab 2.png" (eg, Fabia - Lab 2.png)
5. Attach the screenshot when you turn in this lab assignment in Google Classroom.
References
[1] KVM Virtual Networking Concepts. Retrieved August 21, 2021 from the WWW: https://kb.novaordis.com/index.
php/KVM_Virtual_Networking_Concepts
[2] libvirt.org. Network XML Format. Retrieved August 21, 2021 from the WWW: https://libvirt.org/formatnetwork.ht
ml
[3] Red Hat, Inc. (2020). RHEL 7 Virtualization Deployment and Administration Guide: Examples of Common
Scenarios. Retrieved August 21, 2021 from the WWW: https://access.redhat.com/documentation/en-us/red_hat_ente
rprise_linux/7/html/virtualization_deployment_and_administration_guide/sect-virtual_networking-examples_of_com
mon_scenarios