KVM default network and nftables rules for virbr0
Enable the libvirt default network and allow traffic on the virbr0 bridge in nftables.
On a KVM/libvirt host, the default network (bridge virbr0) can be inactive, and its traffic can be blocked by the nftables firewall rules. This article summarises the commands used to set the network to start automatically and to allow traffic on virbr0.
Reference: Xmodulo, "network default is not active"
Enable the default network
sudo virsh net-autostart default
Check and reload nftables
List the tables and rules:
sudo nft list tables
sudo nft list table ip filter -a -n
nft -s list ruleset
Reload the configuration from the file:
nft -f /etc/nftables.conf
Allow traffic on virbr0
sudo nft add rule ip filter position 10 iif "virbr0" accept
sudo nft insert rule ip filter forward position 13 oif "virbr0" accept
sudo nft insert rule ip filter forward position 13 iif "virbr0" accept
Notes
net-autostartsets the network to start automatically. It does not start it immediately: to start it now, usesudo virsh net-start default.- The
positionvalues are specific to the original host. Check the rule handles withsudo nft list table ip filter -abefore running these commands. - The first rule does not name a chain. Check the
nft add rulesyntax for the intended chain before applying it. - Back up
/etc/nftables.confbefore changing it.