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 like a single network. In this case, it allows any connections to the bridge network to get their own internal IPs, as if plugged into the network directly, and work as you'd expect a completely new physical PC to work. i.e. Accessble to other clients outside of the host.

Install bridge-utils

sudo apt install bridge-utils

Find the network to bridge

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

ip a

Bridge it

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

This can be done by editing /etc/network/interfaces

sudo vim /etc/network/interfaces

And setting the following lines

Change existing port to manual

There will already exist some lines with your chosen network adapter, such as

iface enp2s0 inet auto

Change this to contain manual instead

iface enp2s0 inet manual

Static Bridge

If you want your server to have a static IP use this

auto br0
iface br0 inet static
	bridge_ports enp2s0 # which port(s) to bridge together
                address 192.168.0.100 # Static IP
                netmask 255.255.255.0
                network 192.168.0.1
                broadcast 192.168.0.255
                gateway 192.168.0.1
                bridge_stp off # New
                bridge_fd 0 # New
                bridge_maxwait 0 # New
                dns-nameservers 8.8.8.8 8.8.1.1

Dynamic Bridge

If instead you wish your server to have a dynamic IP (not recommended). A bridged network can be set, with a dynamic DHCP set IP

iface br0 inet dhcp
    bridge_ports enp2s0

Create Virtual Network

To make it easier to manage with VMs, this new bridge can be made into a Virtual Network.

Open up a text-editor, and create a file called bridged-network.xml

vim bridged-network.xml

Enter the following, then save

<network>
	<name>bridged-network</name>
	<forward mode="bridge"/>
	<bridge name="br0"/>
</network>

Then pass the file to virsh net-define

sudo virsh net-define bridged-network.xml

Active, and auto-start the new network

sudo virsh net-start bridged-network
sudo virsh net-autostart bridged-network

Reload the network

sudo systemctl restart networking

If this creates the bridge, but claims to have failed, restart your PC

sudo reboot

Check it's there

Run another check for networks, and you should now see br0

ip a

			

Useful Links