We want to have the QEMU/KVM guest VM to be on the same network subnet as the host.
In this example, the host IP on the network has IP address 192.168.0.10. The host only has one and only one NIC.
Disconnect or turn off (the best way is to delete) the existing wired network connection.
This is very important so that the existing connection doesn't interfere with the following setup.
The setup is by using nmcli (command-line tool for controlling NetworkManager) and brctl (ethernet bridge administration)
A handy tool to install is nm-connection-editor which is great for setting up or deleting connections.
One can always create a bridge with brtcl command to test before committing with nmcli. In the following example the only use of brtcl command is to show the bridge connections, and not creating the bridge for testing. We are creating, hence committing, the bridge connection by using nmcli.
sudo nmcli con show
NAME UUID TYPE DEVICE
virbr0 c42932ae-be14-4b8e-9c70-69868d093483 bridge virbr0
We ignore virbr0 as it was created by VirtualBox and create a new one
sudo brctl show
bridge name bridge id STP enabled interfaces
virbr0 8000.52540066413b yes
Again, in this case we are ignoring virbr0 as it is already created by VirtualBox.
Add a new bridge interface on host machine call it br0:
sudo nmcli con add type bridge ifname br0
Connection 'bridge-br0' (0ac8ba53-3ae8-4241-b464-ec0671aa0239) successfully added.
ip a
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether d8:bb:c1:47:1b:bb brd ff:ff:ff:ff:ff:ff <---
altname enp5s0
6: br0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 66:bb:79:6b:bb:67 brd ff:ff:ff:ff:ff:ff <---
Attach the newly added bridge br0 to physical interface on host, in this case eth1:
sudo nmcli con add type bridge-slave ifname eth1 master br0
Connection 'bridge-slave-eth1' (4696cbda-1002-469c-9893-c085e726ebd5) successfully added.
sudo nmcli con show
NAME UUID TYPE DEVICE
bridge-br0 0ac8ba53-3ae8-4241-b464-ec0671aa0239 bridge br0 <---
bridge-slave-eth1 4696cbda-1002-469c-9893-c085e726ebd5 ethernet eth1 <---
virbr0 c42932ae-be14-4b8e-9c70-69868d093483 bridge virbr0
ip a
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP group default qlen 1000
link/ether d8:bb:c1:47:1b:bb brd ff:ff:ff:ff:ff:ff <---
altname enp5s0
6: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether d8:bb:c1:47:1b:bb brd ff:ff:ff:ff:ff:ff <---
inet 192.168.0.10/24 brd 192.168.0.255 scope global dynamic noprefixroute br0
valid_lft 86071sec preferred_lft 86071sec
inet6 fe80::291e:4838:6d3b:6620/64 scope link noprefixroute
valid_lft forever preferred_lft forever
Notice that br0 is now attached to the physical interface *eth1.
This will also reflect in 'brctl show' :
sudo brctl show
bridge name bridge id STP enabled interfaces
br0 8000.d8bbc1471bdb yes eth1 <---
virbr0 8000.52540066413b yes
To check with ip command that br0 is a bridge connection:
ip link show type bridge
6: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
link/ether d8:bb:c1:47:1b:bb brd ff:ff:ff:ff:ff:ff
To check with IP command the master to br0:
ip link show master br0
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP mode DEFAULT group default qlen 1000
link/ether d8:bb:c1:47:1b:bb brd ff:ff:ff:ff:ff:ff
altname enp5s0
Configure the Virtual Machine Manager (QEMU/KVM) to use Network Source as 'Bridge device' and 'Device name': br0
Start the guest VM and run 'ip a' command:
VirtMachine1:~> ip a
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 52:54:00:e8:ba:ce brd ff:ff:ff:ff:ff:ff
inet 192.168.0.192/24 brd 192.168.0.255 scope global dynamic noprefixroute enp1s0
valid_lft 86392sec preferred_lft 86392sec
inet6 fe80::5054:ff:fee8:bace/64 scope link noprefixroute
valid_lft forever preferred_lft forever
Hope this helps.