VLANs on MikroTik RouterOS: A Complete Guide
VLANs on MikroTik RouterOS: A Complete Guide
Section titled âVLANs on MikroTik RouterOS: A Complete GuideâRouterOS Version: 7.x+ Difficulty: Intermediate Estimated Time: 45 minutes
TL;DR (Quick Start)
Section titled âTL;DR (Quick Start)âFor the impatient: hereâs the 30-second version.
# Router-on-a-Stick: VLAN interfaces for inter-VLAN routing/interface vlan add name=vlan100 vlan-id=100 interface=ether2/interface vlan add name=vlan200 vlan-id=200 interface=ether2/ip address add address=10.100.0.1/24 interface=vlan100/ip address add address=10.200.0.1/24 interface=vlan200Overview
Section titled âOverviewâVirtual LANs (VLANs) are the foundation of modern network segmentation. On MikroTik RouterOS, there are two fundamentally different approaches to VLAN implementation, and choosing the wrong one is the most common source of confusion and misconfiguration.
This guide explains both approaches, when to use each, and the critical differences that determine whether your network performs efficiently or becomes a troubleshooting nightmare.
The Two VLAN Paradigms
Section titled âThe Two VLAN Paradigmsâ1. VLAN Interfaces (Layer 3 Routing)
Section titled â1. VLAN Interfaces (Layer 3 Routing)âA VLAN interface is a virtual interface that tags/untags traffic for a specific VLAN ID. It sits on top of a physical interface or bridge.
Use when: You need the router to participate in the VLAN - routing between VLANs, running services (DHCP, DNS), or terminating the VLAN.
2. Bridge VLAN Filtering (Layer 2 Switching)
Section titled â2. Bridge VLAN Filtering (Layer 2 Switching)âBridge VLAN filtering uses the bridgeâs built-in VLAN table to control which VLANs can traverse which ports. The bridge acts as a managed switch.
Use when: You need to switch VLAN traffic between ports without the CPU processing every packet - the classic trunk/access port model.
The Critical Mistake
Section titled âThe Critical MistakeâNever create VLAN interfaces on physical ports that are also bridge members with the same VLANs. This creates a âVLAN in a bridge with a physical interfaceâ misconfiguration that causes:
- Packet duplication
- Loops
- Performance degradation (all traffic hits CPU)
- Unpredictable behavior
If you need both switching AND routing, use Bridge VLAN Filtering with VLAN interfaces on the bridge itself, not the physical ports.
Understanding 802.1Q
Section titled âUnderstanding 802.1QâIEEE 802.1Q defines how VLAN tags are inserted into Ethernet frames:
Key terms:
- Tagged frame: Has the 4-byte 802.1Q header inserted
- Untagged frame: No VLAN header (native traffic)
- PVID (Port VLAN ID): The VLAN ID assigned to untagged ingress traffic
- Trunk port: Carries multiple VLANs (usually tagged)
- Access port: Connects end devices (usually untagged)
Reserved VLAN IDs:
- VLAN 0: Priority tagging only (no VLAN assignment)
- VLAN 1: Default VLAN (often used for management, avoid in production)
- VLAN 4095: Reserved
Part 1: VLAN Interfaces for Inter-VLAN Routing
Section titled âPart 1: VLAN Interfaces for Inter-VLAN RoutingâWhen your MikroTik device needs to route between VLANs (act as the gateway), you create VLAN interfaces and assign IP addresses to them.
Scenario: Router-on-a-Stick
Section titled âScenario: Router-on-a-StickâA single router interface connects to a switch trunk port, handling multiple VLANs:
Configuration Steps
Section titled âConfiguration StepsâStep 1: Create VLAN Interfaces
Section titled âStep 1: Create VLAN InterfacesâCreate a VLAN interface for each network segment. The interface parameter specifies which physical port carries the tagged traffic.
/interface vlan add name=vlan100-mgmt vlan-id=100 interface=ether2/interface vlan add name=vlan200-users vlan-id=200 interface=ether2Why name matters: Use descriptive names like vlan100-mgmt rather than just vlan100. When troubleshooting at 2 AM, youâll thank yourself.
Step 2: Assign IP Addresses
Section titled âStep 2: Assign IP AddressesâEach VLAN interface becomes a gateway for that network segment:
/ip address add address=10.100.0.1/24 interface=vlan100-mgmt/ip address add address=10.200.0.1/24 interface=vlan200-usersAt this point, the router can:
- Receive tagged traffic on ether2
- Route between 10.100.0.0/24 and 10.200.0.0/24
- Act as the gateway for devices in each VLAN
Step 3: Configure Services (Optional)
Section titled âStep 3: Configure Services (Optional)âIf the router should provide DHCP to each VLAN:
/ip pool add name=pool-vlan100 ranges=10.100.0.100-10.100.0.200/ip pool add name=pool-vlan200 ranges=10.200.0.100-10.200.0.200
/ip dhcp-server network add address=10.100.0.0/24 gateway=10.100.0.1 dns-server=10.100.0.1/ip dhcp-server network add address=10.200.0.0/24 gateway=10.200.0.1 dns-server=10.200.0.1
/ip dhcp-server add name=dhcp-vlan100 interface=vlan100-mgmt address-pool=pool-vlan100/ip dhcp-server add name=dhcp-vlan200 interface=vlan200-users address-pool=pool-vlan200Verification
Section titled âVerificationâCheck that VLAN interfaces are created and running:
/interface vlan printExpected output shows both VLANs bound to ether2:
Flags: R - RUNNING# NAME MTU ARP VLAN-ID INTERFACE0 R vlan100-mgmt 1500 enabled 100 ether21 R vlan200-users 1500 enabled 200 ether2Verify IP addressing:
/ip address print where interface~"vlanPart 2: Bridge VLAN Filtering for Switching
Section titled âPart 2: Bridge VLAN Filtering for SwitchingâWhen your MikroTik device should act as a managed switch (passing traffic between ports based on VLAN membership), use Bridge VLAN Filtering.
Scenario: Access Switch with Uplink
Section titled âScenario: Access Switch with UplinkâCritical Concept: The Bridge VLAN Table
Section titled âCritical Concept: The Bridge VLAN TableâThe bridge maintains a VLAN table that controls:
- Which VLANs are allowed on each port
- Whether packets egress tagged or untagged
- What VLAN ID to assign to untagged ingress packets (PVID)
Ingress behavior:
- Access port: Untagged packets get tagged with PVID
- Trunk port: Tagged packets pass through; untagged get PVID
Egress behavior:
- Tagged port: Packets sent with VLAN tag
- Untagged port: VLAN tag stripped before sending
Configuration Steps
Section titled âConfiguration StepsâStep 1: Create the Bridge
Section titled âStep 1: Create the BridgeâCreate a bridge but do not enable VLAN filtering yet - you could lock yourself out:
/interface bridge add name=bridge1 vlan-filtering=noStep 2: Add Ports with PVID
Section titled âStep 2: Add Ports with PVIDâAdd ports to the bridge. Set PVID for access ports:
/interface bridge port add bridge=bridge1 interface=ether1/interface bridge port add bridge=bridge1 interface=ether2 pvid=100/interface bridge port add bridge=bridge1 interface=ether3 pvid=200PVID has no effect until VLAN filtering is enabled.
Step 3: Configure the Bridge VLAN Table
Section titled âStep 3: Configure the Bridge VLAN TableâDefine which VLANs are allowed on which ports, and whether they should be tagged or untagged:
/interface bridge vlan add bridge=bridge1 tagged=ether1 untagged=ether2 vlan-ids=100/interface bridge vlan add bridge=bridge1 tagged=ether1 untagged=ether3 vlan-ids=200Common mistake: Do NOT combine multiple VLANs with multiple untagged ports in one entry:
# WRONG - This allows VLAN 100 to leak to ether3 and VLAN 200 to leak to ether2!/interface bridge vlan add bridge=bridge1 tagged=ether1 untagged=ether2,ether3 vlan-ids=100,200Step 4: Enable VLAN Filtering
Section titled âStep 4: Enable VLAN FilteringâOnce configuration is complete, enable filtering:
/interface bridge set bridge1 vlan-filtering=yesWarning: If youâre connected through the bridge, you may lose access. Always configure from:
- A port not in the bridge
- Serial console
- Or configure management access first (see below)
Management Access Through the Bridge
Section titled âManagement Access Through the BridgeâTo access the device through a bridge port using a management VLAN:
- Add the bridge itself as a tagged member of the management VLAN:
/interface bridge vlan add bridge=bridge1 tagged=bridge1,ether1 vlan-ids=99- Create a VLAN interface on the bridge (not a physical port):
/interface vlan add interface=bridge1 name=vlan99-mgmt vlan-id=99/ip address add address=192.168.99.1/24 interface=vlan99-mgmtThe bridge interface is the âCPU portâ - traffic destined for management goes through it.
Verification
Section titled âVerificationâCheck the bridge VLAN table (including dynamic entries):
/interface bridge vlan printExpected output:
Flags: D - DYNAMIC# BRIDGE VLAN-IDS CURRENT-TAGGED CURRENT-UNTAGGED0 bridge1 100 ether1 ether21 bridge1 200 ether1 ether3Check port configuration:
/interface bridge port printCombining Both: Bridge with VLAN Routing
Section titled âCombining Both: Bridge with VLAN RoutingâThe most common production setup: the MikroTik acts as both a switch AND the router/gateway.
Configuration
Section titled âConfigurationâ# Create bridge (VLAN filtering off initially)/interface bridge add name=bridge1 vlan-filtering=no
# Add LAN ports/interface bridge port add bridge=bridge1 interface=ether2 pvid=100/interface bridge port add bridge=bridge1 interface=ether3 pvid=200
# Configure VLAN table - bridge is tagged because we route through it/interface bridge vlan add bridge=bridge1 tagged=bridge1 untagged=ether2 vlan-ids=100/interface bridge vlan add bridge=bridge1 tagged=bridge1 untagged=ether3 vlan-ids=200
# Create VLAN interfaces ON THE BRIDGE (not physical ports!)/interface vlan add interface=bridge1 name=vlan100-mgmt vlan-id=100/interface vlan add interface=bridge1 name=vlan200-users vlan-id=200
# Assign gateway IPs/ip address add address=10.100.0.1/24 interface=vlan100-mgmt/ip address add address=10.200.0.1/24 interface=vlan200-users
# Enable VLAN filtering/interface bridge set bridge1 vlan-filtering=yesKey insight: The VLAN interfaces are created on bridge1, not on ether2 or ether3. The bridge handles Layer 2 switching; the VLAN interfaces handle Layer 3 routing.
Security Considerations
Section titled âSecurity ConsiderationsâIngress Filtering
Section titled âIngress FilteringâBy default, the bridge only checks VLANs on egress. Enable ingress filtering to drop unauthorized VLANs immediately:
/interface bridge port set [find interface=ether1] ingress-filtering=yes/interface bridge port set [find interface=ether2] ingress-filtering=yes/interface bridge port set [find interface=ether3] ingress-filtering=yesFrame Type Filtering
Section titled âFrame Type FilteringâRestrict what frame types each port accepts:
# Trunk port: only accept tagged frames/interface bridge port set [find interface=ether1] frame-types=admit-only-vlan-tagged
# Access ports: only accept untagged frames/interface bridge port set [find interface=ether2] frame-types=admit-only-untagged-and-priority-tagged/interface bridge port set [find interface=ether3] frame-types=admit-only-untagged-and-priority-taggedVLAN Hopping Prevention
Section titled âVLAN Hopping PreventionâAn attacker could send double-tagged frames to âhopâ into another VLAN. Prevent this:
- Use a dedicated native VLAN (not VLAN 1)
- Enable ingress filtering on all ports
- Use frame-type restrictions
- Never use the same VLAN as both tagged and untagged on the same port
Troubleshooting
Section titled âTroubleshootingââI enabled VLAN filtering and lost access
Section titled ââI enabled VLAN filtering and lost accessâThe bridge resets when VLAN filtering is toggled. If you were connected through the bridge:
- Connect via serial console or a port not in the bridge
- Disable VLAN filtering:
/interface bridge set bridge1 vlan-filtering=no - Verify your management VLAN configuration
- Re-enable filtering
âTraffic between VLANs doesnât work
Section titled ââTraffic between VLANs doesnât workâCheck:
- Are VLAN interfaces created on the bridge (not physical ports)?
- Is the bridge tagged for those VLANs in the VLAN table?
- Are IP addresses assigned to VLAN interfaces?
- Is IP forwarding enabled? (
/ip settings print)
âAccess port device canât get DHCP
Section titled ââAccess port device canât get DHCPâVerify:
- PVID is set correctly on the access port
- The VLAN is in the bridge VLAN table with the port as untagged
- DHCP server is listening on the correct VLAN interface
Useful Debug Commands
Section titled âUseful Debug Commandsâ# See bridge VLAN table with current ports/interface bridge vlan print
# Check host table (which MACs seen on which ports/VLANs)/interface bridge host print
# Monitor bridge port statistics/interface bridge port monitor [find]
# Check if hardware offloading is active/interface bridge port print detailCommon Configurations Reference
Section titled âCommon Configurations ReferenceâBasic Access Switch (2 VLANs)
Section titled âBasic Access Switch (2 VLANs)â/interface bridge add name=bridge1/interface bridge port add bridge=bridge1 interface=ether1/interface bridge port add bridge=bridge1 interface=ether2 pvid=10/interface bridge port add bridge=bridge1 interface=ether3 pvid=20/interface bridge vlan add bridge=bridge1 tagged=ether1 untagged=ether2 vlan-ids=10/interface bridge vlan add bridge=bridge1 tagged=ether1 untagged=ether3 vlan-ids=20/interface bridge set bridge1 vlan-filtering=yesRouter-on-a-Stick (Layer 3)
Section titled âRouter-on-a-Stick (Layer 3)â/interface vlan add name=vlan10 vlan-id=10 interface=ether1/interface vlan add name=vlan20 vlan-id=20 interface=ether1/ip address add address=10.10.0.1/24 interface=vlan10/ip address add address=10.20.0.1/24 interface=vlan20Combined Switch + Router
Section titled âCombined Switch + Routerâ/interface bridge add name=bridge1/interface bridge port add bridge=bridge1 interface=ether2 pvid=10/interface bridge port add bridge=bridge1 interface=ether3 pvid=20/interface bridge vlan add bridge=bridge1 tagged=bridge1 untagged=ether2 vlan-ids=10/interface bridge vlan add bridge=bridge1 tagged=bridge1 untagged=ether3 vlan-ids=20/interface vlan add name=vlan10 vlan-id=10 interface=bridge1/interface vlan add name=vlan20 vlan-id=20 interface=bridge1/ip address add address=10.10.0.1/24 interface=vlan10/ip address add address=10.20.0.1/24 interface=vlan20/interface bridge set bridge1 vlan-filtering=yesReferences
Section titled âReferencesâ- MikroTik VLAN Documentation
- Bridge VLAN Filtering
- Bridge VLAN Table
- Layer2 Misconfigurations to Avoid
Configuration Steps
Section titled âConfiguration StepsâThis section provides a minimal testable configuration that validates the core VLAN interface concepts from this guide.
Step 1: Create VLAN Interface
Section titled âStep 1: Create VLAN InterfaceâCreate a VLAN interface for testing:
/interface vlan add name=vlan100-test vlan-id=100 interface=ether2Step 2: Assign IP Address
Section titled âStep 2: Assign IP AddressâAssign an IP address to act as the gateway for this VLAN:
/ip address add address=10.100.0.1/24 interface=vlan100-testVerification
Section titled âVerificationâVerify the VLAN interface was created correctly:
/interface vlan print where name=vlan100-test/ip address print where interface=vlan100-testRelated Topics
Section titled âRelated TopicsâPrerequisites
Section titled âPrerequisitesâ- Bridge Configuration - basic bridge setup before VLAN filtering
- Ethernet Interfaces - physical port configuration
VLAN Implementation
Section titled âVLAN Implementationâ- VLAN Basic Configuration - simplified VLAN setup guide
- Bridge VLAN Filtering - detailed VLAN table configuration
Inter-VLAN Routing
Section titled âInter-VLAN Routingâ- IP Address Configuration - assign IPs to VLAN interfaces
- DHCP Server - per-VLAN DHCP services
- Static Routes - routing between VLANs
Security
Section titled âSecurityâ- Firewall Basics - inter-VLAN firewall rules
- Dot1X - 802.1X port authentication with dynamic VLANs