2.9 KiB
title, description, published, date, tags, editor, dateCreated
| title | description | published | date | tags | editor | dateCreated |
|---|---|---|---|---|---|---|
| Network Bridge | Guide to create a network bridge for KVM guests | true | 2022-04-30T20:10:36.036Z | network, nmcli, networkmanager, kvm, virt-manager | markdown | 2022-04-29T14:05:54.201Z |
The best way to run virtual machines under Linux is the virt-manager UI for qemu.
Virt-manager unfortunately insists on creating a NAT network by default - which takes over DNS port 53 and throws the VM onto a different subnet.
To recitify this, the best solution is to generate a network bridge.
There are several ways to go about it, chiefly with the ip command, the bridgeutils package, or NetworkManager with nmcli.
Since bridgeutils is a seperate, older utility and the ip procedure tends to hamstring the internet connection (probably solveable, but still), I used nmcli.
Arch wiki has a great page on bridge networking. {.is-info}
Create the bridge
In essence:
-
Create the bridge:
nmcli connection add type bridge ifname [bridge name] stp no -
Add your main internet interface as a slave:
nmcli connection add type bridge-slave ifname [internet interface name] master [bridge name] -
Bring your internet interface down:
ncmli connection down [internet interface name] -
Bring the bridge up:
nmcli connection up bridge-[bridge-name](note hownmcliappendsbridge-before the bridge name). -
Assign an IP address to the bridge using your favourite tool (
ip,nmcli,nmtuiand the GNOME GUI all work well).
Register the bridge with Virt-Manager
For Virt-Manager to see your bridge, you must add it as an xml:
-
From the main window, select
Edit->Preferences->Enable XML editing. -
Hover over a VM ->
Edit->Connection Details->+->XML -
Paste the following:
<network>
<name>bridged-network</name>
<forward mode="bridge" />
<bridge name="[bridge-name]" />
</network>
Note you do not need to add the bridge- beforehand.
- You can now use the bridge for virtual machines. Success!
Enable internet access for bridged guests
If all you want is a VM on your subnet and guest-to-host access, you're all done.
Source: LinuxConfig.org {.is-info}
However, if you want the guest to have internet access, you must enable it via sysctl by disabling the Bridge Netfilter:
- Edit
vim /etc/sysctl.d/99-netfilter-bridge.confand write the following:
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0
-
Load the
br_netfiltermodule withmodprobe br_netfilter -
Enable the module at bootime by editing
/etc/modules-load.d/br_netfilter.confand addingbr_netfilter. -
Load the new settings into
sysctlwithsysctl -p /etc/sysctl.d/99-netfilter-bridge.conf
Enjoy your networked KVM guests, yo.