Jump directly to main content

Setup a bridge network for KVM

A bridge network is a means to connect/bridge different networks together to act as a single network. In this case, it allows any virtual connections to the bridge network to get their own internal IPs, as if plugged into the network directly.

Install bridge-utils

sudo apt install bridge-utils

Find the network device to bridge

First we need to find the network device we want to bridge to the VMs.

ip link

You'll likely have a device called something similar to enp1s0, or eth0.

Create the bridge network

This will be familiar to those who have set a static ip on linux, as it's essentially the same, with a few additional lines related to bridging

Remove interface from interfaces file

First step is to remove any references to your network device from /etc/network/interfaces, if this file is untouched there will likely be two lines at the bottom.

sudo vim /etc/network/interfaces

Create a new bridge interface

Now create a file in the /etc/network/interfaces.d/ directory, with the name of your bridge (I like br0).

Static IP

auto br0
iface br0 inet static # Name the same as your file (br0)
	gateway # Normally your router's IP
	dns-nameservers # Don't set if resolveconf is installed, comment if internet borked
	bridge_ports enp1s0 # Your device name
	bridge_stp off # Disable Spanning Tree Protocol
        bridge_waitport 0 # No delay before a port becomes available
        bridge_fd 0 # No forwarding delay (Connects to network immediately)

Dynamic IP

iface br0 inet dhcp
    bridge_ports enp2s0

(Optional) Create Virtual Network

To make it easier to manage with VMs, this new bridge can also be made into a Virtual Network (Basically so you can select it from a dropdown).

Create XML file

Open up a text-editor, and create a file called br0.xml, named after the bridge itself.

vim br0.xml

Enter the following, then save

	<forward mode="bridge"/>
	<bridge name="br0"/>

Create the virtual network

sudo virsh net-define br0.xml

Activate, and auto-start (on boot) the new network.

sudo virsh net-start br0
sudo virsh net-autostart br0

You can now remove the br0.xml file.

Reload the network

sudo systemctl restart networking

This may claim to have failed, but if checking with ip link shows the bridge, reboot. Essentially the bridge has been brought up, and it's trying to bring it up again (and can't), then throws an error.

sudo reboot

Check it's there

Run some checks and you should now see br0, with an IP4 address.

ip a
ping google.co.uk

Useful Links