I followed this guide to set network between virtual machines How to use bridged networking with libvirt and KVM.
There are two problems emerged:
- network settings does not persist after system reboot;
- on virtual guest machine the second NIC can't connect to the router, no network connection shown
I created new bridge on the host
sudo ip link add hostbr0 type bridge
sudo ip link show type bridge
# 4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
# link/ether 52:54:00:8a:2e:73 brd ff:ff:ff:ff:ff:ff
# 8: mpqemubr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
# link/ether 52:54:00:87:65:df brd ff:ff:ff:ff:ff:ff
# 9: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default
# link/ether 02:42:e9:8e:81:fc brd ff:ff:ff:ff:ff:ff
# 10: hostbr0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
# link/ether 18:31:bf:cc:08:61 brd ff:ff:ff:ff:ff:ff
I have two network interfaces on the host, both connected to the router with Internet access.
name -v
#44~20.04.2-Ubuntu SMP Tue Oct 26 18:07:44 UTC 2021
ls -l /sys/class/net/ | grep pci
# enp4s0 -> ../../devices/pci0000:00/0000:00:1c.5/0000:04:00.0/net/enp4s0
# enp5s0 -> ../../devices/pci0000:00/0000:00:1c.7/0000:05:00.0/net/enp5s0
DHCP server on my router connected to Internet configuration:
IP Adress Pool: 192.168.0.1--192.168.0.254
Default gateway: 192.168.0.1
host enp4s0: 192.168.0.11
hostbr0 enp5s0: 192.168.0.10
I attached enp5s0
physical device to the bridge:
sudo ip link set enp5s0 up
sudo ip link set enp5s0 master hostbr0
sudo ip address add dev hostbr0 192.168.2.2/24
ip addr show hostbr0
#10: hostbr0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN #group default qlen 1000
# link/ether 18:31:bf:cc:08:61 brd ff:ff:ff:ff:ff:ff
# inet 192.168.2.2/24 scope global hostbr0
# valid_lft forever preferred_lft forever
To make configuration persistent I modified /etc/network/interfaces
. As you can see I have already several configured interfaces and added new one enp5s0
# /etc/network/interfaces
auto lo
iface lo inet loopback
mapping hotplug
script grep
map eth1
iface eth1 inet dhcp
auto eth0
iface eth0 inet static
address 10.152.187.1
netmask 255.255.255.0
auto wlan0
iface wlan0 inet static
address 192.168.1.1
netmask 255.255.255.0
up /sbin/iwconfig wlan0 mode TTTTTT && /sbin/iwconfig wlan0 enc
restricted && /sbin/iwconfig wlan0 key [Y] XXXXXXXX && /sbin/iwconfig
wlan0 essid SSSSSSSS
auto eth1
# Specify that the physical interface that should be connected to the bridge
# should be configured manually, to avoid conflicts with NetworkManager
iface enp5s0 inet manual
# The hostbr0 bridge settings
auto hostbr0
iface hostbr0 inet static
bridge_ports enp5s0
address 192.168.2.11
broadcast 192.168.2.255
netmask 255.255.255.0
gateway 192.168.0.11
It is recommended to disable netfilter:
sudo nano /etc/sysctl.d/99-netfilter-bridge.conf
# net.bridge.bridge-nf-call-ip6tables = 0
# net.bridge.bridge-nf-call-iptables = 0
# net.bridge.bridge-nf-call-arptables = 0
# load the settings written in the file
sudo modprobe br_netfilter
# to load the module automatically at boot
sudo nano /etc/modules-load.d/br_netfilter.conf
# br_netfilter
# load the settings in the 99-netfilter-bridge.conf
sudo sysctl -p /etc/sysctl.d/99-netfilter-bridge.conf
Than I created new virtual network in libvirt
# create a new virtual network
sudo nano /tmp/host-bridged-network.xml
# <network>
# <name>host-bridged-network</name>
# <forward mode="bridge" />
# <bridge name="hostbr0" />
# </network>
sudo virsh net-define /tmp/host-bridged-network.xml
sudo virsh net-start host-bridged-network
sudo virsh net-autostart host-bridged-network
sudo virsh net-list
# Name State Autostart Persistent
# ---------------------------------------------
# default active yes yes
# host-bridged-network active yes yes
virsh net-edit default
# <network>
# <name>default</name>
# <uuid>96dc6685-2006-4d88-9239-20f0b263f14b</uuid>
# <forward mode='nat'/>
# <bridge name='virbr0' stp='on' delay='0'/>
# <mac address='52:54:00:8a:2e:73'/>
# <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>
virsh net-edit host-bridged-network
# <network>
# <name>host-bridged-network</name>
# <uuid>762ec061-5a3d-417e-81ae-e06a920e0b13</uuid>
# <forward mode='bridge'/>
# <bridge name='hostbr0'/>
# </network>
Some information about my host final configuration:
# on the host
ip route
# default via 192.168.0.1 dev enp4s0 proto dhcp metric 100
# 10.139.212.0/24 dev mpqemubr0 proto kernel scope link src 10.139.212.1 linkdown
# 169.254.0.0/16 dev virbr0 scope link metric 1000 linkdown
# 172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown
# 192.168.0.0/24 dev enp4s0 proto kernel scope link src 192.168.0.11 metric 100
# 192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown
ip link
# 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: enp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
# link/ether 50:3e:aa:0c:97:02 brd ff:ff:ff:ff:ff:ff
# 3: enp5s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master hostbr0 state UP mode DEFAULT group default qlen 1000
# link/ether 18:31:bf:cc:08:61 brd ff:ff:ff:ff:ff:ff
# 4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
# link/ether 52:54:00:8a:2e:73 brd ff:ff:ff:ff:ff:ff
# 5: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN mode DEFAULT group default qlen 1000
# link/ether 52:54:00:8a:2e:73 brd ff:ff:ff:ff:ff:ff
# 8: mpqemubr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
# link/ether 52:54:00:87:65:df brd ff:ff:ff:ff:ff:ff
# 9: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default
# link/ether 02:42:e9:8e:81:fc brd ff:ff:ff:ff:ff:ff
# 10: hostbr0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
# link/ether 18:31:bf:cc:08:61 brd ff:ff:ff:ff:ff:ff
Than I added to the ubuntu 20.04 guest virtual machine two network interfaces: default
and host-bridged-network
. Guest starts as usual, I can see Network environment in the Nemo file manager (guest node only). The enp5s0 interface can't connect, Ubuntu tries to establish connection, but always fails. System message: "Activation of network connection failed" for enp5s0
interface. Default libvirt
network is shown as enp9s0
and works correctly.
On the host this interface is shown as unmanaged
.
My questions are:
Which address ranges should I assign to the virtual networks?
The hostbr0
is not created after system reboot, so there is some problem in configuration?
I also have DHCP server initialized on the host, it is currently not used. Maybe it is better to delete it?
Should I add both networks to the guest machine: default
, host-bridged-network
or only host-bridged-network
?
The bridged physical network interface must be plugged in to the router? Or it serves all the functions on the host and the second NIC provides Internet via NAT networking?
Please, suggest improvements on address assignment, I suspect there is something wrong in my configuration