Vlans on QEMU-KVM

Cool. I figured out how to configure my KVM host to use a trunked VLAN for multiple subnet access. I can now land a VM on any subnet. Still reviewing if my process is right but here is a script.

#!/bin/bash
VMINT="en0"
VLANINT="vmnetwork"
BRIDGE="vmbridge"
VLANTAG=199

# Bridge should already exist but here is how to create it
nmcli connection add type bridge \
  ifname ${BRIDGE} \
  con-name ${BRIDGE}

# Attach VLAN interface to the bridge
nmcli connection add type vlan \
  ifname ${VLANINT}${VLANTAG} \
  con-name ${VLANINT}${VLANTAG} \
  dev ${VMINT} id ${VLANTAG} \
  master ${BRIDGE}

nmcli con mod ${BRIDGE} ipv4.method "disabled"
nmcli con mod ${BRIDGE} ipv6.method "disabled"

cat << ENDOFFILE > $VLANINT.xml 
<network>
  <name>'$VLANINT'</name>
  <forward mode='bridge'/>
  <bridge name='$BRIDGE'/>
</network>
ENDOFFILE

virsh net-define ${VLANINT}.xml
virsh net-start ${VLANINT}
virsh net-autostart ${VLANINT}

Really cool, another step towards bailing on ESXi.

Weight: 330.6

This entry was posted in Fitbit, New Toys, Technical, Training, Virtualization, Weigh In. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.