Many times, in KVM hosts we need to bridge the host's physical network interface with the virtual network interfaces used by the KVM guests.
Install the bridge utilities
# apt-get install bridge-utils
List network interfaces
# ip a|grep ":\ " 1: lo:mtu 16436 qdisc noqueue state UNKNOWN 2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
Inspect the ethernet bridge(s)
# brctl show bridge name bridge id STP enabled interfaces #None yet.
Create a bridge instance that you can access from an interface named b0.
# brctl addbr b0
Show bridge
# brctl show bridge name bridge id STP enabled interfaces b0 8000.000000000000 no
You may add the physical interface(s) to the bridge.
# brctl addif b0 eth0However, do not try it if you are working on a remote host.
See below how to adjust the interfaces file instead.
Delete b0
# brctl delbr b0
Adjust /etc/network/interfaces to create a "persistent" bridge and restart networking.
# vi /etc/network/interfaces # /etc/init.d/networking restart
An example /etc/network/interfaces file where the host has the IP address 192.0.2.29/25 and the interface to the bridge is called b0.
auto lo iface lo inet loopback auto eth0 iface eth0 inet manual auto b0 iface b0 inet static address 192.0.2.29 netmask 255.255.255.128 network 192.0.2.0 broadcast 192.0.2.127 gateway 192.0.2.10 dns-nameservers 192.0.2.4 dns-search ipduh.rocks bridge_ports eth0 bridge_stp on #spanning tree bridge_waitport 0 #no delay before a port becomes available bridge_fd 0 #no forwarding delay bridge_maxwait 0
Inspect bridge.
# brctl show bridge name bridge id STP enabled interfaces b0 8000.40167e6d6745 yes eth0
List network interfaces.
# ip a|grep ":\ " 1: lo:mtu 16436 qdisc noqueue state UNKNOWN 2: eth0: mtu 1500 qdisc pfifo_fast master b0 state UP qlen 1000 4: b0: mtu 1500 qdisc noqueue state UP
Add a KVM host (anaxagoras) and inspect the bridge.
# brctl show bridge name bridge id STP enabled interfaces b0 8000.40167e6d6745 yes anaxagoras eth0
The system used.
# cat /etc/issue /etc/debian_version Debian GNU/Linux 7 \n \l 7.6 # uname -r 3.2.0-4-amd64
L2 bridging for KVM