Virtual Bridge Setup
Bridge interfaces are helpful in virtual and container environments since they can be easily put in promiscuous mode thus allowing multiple IP and MAC addresses to send traffic over a single physical or virtual interface.
In our lab, we set up virtual bridge interface br0
on every VM and on the phyiscal KVM host.
Identify netplan config file
Ubuntu uses netplan to configure and manage network interfaces. Depending on how your KVM host or VM were set up, you might end up with interface config files that are named differently. For instance, in this lab, the KVM host has it's configuration in /etc/netplan/00-installer-config.yaml
and VMs have their netplan config stored in /etc/netplan/01-netcfg.yaml
.
New nodes will typically have their interfaces configured with a dynamic IP address assigned by DHCP so your netplan config file will look similar to this:
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
enp1s0:
dhcp4: yes
Update netplan config
To set up the br0
virtual bridge with a static IP, modify the contents of netplan config file identified in the previous step, to bridge your physical or network adapter to a virtual bridge interface. Replace the variables shown in <...>
with correct values.
network:
ethernets:
<PHYSICAL_NIC>:
dhcp4: no
dhcp6: no
bridges:
br0:
interfaces: [<PHYSICAL_NIC>]
addresses: [<HOST_IP>/<HOST_NETMASK>]
gateway4: <GATEWAY_IP>
nameservers:
addresses: [<DNS_SERVER_IP>]
parameters:
stp: true
forward-delay: 4
dhcp4: no
dhcp6: no
version: 2
For instance:
Network
Make sure to replace the name of the physical interface with the one that is correct for your system. If necessary, update IP addresses to the ones specific to your environment.
network:
ethernets:
enp37s0:
dhcp4: no
dhcp6: no
bridges:
br0:
interfaces: [enp37s0]
addresses: [10.0.0.235/24]
gateway4: 10.0.0.1
nameservers:
addresses: [10.0.0.1]
parameters:
stp: true
forward-delay: 4
dhcp4: no
dhcp6: no
version: 2
Apply new config
Important
Make sure you have set up your virtual bridge correctly in the previous step. At the moment, you are connected to the host via SSH on a dynamic IP address. As soon as you issue the netplan apply
command, your old IP and network interface will become inaccessible and your SSH session will hang or terminate. You will need to reconnect on the static IP address that is now attached to the new br0
interface. If there is a misconfiguration, you might not be able to reconnect to your VM.
sudo netplan apply
Validate setup
SSH back into the system on the newly configured static IP and validate that the bridge interface is correctly set up:
ip link show
You should see your virtual interface br0
as the master of the phyiscal interface, for instance:
enp37s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UP mode DEFAULT group default qlen 1000
br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
Alternatively, you can check the br0
interface status with the brctl show
command
sudo apt install bridge-utils
brctl show
This should show br0
mapped to the physical interface, such as enp1s0
:
bridge name bridge id STP enabled interfaces
br0 8000.5254006e4b2d yes enp1s0