All posts

Getting Virtual Machines onto the Right VLANs

Updated November 26, 2026

A band of parallel colored lanes entering a hexagonal block and fanning out to separate virtual machine cubes

I had built VLANs (virtual LANs, separate networks sharing one cable) on my firewall, and my hypervisor had no idea they existed.

That was the state of things last Friday. OPNsense was running as my firewall with several VLANs defined, each one a separate network for a different class of machine. Proxmox, my hypervisor (the software that runs virtual machines), was running my VMs. The two were connected by a cable, and every VM still landed on the same flat network no matter what I wanted. My note from that day starts with one line: I don't think Proxmox knows anything about the VLANs. Let's start from scratch.

Starting from scratch was the right call. Here is what the problem actually was and what fixed it.

This is an intermediate post. It assumes you know what an IP address and a subnet are. It's not a master-level networking discussion, but it does move between a few layers of the network, so I'll define the words and the layers first.

Words You'll Need

  • Frame: a unit of data on the local network, at layer 2.
  • Packet: a unit of data with an IP address on it, at layer 3.
  • VLAN (virtual LAN): a separate network that shares a physical cable and switch with other networks, kept apart by a tag.
  • Tag (VLAN ID): a number from 1 to 4094 added to a frame to say which VLAN it belongs to.
  • Trunk port: a switch or firewall port that carries several VLANs, with tags.
  • Access port: a port that carries one VLAN, without tags.
  • Bridge: software that acts like a switch inside the hypervisor. Proxmox calls the default one vmbr0.
  • Hypervisor: the host that runs the virtual machines (VMs).
  • Subnet: a block of IP addresses that share a network, like 192.0.2.0/24.
  • Gateway: the address a machine sends traffic to when the destination is on another network.
  • DHCP (Dynamic Host Configuration Protocol): the service that hands out IP addresses automatically.
  • Firewall: the device that routes between networks and decides what traffic is allowed.

Which Layer Are We Talking About

Networking is described in seven layers, called the OSI (Open Systems Interconnection) model. You can go a long way knowing only the first three:

  1. Layer 1, physical: cables and ports.
  2. Layer 2, data link: frames, MAC addresses (the hardware address of a network card) and switches. VLAN tags live here.
  3. Layer 3, network: IP addresses, subnets and routing. Firewall rules between networks mostly act here.

Layers 4 to 7 (transport, session, presentation and application) are where TCP, HTTP and your actual software live. They matter less for this post.

This post is about layers 2 and 3, and it's easy to blur them. Making a bridge understand tags is layer 2 work. Giving each VLAN an address range, a gateway and firewall rules is layer 3 work. When something breaks, knowing which layer you're debugging cuts the search in half.

Where Should You Define Your Networks?

Before any configuration, there's a design decision that confused me, and it's a big one: where do the networks get defined? You can do it in more than one place:

  • On the firewall. The firewall owns each VLAN: its interface, address range, DHCP and rules.
  • On the hypervisor's virtual switch. The bridge carries the tags and decides which VM ports belong to which VLAN.
  • Between VMs inside one VLAN. Rules at the hypervisor level can control how VMs on the same VLAN talk to each other.
  • Inside the operating system of each VM. The guest can have its own firewall rules or even its own VLAN interfaces.

You can use one, or a little of each. I had originally prepped the VLANs on Proxmox. Then I decided not to go that route, especially as more hypervisors joined the network. Having one place that defines the networks is easier to reason about than having the definitions scattered over every host. So here the firewall defines the networks, and Proxmox's only job is to carry the tags to the right VMs. Whichever way you go, make the choice on purpose.

Why the VMs Were All on One Network

A VLAN is a layer 2 idea: a tag in the Ethernet frame. Switches and firewalls read the tag and keep tagged traffic separate, so one physical cable can carry several networks at once. The firewall was sending and expecting tagged frames for each VLAN.

Proxmox, out of the box, connects VMs through a Linux bridge called vmbr0. A default bridge behaves like a dumb switch. It passes frames between the physical port and the VMs, but it doesn't sort them by tag, and it gives the VMs no way to say which VLAN they belong to. So every VM was effectively plugged into the untagged network, and the VLANs on the firewall were unreachable from inside them.

The fix has three parts: make the bridge understand tags, tell each VM which tag to use, and make sure the path between the host and the firewall carries tagged traffic.

Making the Bridge VLAN-Aware

First, find the physical interface that connects the host to the firewall or the switch:

ip a

On most Proxmox installs it has a name like eno1 or enp3s0. Then look at the network configuration in /etc/network/interfaces. The change is one line on the bridge. Here is a generic version, with a documentation address range standing in for the management network:

auto lo
iface lo inet loopback

auto eno1
iface eno1 inet manual

auto vmbr0
iface vmbr0 inet static
    address 192.0.2.10/24
    gateway 192.0.2.1
    bridge-ports eno1
    bridge-stp off
    bridge-fd 0
    bridge-vlan-aware yes
    bridge-vids 2-4094

bridge-vlan-aware yes is the line that matters. With it, the bridge keeps track of tags and only delivers a frame to a VM port that belongs to that VLAN. You can also set this in the web interface under the node's Network settings by checking "VLAN aware" on the bridge.

Changing the bridge that carries the management address is the classic way to lock yourself out of a remote hypervisor. I always had physical access to the machine, so I could never really lock myself out. If you don't have that, keep a console open (a monitor and keyboard, or IPMI, a remote management port) and a copy of the original file. Then apply:

cp /etc/network/interfaces /etc/network/interfaces.bak
systemctl restart networking

I applied it with a networking restart. On recent Proxmox versions ifreload -a applies the same change without a full restart, but that isn't what I used.

Tagging Each VM

With the bridge VLAN-aware, each VM's network device gets a tag. In the Proxmox web interface: select the VM, open Hardware, edit the Network Device, keep the bridge as vmbr0, and enter the VLAN ID in the VLAN Tag field. From the command line it looks like this (VM ID and VLAN ID are examples):

qm set 101 --net0 virtio,bridge=vmbr0,tag=100

The VM itself needs no VLAN configuration. Proxmox adds the tag on the way out and strips it on the way in, so the guest OS sees an ordinary network card on an ordinary network and gets its address from that VLAN's DHCP server on the firewall. That keeps the setup simple to operate. A new VM goes onto the right network by changing one field, and nobody has to touch the guest.

Putting the Host Itself on a VLAN

Sometimes the hypervisor should live on a VLAN too, usually a management network that only admins can reach. That's a VLAN sub-interface on the bridge, with the management address moved off the untagged bridge:

auto vmbr0.100
iface vmbr0.100 inet static
    address 198.51.100.10/24
    gateway 198.51.100.1

This is optional, and it's the step most likely to cut you off, because the address you're connected through is moving. Do it from the console.

The Other End of the Cable

The bridge is only half of it. Whatever sits between the host and the firewall must pass tagged frames. That's layer 2. If the host plugs straight into a firewall port that has the VLANs assigned, that port already carries them. If there's a managed switch in between, the switch port facing the host and the port facing the firewall both need to be trunk ports carrying those VLANs. An unmanaged switch may pass tags or may not, and that isn't something you want to find out the hard way.

On the firewall side, which is layer 3, each VLAN needs to be assigned to an interface, have an address and a DHCP range, and have rules that allow the traffic you expect. A new VLAN interface in OPNsense starts with no pass rules, so it blocks everything until you add them. That's the safe default, and it's also the first thing to check when a VM gets an address and still can't reach anything.

How I Checked It

I tested in layers, from closest to farthest:

  1. Layers 2 and 3: inside a tagged VM, did it get a DHCP address from the right VLAN's range? That proves the tag is reaching the firewall and coming back.
  2. Layer 2: could two VMs on the same VLAN ping each other? That proves the bridge is delivering within the VLAN.
  3. Layer 3: could the VM ping its gateway on the firewall, and then something past it? That proves routing and rules.
  4. Layer 3: could a VM on one VLAN reach a VM on another only when a firewall rule allowed it? That proves the separation is real.

ping and traceroute were enough for all of it. The last check matters most, because it's the reason the VLANs exist: if every VLAN can reach every other one with no rule in the way, the segmentation isn't doing anything.

What I'd Tell Someone Doing This Tomorrow

Draw the path before you change anything: VM, bridge, physical port, switch port, firewall interface. A VLAN problem is almost always one hop on that path that doesn't know about the tag. Make the bridge VLAN-aware, tag the VM, confirm the switch ports are trunks, and give the firewall interface rules. Then test from the inside of a VM outward, one layer at a time.

And keep a console within reach while you edit the hypervisor's network file. The change itself takes a minute. Recovering from a typo on the management bridge without a console can take the rest of the afternoon.

About the author

Carlos Mendez

Carlos Mendez

IT support and systems, Maui, Hawaii

I come from IT support and systems work. I build and run my own infrastructure and the production websites for West Maui Tech, my business, and I build AI tooling on top of that stack. I write here about what I run, what broke, and how I fixed it.

Enjoyed this article?

Subscribe to get notified about new posts on software engineering, AI development, and infrastructure.

No spam, unsubscribe anytime.