How to Create Bridged Network Shared by KVM Host and Guests Sep 3rd 2021 Words: 340

Background

I am trying to setup a KVM network where one of the guest running OpenWrt will be providing networking for other guests, as well as the host itself. The following figure shows the topology.

Steps

Create the bridge interface

To temporarily (non-persist over reboot) create a bridge interface:

1
ip link add br0 type bridge

To add the interface permanently, edit /etc/network/interface:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# bridge example static IP
auto br0
iface br0 inet static
address 192.168.1.100
network 192.168.1.0
netmask 255.255.255.0
# Include the following line if you want it to be the default route
#gateway 192.168.1.1
broadcast 192.168.1.255
# bridge_ports argument is important else it fails on boot
bridge_ports none
bridge_stp off
bridge_fd 0
bridge_maxwait 0

# bridge example DHCP
auto br0
iface br0 inet dhcp
# bridge_ports argument is important else it fails on boot
bridge_ports none
bridge_stp off
bridge_fd 0
bridge_maxwait 0

KVM guests settings

OpenWrt

The bridge interface should be the first(ordered by PCI slot) interface of the OpenWrt, since it uses the first interface for LAN.

1
2
3
4
5
6
7
8
<interface type="bridge">
<mac address="52:54:00:aa:2a:fe"/>
<source bridge="br0"/>
<target dev="vnet0"/>
<model type="virtio"/>
<alias name="net0"/>
<address type="pci" domain="0x0000" bus="0x00" slot="0x07" function="0x0"/>
</interface>

Other guests

1
2
3
4
5
6
7
8
<interface type="bridge">
<mac address="52:54:00:85:e6:6f"/>
<source bridge="br0"/>
<target dev="vnet1"/>
<model type="virtio"/>
<alias name="net0"/>
<address type="pci" domain="0x0000" bus="0x01" slot="0x00" function="0x0"/>
</interface>

References