Sistemi e Reti Anno 4 Modulo 2 Lezione 09 - VLAN, progettazione, configurazione e inter-VLAN routing
Sistemi e Reti · Anno 4 · Modulo 2 · Lezione 09
✍ Autore: profgiagnotti · Materia: Sistemi e Reti

VLAN: progettazione, configurazione e inter-VLAN routing

Segmentazione logica della LAN, tag 802.1Q, porte access e trunk, native VLAN, DTP, configurazione Cisco e tre tecniche di inter-VLAN routing: tradizionale, Router-on-a-Stick e SVI su switch L3.

// obiettivi di apprendimento
✓Spiegare cos'è una VLAN, perché si usano e come segmentano logicamente una LAN fisica in domini broadcast distinti.
✓Descrivere il tag 802.1Q: struttura TPID/TCI, VID a 12 bit, PCP, DEI e differenza tra porte access e trunk.
✓Configurare VLAN di base su switch Cisco: creazione VLAN, assegnazione porte access, configurazione trunk, native VLAN e controllo DTP.
✓Illustrare le tecniche di inter-VLAN routing: routing tradizionale su interfacce fisiche, Router-on-a-Stick con subinterface e SVI su switch L3.
✓Valutare sicurezza e best practice: VLAN hopping, native VLAN dedicata, disabilitazione DTP, shutdown porte non usate e confronto prestazioni.

1. Perché segmentare con le VLAN

Una VLAN (Virtual LAN) è una segmentazione logica di uno switch: anche se gli host sono collegati allo stesso hardware, il traffico broadcast di una VLAN non raggiunge mai un'altra VLAN. È come avere switch virtuali separati.

definizione

VLAN = dominio broadcast logico. Stessa VLAN = L2 diretto. VLAN diverse = serve un router/L3 per comunicare, anche se sono sullo stesso switch fisico.

🔇 Riduzione broadcast

Ogni VLAN limita broadcast, ARP e storm a un sottoinsieme di porte. Migliora prestazioni e stabilità con STP.

🔒 Sicurezza e separazione

Reparti, ospiti, VoIP, IoT isolati a L2. Politiche ACL applicate solo al traffico inter-VLAN su router/firewall.

🧩 Flessibilità geografica

Un utente sposta PC in altro piano ma resta in VLAN 20. Nessun ricascablaggio, solo riconfigurazione porta access.

💡 nota docente

Senza VLAN avresti bisogno di uno switch fisico per reparto. Con 4 reparti e 3 piani = 12 switch. Con VLAN ne bastano 3, uno per piano, con 4 VLAN ciascuno.

LAN fisica unica → 3 VLAN logiche Switch 24 porte VLAN 10 Blu VLAN 20 Gialla VLAN 30 Azzurra 💻192.168.10.0/24 GW .1 🖨192.168.20.0/24 GW .1 📞192.168.30.0/24 GW .1 Broadcast VLAN 10 → solo porte verdi ARP VLAN 20 → solo porte gialle Inter-VLAN → serve router L3

2. Standard 802.1Q: tag, TPID e TCI

Per trasportare più VLAN su un singolo cavo serve un'etichetta. IEEE 802.1Q inserisce 4 byte tra Source MAC e EtherType/Type.

Ethernet frame con tag 802.1Q (4 byte) Dst MAC 6B Src MAC 6B 802.1Q Tag 4BTPID 0x8100 (16) + TCI (16) Type 2B Payload 42-1500 FCS 4B PCP 3b DEI VID 12b 0-4094 (1-1001 normali, 1 e 4095 riservati)
CampoBitSignificatoEsempio
TPID16Tag Protocol Identifier, indica frame tagged = 0x81000x8100
PCP3Priority Code Point - QoS L2 (0-7) per voce/video5 per VoIP
DEI1Drop Eligible, se 1 frame scartabile in congestione0 default
VID12VLAN Identifier: identifica VLAN (0 e 4095 riservati)10, 20, 99
📌 dettaglio tecnico

VID = 12 bit → 4096 VLAN teoriche (0-4095) ma VLAN 0 = priority tag only, VLAN 4095 riservata. Utili: 1-1001 normal-range, 1002-1005 legacy Token/FDDI, 1006-4094 extended. Native VLAN di default = 1 su Cisco.

3. Porte Access vs Trunk, native VLAN e DTP

Uno switch ha due personalità per porta:

CaratteristicaAccessTrunk (802.1Q)
Collega aPC, stampante, AP, telefonoAltro switch, router, switch L3, hypervisor
VLAN trasportate1 sola (untagged)Molte (tagged), più native untagged
Frame in uscita verso hostSenza tag (rimosso all'egress)Con tag, tranne native VLAN
Configurazione tipicaswitchport mode access + switchport access vlan 10switchport mode trunk + switchport trunk allowed vlan 10,20,30
🧑‍🏫 voce / vlan dati

Telefono IP con PC a cascata: porta access con switchport access vlan 10 per dati + switchport voice vlan 30 per VoIP. Due VLAN sulla stessa porta: dati untagged + voce tagged.

Native VLAN e DTP

Su un trunk 802.1Q i frame della native VLAN viaggiano senza tag per compatibilità. Cisco usa di default VLAN 1. Per sicurezza va cambiata in VLAN dedicata inutilizzata (es. 999).

DTP (Dynamic Trunking Protocol) negozia automaticamente access/trunk. Pericolo: un attaccante può negoziare trunk e vedere tutte le VLAN (VLAN hopping). Best practice: disabilitare DTP con switchport nonegotiate e impostare manualmente mode.

IOS · Trunk hardening
Switch(config)# interface range g0/1-2 Switch(config-if-range)# switchport mode trunk Switch(config-if-range)# switchport trunk encapsulation dot1q Switch(config-if-range)# switchport trunk native vlan 999 Switch(config-if-range)# switchport trunk allowed vlan 10,20,30 Switch(config-if-range)# switchport nonegotiate Switch(config-if-range)# spanning-tree portfast trunk ! solo se edge tronco sicuro

4. Configurazione VLAN base su Cisco

Workflow standard: creare VLAN → nome → assegnare porte access → verificare → configurare trunk verso altri switch.

IOS · Creazione VLAN
Switch# configure terminal Switch(config)# vlan 10 Switch(config-vlan)# name AMMINISTRAZIONE Switch(config-vlan)# exit Switch(config)# vlan 20 Switch(config-vlan)# name LABORATORI Switch(config-vlan)# exit Switch(config)# vlan 30 Switch(config-vlan)# name VOIPSwitch(config)# interface range f0/1-10 Switch(config-if-range)# switchport mode access Switch(config-if-range)# switchport access vlan 10 Switch(config-if-range)# spanning-tree portfast ! solo porte end-deviceSwitch(config)# interface g0/1 Switch(config-if)# switchport mode trunk Switch(config-if)# switchport trunk allowed vlan 10,20,30Switch# show vlan brief Switch# show interfaces trunk Switch# show interfaces g0/1 switchport
🔍 verifica rapida

show vlan brief = VLAN esistenti e porte access. show interfaces trunk = trunk attivi, native, allowed. show mac address-table vlan 10 = MAC appresi in VLAN 10. Se host non comunica nella stessa VLAN → porta in VLAN sbagliata o access/trunk invertito.

VLAN untagged (access)

PC invia frame senza tag. Switch aggiunge VID interno alla porta (PVID). In uscita verso altra porta access stessa VLAN → tag rimosso. Ideale per lab VLAN-untagged.pkt.

VLAN tagged (trunk)

Switch mantiene tag tra switch. Host non vedono tag perché rimosso su porte access. Tra due switch: 10 e 20 tagged sullo stesso cavo. Vedi lab VLAN-tagged.pkt e VLAN-STP.pkt con ridondanza.

5. Inter-VLAN routing tradizionale

Due VLAN non parlano a L2. Per far comunicare 192.168.10.0/24 con 192.168.20.0/24 serve L3.

Metodo 1 — router con una interfaccia fisica per VLAN: N VLAN = N porte fisiche su router + N link verso switch. Semplice ma non scala: spreco di porte, cavi, costo.

Inter-VLAN tradizionale: 1 porta fisica = 1 VLAN SwitchVLAN10 f0/1VLAN20 f0/2 g0/0 .10.1 g0/1 .20.1 Routerg0/0 10.1g0/1 20.1 Tabella routing: C 10.0/24 via g0/0, C 20.0/24 via g0/1 → forwarding L3 ❌ Bottleneck: serve 1 cavo/port per VLAN → non scalabile
IOS · Inter-VLAN tradizionale
Router(config)# interface g0/0 Router(config-if)# ip address 192.168.10.1 255.255.255.0 Router(config-if)# no shutdownRouter(config)# interface g0/1 Router(config-if)# ip address 192.168.20.1 255.255.255.0 Router(config-if)# no shutdown! Su switch: f0/1 access vlan 10 verso g0/0 router, f0/2 access vlan 20 verso g0/1
lab consigliato

Apri Inter-VLAN-tradizionale.pkt e Inter-Vlan-tradizionale2.pkt: ping tra VLAN fallisce senza gateway, funziona configurando IP router e default-gateway su PC.

6. Router-on-a-Stick (ROAS)

Un solo link fisico tra switch e router diventa trunk. Sul router si creano subinterface logiche: g0/0.10 per VLAN10, g0/0.20 per VLAN20. Ogni subinterface fa tagging 802.1Q in uscita e untagging in entrata.

ROAS: 1 link fisico + N subinterface logiche Switchg0/1 trunk allow 10,20VLAN10+20 tagged trunk 802.1Q Routerg0/0 no ip !g0/0.10 dot1Q 10 .10.1 /24g0/0.20 dot1Q 20 .20.1 /24 Frame VLAN10 → tag 10 su trunk → subif .10 toglie tag → routing → tag 20 verso subif .20 → frame tagged 20 su trunk → switch → access ⚠ Collo di bottiglia: tutto su 1 Gbps condiviso
IOS · ROAS
Router(config)# interface g0/0 Router(config-if)# no ip address Router(config-if)# no shutdownRouter(config)# interface g0/0.10 Router(config-subif)# encapsulation dot1q 10 Router(config-subif)# ip address 192.168.10.1 255.255.255.0Router(config)# interface g0/0.20 Router(config-subif)# encapsulation dot1q 20 Router(config-subif)# ip address 192.168.20.1 255.255.255.0Router(config)# interface g0/0.30 Router(config-subif)# encapsulation dot1q 30 native ! se usi native 30 su questo trunk Router(config-subif)# ip address 192.168.30.1 255.255.255.0Switch(config)# interface g0/1 Switch(config-if)# switchport mode trunk Switch(config-if)# switchport trunk allowed vlan 10,20,30
⚠ errore comune

Dimenticare no shutdown sull'interfaccia fisica g0/0 → subinterface up ma line protocol down. Encapsulation deve corrispondere esattamente a VLAN permessa su trunk. Ordine: prima encapsulation dot1q poi ip address.

lab

Verifica ROAS con Router-on-a-stick.pkt e Router-on-a-stick2.pkt + video ROAS.

7. SVI e routing inter-VLAN su switch L3

Negli scenari enterprise si usa uno switch multilayer L3: routing in hardware ASIC a velocità di linea, non più bottleneck su singolo link router.

Una SVI (Switched Virtual Interface) è un'interfaccia logica Vlan10 con IP che fa da gateway per quella VLAN. ip routing abilita il motore L3.

IOS · SVI L3
Switch-L3(config)# ip routing Switch-L3(config)# vlan 10,20,30 Switch-L3(config)# interface vlan 10 Switch-L3(config-if)# ip address 192.168.10.1 255.255.255.0 Switch-L3(config-if)# no shutdownSwitch-L3(config)# interface vlan 20 Switch-L3(config-if)# ip address 192.168.20.1 255.255.255.0 Switch-L3(config-if)# no shutdownSwitch-L3(config)# interface vlan 30 Switch-L3(config-if)# ip address 192.168.30.1 255.255.255.0 Switch-L3(config-if)# no shutdown! Porte access come prima ! Verifica: show ip route mostra C direttamente connesse + SVI up
💡 perché SVI è preferito

Routing tra SVI avviene nella fabric dello switch, senza uscire su cavo. Throughput decine di Gbps, latenza microsecondi, possibile routing dinamico OSPF tra distribution e core. Modello gerarchico: access L2 + distribution L3 con SVI.

8. Confronto tra i tre approcci

MetodoHardwarePrestazioniScalabilitàUso tipico
Interfacce fisicheRouter + N porte + N caviMedia❌ Scarsa, max porteLab, legacy, 2-3 VLAN
ROASRouter + 1 link trunk 802.1QMedia (bottleneck 1 link)✅ Buona ≤ 10 VLAN traffico moderatoPMI, sedi piccole
SVI (L3)Switch L3 (3560, 3650, 9300)✅ Molto alta (ASIC)✅ Ottima centinaia VLANEnterprise, Campus

9. Sicurezza: VLAN hopping e hardening

// vlan hopping attack

Switch spoofing: attaccante manda DTP desirable → porta diventa trunk → vede tutte le VLAN. Double tagging: sfrutta native VLAN: 1° tag = native, 2° tag = vittima, switch1 rimuove native e inoltra tag interno a vittima. Contromisure sotto.

MinacciaContromisura obbligatoriaComando
DTP spoofingDisabilita DTP, mode staticoswitchport nonegotiate + mode access/trunk
Native VLAN double tagCambia native a VLAN inutilizzata, tag anche nativeswitchport trunk native vlan 999 + vlan dot1q tag native
Porte non usateShutdown + VLAN blackholeshutdown + switchport access vlan 998
VLAN 1 defaultNon usare VLAN 1 per dati, sposta managementCrea VLAN 99 management
IOS · Hardening template
! Template porta access end-device interface range f0/1-20 switchport mode access switchport access vlan 10 switchport nonegotiate spanning-tree portfast spanning-tree bpduguard enable no shutdown! Template porte non usate interface range f0/21-24, g0/2 switchport mode access switchport access vlan 998 shutdown! Globale vlan dot1q tag native no cdp run ! o limita a trunk necessari no lldp run ! se security stretta
✓VLAN segmenta L2, riduce broadcast, aumenta sicurezza. Host stessa VLAN comunicano diretto L2, VLAN diverse via L3.
✓802.1Q aggiunge 4 byte: TPID 0x8100 + TCI (PCP 3b + DEI 1b + VID 12b = 4096 VLAN).
✓Access = 1 VLAN untagged verso host. Trunk = N VLAN tagged verso switch/router. Native VLAN viaggia untagged.
✓Configurazione base: vlan X, name, switchport access vlan, mode trunk, allowed vlan, verifica con show vlan brief / show interfaces trunk.
✓Inter-VLAN tradizionale = 1 cavo/porta per VLAN. ROAS = 1 trunk + subinterface encapsulation dot1q + IP. SVI = interface vlan X + ip routing su L3.
✓Sicurezza: disabilita DTP, cambia native VLAN a 999, tag native, shutdown porte libere, non usare VLAN 1 per dati, BPDU Guard su access.
QUIZ · VERIFICA
1. Perché due PC in VLAN diverse sullo stesso switch non si pingano anche con IP stessa subnet? 2. Cosa succede su trunk se allowed vlan 10,20 ma manca 30? Frame VLAN 30? 3. In ROAS dimentichi encapsulation dot1q 10 su g0/0.10 ma metti IP: perché non funziona? 4. Qual è il rischio se lasci DTP in auto su porte access verso PC? 5. Disegna: Switch Access (10 PC) --trunk--> Switch L3 con SVI 10(.1) e 20(.1). Dove va default-gateway dei PC? 6. Configura: VLAN 99 management, porta f0/5 access 99, trunk g0/1 allow 10,20,99 native 999, SVI 99 192.168.99.1/24.