Goal: Get a VM to behave like a real machine on the LAN:
- Gets router DHCP
- Accessible from other devices
- Can host services directly
- Supports PXE
Bridged Networking (pure CLI: KVM/libvirt)
You will need to find your physical interface you are using for the bridge, something like enp3s0.
ip link
Find your physical interface's name and adapt instructions below accordingly.
Create Linux Bridge
Replace enp3s0 with your real NIC.
sudo ip link add name br0 type bridge
sudo ip link set enp3s0 master br0
sudo ip link set br0 up
sudo ip link set enp3s0 up
The br0 created will dies on reboot.
Persistent Bridge (systemd-networkd)
Enable:
sudo systemctl status systemd-networkd
# if not enabled you can enable (or try another way)
sudo systemctl enable systemd-networkd
sudo systemctl start systemd-networkd
Create /etc/systemd/network/br0.netdev
[NetDev]
Name=br0
Kind=bridge
Create /etc/systemd/network/br0.network
[Match]
Name=br0
[Network]
DHCP=yes
Create /etc/systemd/network/enp3s0.network
remember to adapt the name of that file and contents below for your interface name
[Match]
Name=enp3s0
[Network]
Bridge=br0
Restart networking:
sudo systemctl restart systemd-networkd
Verify:
ip a
You should now see your IP on br0, not enp3s0.
Tell libvirt to Use Bridge
If you only need the bridge then there is no need for default NAT network anymore (optional):
sudo virsh net-destroy default
sudo virsh net-autostart --disable default
Create VM Using Bridge
virt-install \
--name arch-bridge \
--memory 4096 \
--vcpus 4 \
--cpu host \
--disk size=40 \
--cdrom /path/to/linux.iso \
--os-variant archlinux \
--network bridge=br0,model=virtio \
--graphics none \
--console pty,target_type=serial \
--boot uefi
Verify It Works
Inside VM:
ip a
You should receive an IP from your LAN router (not 192.168.122.x).
On host:
bridge link
You should see VM tap device attached to br0.
Sanity Checks
Check bridge:
bridge link
bridge addr
Check DHCP from router:
journalctl -u systemd-networkd
Using NetworkManager Instead (Alternative)
sudo nmcli connection add type bridge ifname br0
sudo nmcli connection add type bridge-slave ifname enp3s0 master br0
sudo nmcli connection modify br0 ipv4.method auto
sudo nmcli connection up br0
Network Manager makes Dayne Sad though