Guida MikroTik
Interfacce, switching e VLANIntermedio

VLAN 802.1Q con bridge vlan-filtering: configurazione completa e sicura

Come configurare VLAN IEEE 802.1Q su RouterOS v7 usando bridge vlan-filtering: porte access con pvid, porte trunk tagged, interfacce L3 per routing inter-VLAN, e come non perdere l'accesso di gestione.

La VLAN 802.1Q permette di segmentare un dominio L2 fisico in più reti logiche isolate. In RouterOS v7 il metodo ufficiale e raccomandato è il bridge con vlan-filtering=yes: tutte le porte del bridge condividono lo stesso switch chip ma il traffico è separato per VLAN ID (VID). Supporta hardware offload sui dispositivi compatibili.

Concetti chiave: tagged, untagged, pvid

  • Tagged (trunk): il frame viaggia CON l'header 802.1Q (4 byte) che contiene il VID. Si usa tra switch/router e verso server/AP che gestiscono più VLAN su un solo cavo.
  • Untagged (access): il frame viaggia SENZA tag. Tipico verso un PC, una CPE, una telecamera — il dispositivo finale non sa nemmeno che esistono le VLAN.
  • pvid (Port VLAN ID): il VID assegnato ai frame untagged che ARRIVANO su una porta. Una porta access ha pvid=10: tutto ciò che entra senza tag viene messo in VLAN 10.
  • Hybrid: una porta può essere untagged in una VLAN (il suo pvid) e tagged in altre — es. un AP che porta il management untagged e le SSID taggate.
Ruolo portaframe-typespvidNella VLAN table
Access (utente/CPE)admit-only-untagged-and-priority-tagged= VID della VLANuntagged
Trunk (verso switch/router)admit-only-vlan-tagged1 (irrilevante)tagged per ogni VLAN
Hybrid (es. AP/server)admit-allVLAN mgmt untaggedtagged + 1 untagged
Bridge stesso (L3/CPU)tagged se serve IP nella VLAN
Comportamento di una porta in base al ruolo

Scenario di riferimento

Obiettivo: tre VLAN su un router/switch MikroTik — VLAN 10 (clienti), VLAN 20 (server), VLAN 99 (gestione). ether1 è il trunk verso l'uplink/firewall (tagged per tutte e tre). ether2–ether4 sono porte access per VLAN 10, ether5 è access VLAN 20, ether6 è access VLAN 99 (management). Il router deve fare routing inter-VLAN.

SICUREZZA PRIMA DI TUTTO: prima di abilitare vlan-filtering, configura e testa l'indirizzo IP di gestione sulla VLAN di management. Abilita vlan-filtering SOLO alla fine, quando tutto è pronto, oppure rischi di perdere l'accesso remoto.
Step 1: Creare il bridge (vlan-filtering ancora disabilitato)
# Il bridge viene creato senza vlan-filtering per ora
/interface/bridge
add name=bridge1 protocol-mode=rstp comment="Bridge principale"
Step 2: Aggiungere le porte con pvid e frame-types corretti
/interface/bridge/port

# Trunk verso uplink: accetta solo frame gia taggati
add bridge=bridge1 interface=ether1 \
    frame-types=admit-only-vlan-tagged \
    hw=yes

# Access port VLAN 10 (clienti): ether2, ether3, ether4
# pvid assegna il VID ai frame untagged in ingresso
add bridge=bridge1 interface=ether2 pvid=10 \
    frame-types=admit-only-untagged-and-priority-tagged \
    hw=yes
add bridge=bridge1 interface=ether3 pvid=10 \
    frame-types=admit-only-untagged-and-priority-tagged \
    hw=yes
add bridge=bridge1 interface=ether4 pvid=10 \
    frame-types=admit-only-untagged-and-priority-tagged \
    hw=yes

# Access port VLAN 20 (server)
add bridge=bridge1 interface=ether5 pvid=20 \
    frame-types=admit-only-untagged-and-priority-tagged \
    hw=yes

# Access port VLAN 99 (gestione)
add bridge=bridge1 interface=ether6 pvid=99 \
    frame-types=admit-only-untagged-and-priority-tagged \
    hw=yes
Step 3: Popolare la VLAN table del bridge
# Per ogni VLAN: definire porte tagged e untagged
# "tagged" = la porta trasmette il frame CON tag 802.1Q
# "untagged" = la porta rimuove il tag prima di trasmettere
# (le access port sono untagged in uscita)

/interface/bridge/vlan

# VLAN 10: trunk tagged, ether2-4 untagged (bridge1 tagged per L3)
add bridge=bridge1 vlan-ids=10 \
    tagged=ether1,bridge1 \
    untagged=ether2,ether3,ether4

# VLAN 20: trunk tagged, ether5 untagged
add bridge=bridge1 vlan-ids=20 \
    tagged=ether1,bridge1 \
    untagged=ether5

# VLAN 99 (management): trunk tagged, ether6 untagged
add bridge=bridge1 vlan-ids=99 \
    tagged=ether1,bridge1 \
    untagged=ether6
Step 4: Creare le interfacce L3 per il routing inter-VLAN
# Interfacce VLAN agganciate al bridge (non alle porte fisiche!)
/interface/vlan
add name=vlan10 vlan-id=10 interface=bridge1
add name=vlan20 vlan-id=20 interface=bridge1
add name=vlan99 vlan-id=99 interface=bridge1

# Assegnare indirizzi IP (gateway per ogni segmento)
/ip/address
add address=10.10.10.1/24 interface=vlan10
add address=10.20.20.1/24 interface=vlan20
add address=192.168.99.1/24 interface=vlan99
Step 5: Abilitare vlan-filtering (operazione finale, con cautela)
# FATTO TUTTO? IP di gestione su vlan99 raggiungibile?
# Solo allora: abilitare il filtraggio VLAN
/interface/bridge
set bridge1 vlan-filtering=yes

# Verifica: il bridge deve rispondere sugli IP L3
/ip/address print
RETE SICURA: esegui lo Step 5 dentro un /system/scheduler con reset automatico, oppure usa la Safe Mode (Ctrl+X in terminale). Se sbagli e perdi l'accesso, dopo il timeout la modifica viene annullata e torni online — invece di una trasferta in sito.

ingress-filtering: controllo accesso frame

ingress-filtering=yes su una bridge port fa sì che i frame in ingresso vengano scartati se il loro VID non è nella VLAN table per quella porta. È una misura di sicurezza: impedisce a un host su VLAN 10 di iniettare traffico taggato su VLAN 20. Da abilitare sempre sulle porte access esposte verso gli utenti.

Abilitare ingress-filtering sulle porte access
# Aggiungere ingress-filtering alle porte access utente
/interface/bridge/port
set [find interface=ether2] ingress-filtering=yes
set [find interface=ether3] ingress-filtering=yes
set [find interface=ether4] ingress-filtering=yes
set [find interface=ether5] ingress-filtering=yes
Diagnostica VLAN: chi è in quale VLAN, in tempo reale
# Tabella VLAN attiva (mostra current-tagged/current-untagged risolti)
/interface/bridge/vlan print

# Su quale VLAN sta un host (vid nella host table)
/interface/bridge/host print where vid=10

# Verificare il pvid effettivo per porta
/interface/bridge/port print detail
BEST PRACTICE: aggiungi sempre bridge1 (l'interfaccia bridge stessa) nella lista tagged= della VLAN table per ogni VLAN che deve avere un'interfaccia L3. Se dimentichi questo passaggio, il routing inter-VLAN non funziona perché il bridge non vede i frame taggati verso la CPU.
ATTENZIONE alla VLAN 1: di default il pvid delle porte è 1 e tutto il management 'untagged' finisce in VLAN 1. Non usare la VLAN 1 per dati reali e non lasciarla come native sul trunk verso i clienti. Molti attacchi di VLAN-hopping sfruttano proprio la native VLAN mal configurata.
VLAN802.1Qvlan-filteringpvidtaggeduntaggedtrunkaccess portframe-typesingress-filteringinter-VLAN routingbridge vlanhybrid port

Configura senza fatica con l'AI

In WispOS l'agente AI genera la configurazione RouterOS dalle tue parole e un tutor ti guida passo passo.

Prova WispOS