It's been not as easy as expected.
The general hint by @dyasny is true: it's doable, indeed.
The main objectives here are:
Do not use 3rd party tools (like virsh
,virtinst
or libvirt
) in order to learn and understand.
Run VMs without being root with the normal administration unprivileged user.
Here's how I did it.
Disable the main host interface in /etc/network/interfaces
by commenting out the line(s) for the main ethernet.
Create a network bridge containing that interface in the same file.
The original interface will loose the IP that will go to the bridge.
The configuration file would look like this:
auto eth0 # no iface and IP stuff
auto br0
iface br0 inet static
bridge_ports eth0
bridge_stp off
bridge_maxwait 0
bridge_fd 0
address 192.168.255.253/24
gateway 192.168.255.254
- Create an ACL for QEMU to allow the traffic to the bridge in
/etc/quemu/bridge.conf
, ownership to root:kvm
end permissions 0640
.
The directory /etc/quemu/
needs to be root:kvm
and 0770
:
sudo mkdir -v /etc/qemu
# 'br0' is the same name as used in the previous step
echo allow br0 | sudo tee -a /etc/quemu/bridge.conf > /dev/null
sudo chown -R -vc root:kvm /etc/qemu
sudo chmod -vc 0770 /etc/qemu
sudo chmod -vc 0640 /etc/qemu/*
- Fix the bridge helper script. This is truly mandatory as the default installation if effective only with
root
.
sudo chmod -vc u+s /usr/lib/qemu/qemu-bridge-helper
- Add your unprivileged user to group
kvm
. You will need to logout and login (or open a new session) in order to make this effective.
sudo usermod -a -G kvm `id -un`
- Restart the networking.
sudo service networking restart
- Now, when you'll start your VM by command line, you can use for the network device a list of arguments like this:
... \
-netdev bridge,id=net0,br=br0
where net0
is the enumerated network device (the 1st one in this case) and br0
is the name of the bridge interface as defined earlier.
So, for example, an example full command line can be this one:
kvm -cpu host -machine q35 -boot order=dc -vga virtio -vnc 127.255.255.1:0 -name qemutest,process=qemutest -uuid 901f83ce-b999-459b-b1b6-a9ba94cac382 -smp cpus=4 -m size=8192 -cdrom /home/user/image.iso -drive file=/home/user/Desktop/QEMU/qemutest/qemutest-D0.qcow2,if=virtio -device virtio-net-pci,mac=02:19:3e:39:a5:de,netdev=net0 -netdev bridge,id=net0,br=br0