Creating virtual networks in KVM

In earlier posts I installed the KVM hypervisor on an openSUSE Leap system and added a bridged network connection. That will allow virtual machines to use IP addresses on my house network. However, what if I want to use ‘private’ networks for the experiments I wish to run? That is easily done so let’s see how to create networks and address ranges as follows:

'management'
192.168.99.0/24
'site1'
192.168.100.0/24
'site2vlan1'
192.168.101.0/24
'site2vlan2'
192.168.102.0/24

Bring up the ‘details’ pane for the hypervisor and select the ‘Virtual Networks’ tab as follows:

The list of virtual networks, currently empty

Clicking on the small blue cross opens the dialog for adding a new network. Let’s define the ‘management’ LAN as follows:

Setting the name of the management LAN

Next, define the IP address and subnet mask (192.168.99.0/24) and untick the ‘Enable DHCPv4’ option. DHCP will be provided by the virtual Mikrotek router.

Setting the IP address range and disabling DHCP

On the next pane, disable IPv6 for the time being.

Disable IPv6 for this network

Finally, select the option to create an isolated network and keep the DNS Domain Name as shown.

Creating an isolated network called ‘management’

Repeating the process for the other networks produces a network list as follows:

The completed list of virtual networks

As a final check to see that everything is working as expected, bring up a console as the root user and type the following commands:

virsh net-list

virsh net-list
 Name                 State      Autostart     Persistent
----------------------------------------------------------
 management           active     yes           yes
 site1                active     yes           yes
 site2vlan1           active     yes           yes
 site2vlan2           active     yes           yes

ip addr

ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP group default qlen 1000
    link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
3: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.101/24 brd 192.168.1.255 scope global br0
       valid_lft forever preferred_lft forever
    inet6 fd00::1:8ca0:7c31:ae16:2e0e/64 scope global temporary dynamic 
       valid_lft 6233sec preferred_lft 6233sec
    inet6 fd00::1:12bf:48ff:fe88:f355/64 scope global mngtmpaddr dynamic 
       valid_lft 6233sec preferred_lft 6233sec
    inet6 fe80::12bf:48ff:fe88:f355/64 scope link 
       valid_lft forever preferred_lft forever
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:c4:63:38 brd ff:ff:ff:ff:ff:ff
    inet 192.168.99.1/24 brd 192.168.99.255 scope global virbr0
       valid_lft forever preferred_lft forever
5: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:c4:63:38 brd ff:ff:ff:ff:ff:ff
6: virbr1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:53:8a:0c brd ff:ff:ff:ff:ff:ff
    inet 192.168.100.1/24 brd 192.168.100.255 scope global virbr1
       valid_lft forever preferred_lft forever
7: virbr1-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr1 state DOWN group default qlen 1000
    link/ether 52:54:00:53:8a:0c brd ff:ff:ff:ff:ff:ff
8: virbr2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:cf:6f:e2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.101.1/24 brd 192.168.101.255 scope global virbr2
       valid_lft forever preferred_lft forever
9: virbr2-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr2 state DOWN group default qlen 1000
    link/ether 52:54:00:cf:6f:e2 brd ff:ff:ff:ff:ff:ff
10: virbr3: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:26:84:24 brd ff:ff:ff:ff:ff:ff
    inet 192.168.102.1/24 brd 192.168.102.255 scope global virbr3
       valid_lft forever preferred_lft forever
11: virbr3-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr3 state DOWN group default qlen 1000
    link/ether 52:54:00:26:84:24 brd ff:ff:ff:ff:ff:ff

The results show the four virtual networks (virbr0 to virbr3), but they also show that four virtual network adapters (virbr0-nic to virbr3-nic) have been created that connect each of these new networks to the host machine itself.

In another post, the virtual Mikrotek router will be installed and a basic configuration applied to allow it to route between the four virtual networks.

Leave a Reply

Your email address will not be published. Required fields are marked *