In this blogpost we will see practical libvirt XML network definition and Linux bridge configuration with VLAN tagging in a KVM environment.
tag (if attaching to a base bridge and tagging per guest):
or using the<network> <name>vlan100-net</name> <forward mode='bridge'/> <bridge name='br0.100' /> <virtualport type='openvswitch'/> </network>
<interface type='bridge'> <source bridge='br0'/> <vlan> <tag id='100'/> </vlan> <model type='virtio'/> </interface>In this setup: Traffic is tagged with VLAN ID 100. The VM connects to br0, and libvirt applies the tag. Linux Bridge Configuration with VLAN Sub-interface (Manual or via nmcli):
# Create VLAN sub-interface ip link add link eth0 name eth0.100 type vlan id 100 ip link set eth0.100 up # Create bridge and attach VLAN interface ip link add name br100 type bridge ip link set eth0.100 master br100 ip link set br100 upOr using nmcli (NetworkManager):
# Create VLAN interface nmcli connection add type vlan con-name vlan100 dev eth0 id 100 # Create bridge nmcli connection add type bridge con-name br-vlan100 ifname br-vlan100 # Add VLAN to bridge nmcli connection add type bridge-slave ifname vlan100 master br-vlan100VM XML Example (VLAN-aware interface):
Using VLAN tagging on the KVM command line provides granular control over VM networking, essential for scalable and secure virtualized infrastructures. Mastery of these CLI tools allows efficient and repeatable network setups without reliance on a GUI.<interface type='bridge'> <source bridge='br100'/> <model type='virtio'/> </interface>
Comments