Create KVM Network Bridge Ubuntu 22.04
In this post we will go through the process of creating a Bridged Networking adapter for Ubuntu 22.04.
Disable Netfilter
# vim /etc/sysctl.d/bridge.conf
Add the following lines then save and exit.
net.bridge.bridge-nf-call-ip6tables=0
net.bridge.bridge-nf-call-iptables=0
net.bridge.bridge-nf-call-arptables=0
Create /etc/udev/rules.d/99-bridge.rules
and add the following line. Save and Exit.
ACTION=="add", SUBSYSTEM=="module", KERNEL=="br_netfilter", RUN+="/sbin/sysctl -p /etc/sysctl.d/bridge.conf"
Reboot for the changes to take effect.
Get Network Interface MAC address
We will need the MAC address of your NIC in order to correctly configure the network bridge.
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp2s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 14:cc:20:02:df:e7 brd ff:ff:ff:ff:ff:ff
The NIC we will attach the bridge to is enp2s0. The MAC address is listed just after link\ether
.
14:cc:20:02:df:e7
Create Netplan configuration for the Bridge
Edit the /etc/netplan/00-installer-config.yaml
file:
network:
version: 2
ethernets:
enp2s0:
dhcp4: false
dhcp6: false
bridges:
br0:
dhcp4: false
dhcp6: false
interfaces: [ enp2s0 ]
macaddress: 14:cc:20:02:df:e7
addresses: [192.168.1.200/24]
nameservers:
addresses: [8.8.8.8, 8.8.8.4]
routes:
- to: default
via: 192.168.1.1
mtu: 1500
parameters:
stp: true
forward-delay: 4
Save and exit.
Apply the changes:
netplan apply
Add the bridge to KVM
Create a new file called bridge.xml
with the following contents:
<network>
<name>br0</name>
<forward mode="bridge"/>
<bridge name="br0"/>
</network>
More information can be found about the libvirt XML format at libvirt documentation.
Run the following commands add the bridge to KVM:
sudo virsh
net-define /path/to/br0.xml
net-start br0
net-autostart br0
net-list
quit