Padronamento della Configurazione VLAN su Switch Cisco: Una Guida Completa
Nell'architettura delle reti aziendali moderne, le Virtual Local Area Network (VLAN) non sono solo una comodità; sono un pilastro fondamentale della sicurezza, delle prestazioni e della logica organizzativa. Suddividendo un singolo switch fisico in più reti logiche, gli ingegneri possono isolare i domini di broadcast, proteggere dati sensibili e ottimizzare la gestione del traffico. Questa guida fornisce un percorso rigoroso, passo dopo passo, per configurare, verificare e gestire VLAN su switch basati su Cisco IOS, pensato per professionisti della rete che cercano precisione e aderenza alle best practice.
1. Comprendere il Paradigma VLAN
Prima di eseguire i comandi, è fondamentale comprendere il meccanismo. Una VLAN contrassegna i frame Ethernet con un identificatore (ID) 802.1Q, permettendo agli switch di distinguere i flussi di traffico. Le porte di uno switch vengono generalmente assegnate a una delle due modalità:
- Porte di Accesso: Collegano dispositivi finali (PC, stampanti) e trasportano traffico per una singola VLAN. I frame non sono contrassegnati quando lasciano la porta verso il dispositivo.
- Porte Trunk: Collegano switch ad altri switch o router. Trasportano traffico per più VLAN e mantengono i tag 802.1Q per identificare la proprietà del frame.
2. Creazione e Denominazione delle VLAN
Il primo passo nella segmentazione è definire le VLAN nel database dello switch. Sebbene gli ID VLAN possano variare da 1 a 4094, l'intervallo standard (1-1005) è quello più comunemente utilizzato.
Switch# configure terminal Switch(config)# vlan 10 Switch(config-vlan)# name DATA_NETWORK Switch(config-vlan)# exit Switch(config)# vlan 20 Switch(config-vlan)# name VOICE_NETWORK Switch(config-vlan)# exit Switch(config)# vlan 99 Switch(config-vlan)# name MANAGEMENT Switch(config-vlan)# end
Best Practice: Denomina sempre le tue VLAN. In ambienti complessi, vedere “VLAN 20” durante la risoluzione dei problemi è molto meno informativo che vedere “VOICE_NETWORK”.
3. Assegnazione delle Porte alle VLAN (Modalità Accesso)
Una volta create le VLAN, le interfacce fisiche devono essere assegnate ad esse. Questa configurazione comunica allo switch che qualsiasi traffico che entra in una porta specifica appartiene a una VLAN specifica.
Configurazione di un'interfaccia singola:
Switch(config)# interface GigabitEthernet0/1 Switch(config-if)# description Connection to HR_PC_01 Switch(config-if)# switchport mode access Switch(config-if)# switchport access vlan 10 Switch(config-if)# no shutdown
Configurazione di un intervallo di interfacce:
Switch(config)# interface range GigabitEthernet0/2 - 10 Switch(config-if-range)# description HR_Department_PCs Switch(config-if-range)# switchport mode access Switch(config-if-range)# switchport access vlan 10
4. Configurazione dei Link Trunk (Connessione Inter-Switch)
Per far transitare traffico tra switch, è necessario configurare i link trunk. Questi link trasportano frame contrassegnati. È fondamentale impostare la VLAN nativa (traffico che rimane non contrassegnato) su un valore diverso dalla VLAN predefinita 1 per motivi di sicurezza.
Switch(config)# interface GigabitEthernet0/24
Switch(config-if)# description Uplink_to_Core_Switch
Switch(config-if)# switchport trunk encapsulation dot1q
Switch(config-if)# switchport mode trunk
Switch(config-if)# switchport trunk native vlan 99
Switch(config-if)# switchport trunk allowed vlan 10,20,99
Note: The command `switchport trunk encapsulation dot1q` may not be required on newer switches that only support 802.1Q, but it is mandatory on older models that also supported ISL.
5. Configuring Voice VLANs
In environments with IP phones, a single port often supports both a PC and a phone. Cisco switches use a specialized feature called “Voice VLAN” to handle this via a mini-trunk.
Switch(config)# interface GigabitEthernet0/5
Switch(config-if)# description PC_and_Phone
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 10
Switch(config-if)# switchport voice vlan 20
Switch(config-if)# trust device cisco-phone
This configuration places data traffic in VLAN 10 (untagged) and voice traffic in VLAN 20 (tagged), ensuring Quality of Service (QoS) separation.
6. Verification and Troubleshooting
Configuration is only half the job; verification ensures stability. Use the following commands to validate your setup.
Verify VLAN Database
Ensure your VLANs are active and named correctly.
Switch# show vlan brief
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Gi0/11, Gi0/12...
10 DATA_NETWORK active Gi0/1, Gi0/2...
20 VOICE_NETWORK active Gi0/5
99 MANAGEMENT active
Verify Interface Assignments
Check the administrative and operational mode of specific ports.
Switch# show interfaces switchport
Name: Gi0/1
Switchport: Enabled
Administrative Mode: static access
Operational Mode: static access
Access Mode VLAN: 10 (DATA_NETWORK)
Trunking Native Mode VLAN: 1 (default)
...
Verify Trunk Links
Confirm which ports are trunking and which VLANs are allowed across them.
Switch# show interfaces trunk
Port Mode Encapsulation Status Native vlan
Gi0/24 on 802.1q trunking 99
Port Vlans allowed on trunk
Gi0/24 10,20,99
7. Security Best Practices: VLAN Hopping Mitigation
Default configurations are often insecure. Attackers can exploit Dynamic Trunking Protocol (DTP) to hop between VLANs. Secure your ports with these standard hardening steps:
- Disable DTP on Access Ports: By hard-coding `switchport mode access`, you prevent the port from negotiating a trunk link.
- Shutdown Unused Ports: Any port not in use should be administratively down and assigned to a “black hole” VLAN (a VLAN with no Layer 3 access).
- Disable DTP Globally (Optional but Recommended): Use `switchport nonegotiate` on trunk links to stop DTP frames.
Switch(config)# interface GigabitEthernet0/24
Switch(config-if)# switchport nonegotiate
Conclusione
Effective VLAN management is the bedrock of a stable network infrastructure. By strictly adhering to naming conventions, properly configuring trunk and access modes, and implementing security controls against VLAN hopping, network engineers ensure a scalable and secure environment. Regular auditing using verification commands is essential to maintaining configuration integrity over time.
Whatsapp+8613603031172