sudo apt install qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils virtinst libvirt-daemon -y
nano br0.xml
Please add the following lines inside br0.xml
<network>
<name>br0</name>
<forward mode="bridge"/>
<bridge name="br0" />
</network>
Press Ctrl+X and then y to save changes. Then issue the following commands:
sudo virsh net-define br0.xml
sudo virsh net-start br0
sudo virsh net-autostart br0
Assuming no errors, the br0 network is defined and ready. Use the following command to verify the status of br0:
sudo virsh net-list --all
The output should look similar to the provided example:
Name State Autostart Persistent
--------------------------------------------
br0 active yes yes
default active yes yes
You can also start the default virsh network if needed with the following commands:
sudo virsh net-start default
sudo virsh net-autostart default
sudo virsh net-list --all
The output should look similar to the example output shown below:
user@hostname:~$ sudo virsh net-list --all
Name State Autostart Persistent
--------------------------------------------
br0 active yes yes
default active yes yes
br0 to Your Physical Network Interface(s)Use the following command to edit /etc/network/interfaces:
sudo nano /etc/network/interfaces
Using nano, make the following changes to /etc/network/interfaces. NOTE: The name of the network interface(s) may be different. Take note and be sure to use the correct interface name(s) on your system. My interface was named eno1.
More details can be found here.
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# Bridge bound to eno1
auto br0
iface br0 inet static
bridge_ports eno1
address 10.0.0.10/24
netmask 255.255.255.0
gateway 10.0.0.1
bridge_stp off
bridge_maxwait 5
dns-nameservers 1.1.1.1 8.8.8.8
When finished, press Ctrl+X followed by Y to save changes to /etc/network/interfaces. Use the following command to restart the network service and apply changes:
sudo systemctl restart networking
Verify the bridge is working and has an IP on your network:
ip a
The output of ip a should look similar to the example shown below. Example output has been truncated:
br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 9e:5e:88:25:07:cf brd ff:ff:ff:ff:ff:ff
inet 10.0.0.10/24 brd 10.0.0.255 scope global br0
valid_lft forever preferred_lft forever
inet6 fe80::9c5e:88ff:fe25:7cf/64 scope link
valid_lft forever preferred_lft forever
Edit /etc/group and add your username to the libvirt group:
sudo nano /etc/group
Find libvirt:x:111: and then add your username:
libvirt:x:111:your-user-name-here
If you need to add additional users to the libvirt group, separate them with commas:
libvirt:x:111:user1,user2,user3
You can also add your username to the libvirt group with the following command:
sudo usermod -aG libvirt $(whoami)
Use the following command to verify membership to the libvirt group:
groups $(whoami)
The output should look similar to the example below:
user : user cdrom floppy sudo audio dip video plugdev users kvm netdev libvirt
To manage the VMs via GUI, install virt-manager on another machine with the following command:
sudo apt install virt-manager -y
Before setting up guest VMs on the hypervisor, use tools like wget, curl, or lynx to download images/ISO files into the /var/lib/libvirt/images/ folder.
If using another machine to manage your KVM hypervisor, it is advisable to copy your SSH ID before adding the connection in virt-manager:
ssh-copy-id user@remote-host
Follow the remaining prompts and connect to the hypervisor via IP address or hostname using virt-manager.
For more complicated network setups, you may want to enable IPv4 forwarding using the following commands:
sudo nano /etc/sysctl.conf
Uncomment or add the following line to /etc/sysctl.conf:
net.ipv4.ip_forward=1
Then apply changes with:
sudo sysctl -p
Explanation: Enabling IP forwarding ensures that the bridge can properly forward traffic, which is crucial for networking performance and reliability in a virtualized environment.
Good luck and happy hacking!