The Archlinux wiki has a good article on VLANs that will show you how to set them up for testing.
On CentOS to do this more permanently, use /etc/sysconfig/network-scripts/
.
For example, /etc/sysconfig/network-scripts/ifcfg-eth0.1
could be:
VLAN=yes
DEVICE=eth0.1
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.0.1
NETMASK=255.255.255.0
And /etc/sysconfig/network-scripts/ifcfg-eth0.2
could be:
VLAN=yes
DEVICE=eth0.2
BOOTPROTO=static
ONBOOT=yes
IPADDR=0.0.0.0
NETMASK=0.0.0.0
BRIDGE=br0
You then create br0, your VM bridge, /etc/sysconfig/network-scripts/ifcfg-br0
:
DEVICE=br0
TYPE=Bridge
IPADDR=192.168.1.1
NETMASK=255.255.255.0
ONBOOT=yes
BOOTPROTO=none
NM_CONTROLLED=no
DELAY=0
Assuming you put the appropriate forwarding rules in place, all traffic from your VMs on br0 will be tagged with VLAN id 2 when it hits the switch.