0

I have a KVM host that I would like on VLAN 1 and I would like the VM's to use VLAN 2. emo1 on the host is bridged with br0 and the physical interface is connected to a trunk port on a Cisco switch. The issue is most things I have found on the web are conflicting/old or didn't work for me.

I am running Centos 7. What would be the easiest way to tag the guests with a different VLAN than the host?

Thanks!

3

In the host interface, configure a separate interface for each VLAN.

Since the physical interface is connected to a trunk port, all VLANs should be tagged.

So, on the host, you need to configure emo1.1 and emo1.2 interfaces, which correspond to VLAN 1 and VLAN 2 on the physical interface.

Then you create a bridge for the VMs, and add emo1.2 as a bridge member.

After that, you configure emo0.1 for the host connectivity.

The emo0 interface should be up, but it must not have any IP address configured.

You also need to make sure that the 8021q module is loaded so that the kernel has VLAN support.

  • I tried this but for some reason the sub interfaces wouldn't come up. I got an error that said "No suitable device found for this connection.". The way I set it up was emo1 had no address, emo1.1 had an ip, emo.2 had no ip and was bridged with br0 which did have an ip. I think for now I'll just make it work by using a different physical NIC but it does bother my that I couldn't make it work. Thanks again for the help, I'm sure I just did something wrong. – Jonathan Dotson Mar 29 '17 at 22:16
  • 1
    I forgot to mention that one needs the VLAN kernel module, 8021q in order to have support for VLAN interfaces. – Tero Kilkanen Mar 29 '17 at 23:36
0

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.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.