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.

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 già 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

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
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.
VLAN802.1Qvlan-filteringpvidtaggeduntaggedtrunkaccess portframe-typesingress-filteringinter-VLAN routingbridge vlan

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