Automatically create VLAN bridge interfaces for KVM on RHEL 5-6

At Prophecy, we make extensive use of KVM Virtualization on CentOS6. A VM host can have multiple bridge interfaces (each on a separate VLAN) on which we can run virtual machines.

This lets us (for example) run a dev VM (inside a dev network) on the same physical VM host as a staging VM (in a separate staging network).

Creating these bridge interfaces requires (each time) creating two network config files (one for an ethernet sub-interface, and one for the bridge), and then starting up both interfaces. It’s time-consuming and error-prone.

While doing some work on optimizing pfSense VMs, I wrote this little script to automate the process of creating bridge interfaces. It’s specific to the interface configuration syntax on RHEL5/6