Guía técnica completa: Switching, VLANs, Trunking, STP, Inter-VLAN Routing y Configuración
Un switch opera en la Capa 2 (Enlace de Datos) del modelo OSI. Toma decisiones de reenvío basadas en direcciones MAC usando su tabla CAM (Content Addressable Memory).
┌─────────────────────────────────────────────────────────────┐
│ TABLA CAM (MAC Table) │
├──────────────────────┬────────────┬────────────────────────┤
│ Dirección MAC │ VLAN │ Puerto │
├──────────────────────┼────────────┼────────────────────────┤
│ 00:1A:2B:3C:4D:5E │ 10 │ Fa0/1 │
│ AA:BB:CC:DD:EE:FF │ 20 │ Fa0/5 │
│ 11:22:33:44:55:66 │ 10 │ Gi0/1 (trunk) │
└──────────────────────┴────────────┴────────────────────────┘
Timeout por defecto: 300 segundos (5 minutos)
Trama recibida en puerto X
│
▼
¿Dirección MAC destino en tabla CAM?
│
┌────┴─────┐
NO SÍ
│ │
▼ ▼
FLOODING ¿Mismo puerto que origen?
(todos los │
puertos ├── SÍ → DESCARTAR (evitar bucle)
del VLAN) │
└── NO → REENVIAR al puerto indicado
| Modo | Descripción | Latencia | Detección errores |
|---|---|---|---|
| Store-and-Forward | Recibe la trama completa antes de reenviar | Alta | ✓ Comprueba FCS |
| Cut-Through | Reenvía tras leer solo la MAC destino (6 bytes) | Muy baja | ✗ No comprueba FCS |
| Fragment-Free | Recibe los primeros 64 bytes (evita runts) | Media | Parcial |
Los switches modernos suelen usar Store-and-Forward en combinación con colas de calidad de servicio (QoS).
| Dispositivo | Dominio de colisión | Dominio de broadcast |
|---|---|---|
| Hub | 1 (compartido) | 1 |
| Switch | 1 por puerto | 1 por VLAN |
| Router | 1 por puerto | 1 por interfaz |
Una VLAN (Virtual Local Area Network) es una segmentación lógica de la red a nivel de Capa 2. Permite agrupar puertos de distintos switches como si fueran una única red física, independientemente de su ubicación.
SIN VLANs CON VLANs
───────────────────── ─────────────────────────────
VLAN 10 (Ventas)
PC1──┐ PC1──┐ PC3──┐
PC2──┤ Switch ──────── PC3..PC6 PC2──┤ Switch PC4──┤ Switch
│ │
VLAN 20 (RRHH) │ (trunk)
PC5──┘ PC6──┘
• Un solo dominio broadcast • Dominios broadcast separados
• Sin seguridad lógica • Aislamiento entre departamentos
• Difícil escalabilidad • Políticas de seguridad por VLAN
| Tipo | ID recomendado | Descripción |
|---|---|---|
| VLAN de Datos | 10–999 | Tráfico de usuario normal |
| VLAN de Voz (Voice) | Separada | Tráfico VoIP, requiere QoS |
| VLAN de Gestión | Ej: 99 | Acceso SSH/Telnet al switch |
| VLAN Nativa | 1 (o personalizada) | Tráfico sin etiquetar en trunk |
| VLAN por Defecto | 1 | Todos los puertos la usan al inicio |
| VLAN Negra/Parking | Ej: 999 | Puertos sin usar, desactivados |
| Rango | Tipo | Uso |
|---|---|---|
| 0 | Reservada | No usar |
| 1 | Por defecto | Todos los puertos inicialmente |
| 2–1001 | Normal | VLANs de usuario estándar |
| 1002–1005 | Legacy | FDDI y Token Ring (obsoleto) |
| 1006–4094 | Extendido | Requiere VTP modo transparente o desactivado |
| 4095 | Reservada | No usar |
PC ────────────── [Access Fa0/1 VLAN 10] ──── Switch
sin etiqueta con etiqueta dentro del switch
Switch A ──── [Trunk Gi0/1] ──── [Trunk Gi0/1] ──── Switch B
VLAN 10, 20, 30, 99 →
PC ──── Teléfono IP ──── [Puerto Switch]
│ │
VLAN 10 (datos) VLAN 20 (voz)
El estándar IEEE 802.1Q define cómo se etiquetan las tramas para identificar a qué VLAN pertenecen al transitar por un enlace troncal.
┌────────────┬────────────┬──────────┬───────────────────────┬──────────┐
│ MAC Destino│ MAC Origen │ 802.1Q │ Datos │ FCS │
│ (6 bytes) │ (6 bytes) │ (4 bytes)│ │ (4 bytes)│
└────────────┴────────────┴──────────┴───────────────────────┴──────────┘
│
┌──────────┴──────────┐
│ TAG 802.1Q │
├──────────┬──────────┤
│ TPID │ TCI │
│ 0x8100 │ (2 bytes)│
│ (2 bytes)│ │
└──────────┴──────────┘
│
┌───────────────┴──────────────┐
│ TCI │
├──────┬──────┬────────────────┤
│ PCP │ DEI │ VLAN ID │
│ 3bits│ 1bit │ 12 bits │
│ QoS │Drop │ (0–4094) │
└──────┴──────┴────────────────┘
La VLAN nativa es la única que no lleva etiqueta en el trunk. Por defecto es la VLAN 1.
⚠️ Buenas prácticas: Cambiar la VLAN nativa a una VLAN sin uso (ej: VLAN 999) para evitar ataques de VLAN hopping.
DTP es un protocolo propietario de Cisco que negocia automáticamente si un enlace es trunk o access.
| Modo | Descripción | Inicia negociación |
|---|---|---|
dynamic auto |
Acepta ser trunk si el otro lo solicita | ✗ No |
dynamic desirable |
Intenta activamente convertirse en trunk | ✓ Sí |
trunk |
Siempre trunk, envía DTP | ✓ Sí |
access |
Siempre access, no negocia | ✗ No |
nonegotiate |
Trunk/Access sin DTP (desactiva DTP) | ✗ No |
dynamic auto |
dynamic desirable |
trunk |
access |
|
|---|---|---|---|---|
| dynamic auto | Access | Trunk | Trunk | Access |
| dynamic desirable | Trunk | Trunk | Trunk | Access |
| trunk | Trunk | Trunk | Trunk | ⚠️ Error |
| access | Access | Access | ⚠️ Error | Access |
🔒 Buena práctica de seguridad: Desactivar DTP siempre con
switchport nonegotiateen puertos de acceso y configurar trunks manualmente.
VTP (VLAN Trunking Protocol) es un protocolo propietario de Cisco que permite sincronizar la base de datos de VLANs entre switches de forma centralizada.
┌──────────────┐ VTP advertisements ┌──────────────┐
│ VTP Server │ ─────────────────────────► │ VTP Client │
│ (crea VLANs)│ ◄────────────────────────── │ (solo recibe)│
└──────────────┘ └──────────────┘
│
┌───────┴──────┐
│ VTP Transparent│
│ (reenvía, no │
│ aplica) │
└──────────────┘
| Modo | Crear/Modificar VLANs | Sincronizar BD | Reenviar anuncios |
|---|---|---|---|
| Server | ✓ | ✓ | ✓ |
| Client | ✗ | ✓ | ✓ |
| Transparent | ✓ (local) | ✗ | ✓ |
| Off (VTPv3) | ✓ (local) | ✗ | ✗ |
| Parámetro | Descripción |
|---|---|
| Dominio VTP | Nombre del dominio (debe coincidir entre switches) |
| Contraseña VTP | Autenticación MD5 (opcional pero recomendada) |
| Número de revisión | Contador que aumenta con cada cambio; mayor revisión "gana" |
| Versión VTP | v1, v2, v3 (v3 soporta VLANs extendidas y es más seguro) |
⚠️ Peligro VTP: Un switch recién añadido a la red con un número de revisión mayor puede borrar todas las VLANs del dominio. Por ello muchos administradores prefieren deshabilitar VTP y gestionar VLANs manualmente o con herramientas de automatización.
El VTP Pruning elimina tráfico de broadcast/multicast de VLANs que no tienen puertos activos al otro lado de un trunk, optimizando el ancho de banda.
Sin Pruning: Switch A ──── [Trunk] ──── Switch B
VLAN 10,20,30 floods → (Switch B solo tiene VLAN 10)
VLAN 20,30 tráfico inútil →
Con Pruning: Solo VLAN 10 atraviesa el trunk
Sin STP, los bucles físicos entre switches causan:
- Tormentas de broadcast: Tramas se replican indefinidamente
- Inestabilidad de tabla MAC: Los switches no saben por qué puerto llegan las tramas
- Saturación de CPU: Los dispositivos finales reciben miles de tramas duplicadas
| Protocolo | Estándar | Convergencia | Descripción |
|---|---|---|---|
| STP | IEEE 802.1D | ~50 segundos | Original; lento |
| PVST+ | Cisco (prop.) | ~50 segundos | STP por VLAN (Cisco) |
| RSTP | IEEE 802.1w | ~1-2 segundos | Rapid STP |
| Rapid PVST+ | Cisco (prop.) | ~1-2 segundos | RSTP por VLAN (Cisco) |
| MSTP | IEEE 802.1s | ~1-2 segundos | Múltiples instancias; varias VLANs por árbol |
El Root Bridge es el switch central del árbol STP. Se elige el switch con el menor Bridge ID.
Bridge ID = Prioridad (2 bytes) + MAC Address (6 bytes)
= [16384] + [00:1A:2B:3C:4D:5E]
Prioridad por defecto: 32768 (incrementos de 4096)
Con PVST+: Prioridad = 32768 + VLAN ID
Proceso de elección:
1. Menor prioridad gana
2. En caso de empate → menor dirección MAC gana
| Estado | Duración | Reenvía tramas | Aprende MACs | Descripción |
|---|---|---|---|---|
| Blocking | — | ✗ | ✗ | Puerto bloqueado para evitar bucles |
| Listening | 15 seg | ✗ | ✗ | Escucha BPDUs, participa en elección |
| Learning | 15 seg | ✗ | ✓ | Construye tabla MAC |
| Forwarding | — | ✓ | ✓ | Puerto activo, reenvía tráfico |
| Disabled | — | ✗ | ✗ | Administrativamente deshabilitado |
Con RSTP los estados quedan reducidos a: Discarding, Learning, Forwarding.
| Rol | Descripción |
|---|---|
| Root Port (RP) | Puerto con el menor coste hacia el Root Bridge (uno por switch no-root) |
| Designated Port (DP) | Puerto que reenvía tráfico hacia el segmento (uno por segmento) |
| Alternate Port | Puerto bloqueado, alternativa al Root Port (RSTP) |
| Backup Port | Puerto bloqueado, alternativa al Designated Port (RSTP) |
| Velocidad | Costo IEEE 802.1D | Costo IEEE 802.1w (RSTP) |
|---|---|---|
| 10 Mbps | 100 | 2.000.000 |
| 100 Mbps | 19 | 200.000 |
| 1 Gbps | 4 | 20.000 |
| 10 Gbps | 2 | 2.000 |
| 100 Gbps | — | 200 |
RSTP introduce mecanismos de convergencia rápida:
| Mecanismo | Descripción |
|---|---|
| Edge Port | Puerto conectado a dispositivo final; pasa a Forwarding inmediatamente (equivale a PortFast) |
| Point-to-Point | Enlace full-duplex entre switches; convergencia instantánea |
| Proposal/Agreement | Handshake entre switches para activar puertos rápidamente |
| Topology Change | Notificaciones más eficientes que en 802.1D |
Pasa el puerto directamente a Forwarding (sin Listening/Learning). Solo en puertos de acceso.
⚠️ NUNCA activar PortFast en puertos conectados a otros switches.
Desactiva el puerto si recibe una BPDU (protege puertos con PortFast de switches no autorizados).
Puerto PortFast recibe BPDU → err-disabled inmediatamente
Suprime el envío y recepción de BPDUs en el puerto.
⚠️ Usar con precaución: puede crear bucles si se configura mal.
Evita que un switch externo se convierta en Root Bridge. Si el puerto recibe una BPDU superior, pasa a root-inconsistent (bloqueado).
Detecta si un puerto deja de recibir BPDUs (fallo unidireccional) y lo pone en loop-inconsistent en lugar de pasar a Forwarding.
Las VLANs están aisladas entre sí. Para que se comuniquen necesitan enrutamiento (Capa 3).
Un único enlace físico entre el router y el switch, con subinterfaces por cada VLAN.
┌──────────────┐
│ Router │
│ Gi0/0.10 │ 192.168.10.1/24
│ Gi0/0.20 │ 192.168.20.1/24
│ Gi0/0.30 │ 192.168.30.1/24
└──────┬───────┘
│ Trunk (802.1Q)
┌──────┴───────┐
│ Switch │
├──────────────┤
VLAN 10 │ Fa0/1 Fa0/2 │ VLAN 20
PC1, PC2 │ Fa0/3 Fa0/4 │ PC3, PC4
└──────────────┘
Ventaja: Barato (un solo enlace físico)
Desventaja: Cuello de botella en el enlace único; no escala bien
El switch de capa 3 realiza el enrutamiento internamente mediante SVIs (Switched Virtual Interfaces).
┌────────────────────────────────┐
│ Switch Capa 3 │
│ │
│ SVI VLAN 10: 192.168.10.1/24 │
│ SVI VLAN 20: 192.168.20.1/24 │
│ SVI VLAN 30: 192.168.30.1/24 │
│ │
│ ip routing (activado) │
└────────────────────────────────┘
/ | \
VLAN 10 VLAN 20 VLAN 30
PC1, PC2 PC3, PC4 PC5, PC6
Ventaja: Alto rendimiento, enrutamiento en hardware (ASIC)
Desventaja: Coste del switch L3 (aunque cada vez más asequible)
| Criterio | Router-on-a-Stick | Switch L3 (SVI) |
|---|---|---|
| Coste | Bajo | Medio-alto |
| Rendimiento | Limitado (CPU del router) | Alto (hardware ASIC) |
| Escalabilidad | Baja | Alta |
| Complejidad | Baja | Media |
| Recomendado para | Laboratorio, redes pequeñas | Producción |
EtherChannel (IEEE 802.3ad / LACP) agrupa múltiples enlaces físicos en un único enlace lógico, aumentando el ancho de banda y proporcionando redundancia.
Switch A ════════════ Switch B
Gi0/1 (1Gbps)
Gi0/2 (1Gbps)
Gi0/3 (1Gbps)
══════════════
EtherChannel: 3Gbps lógico
STP ve un único enlace (evita bloqueo)
| Protocolo | Estándar | Modos |
|---|---|---|
| LACP (Link Aggregation Control Protocol) | IEEE 802.3ad | active / passive |
| PAgP (Port Aggregation Protocol) | Cisco propietario | desirable / auto |
| Static | Manual | on / on |
active |
passive |
on |
|
|---|---|---|---|
| active | ✓ EtherChannel | ✓ EtherChannel | ✗ |
| passive | ✓ EtherChannel | ✗ No negocia | ✗ |
| on | ✗ | ✗ | ✓ Static |
desirable |
auto |
on |
|
|---|---|---|---|
| desirable | ✓ EtherChannel | ✓ EtherChannel | ✗ |
| auto | ✓ EtherChannel | ✗ No negocia | ✗ |
| on | ✗ | ✗ | ✓ Static |
El tráfico se distribuye entre los enlaces según el método configurado:
| Método | Descripción |
|---|---|
src-mac |
MAC origen |
dst-mac |
MAC destino |
src-dst-mac |
XOR de MACs origen y destino (más equilibrado) |
src-ip |
IP origen |
dst-ip |
IP destino |
src-dst-ip |
XOR de IPs (recomendado para inter-VLAN) |
src-port |
Puerto TCP/UDP origen |
src-dst-port |
XOR puertos origen y destino |
Limita las direcciones MAC permitidas en un puerto.
| Parámetro | Descripción | Valor típico |
|---|---|---|
maximum |
Máximo de MACs permitidas | 1–8192 (defecto: 1) |
violation |
Acción ante violación | shutdown / restrict / protect |
sticky |
Aprende y guarda MACs dinámicamente | — |
| Modo | Descarta trama | Incrementa contador | Desactiva puerto | Envía Syslog |
|---|---|---|---|---|
protect |
✓ | ✗ | ✗ | ✗ |
restrict |
✓ | ✓ | ✗ | ✓ |
shutdown |
✓ | ✓ | ✓ (err-disabled) | ✓ |
Ataque en el que un atacante accede a VLANs no autorizadas.
El atacante negocia un trunk con el switch usando DTP.
Atacante ──── [DTP dynamic desirable] ──── Switch
←─── trunk establecido ────→
Atacante ve todo el tráfico
Mitigación: Desactivar DTP (nonegotiate) y configurar puertos de acceso explícitamente.
El atacante envía tramas con doble etiqueta 802.1Q.
Atacante (VLAN nativa 1) envía: [Etiqueta VLAN1][Etiqueta VLAN20][datos]
Switch 1 elimina etiqueta VLAN1 (nativa) → reenvía [Etiqueta VLAN20][datos]
Switch 2 recibe trama de VLAN 20 → reenvía a víctima en VLAN 20
Mitigación: Cambiar la VLAN nativa a una VLAN sin uso (999) y no asignarla a ningún host.
Protege contra servidores DHCP falsos (Rogue DHCP).
┌─────────────────────────────────────────────────────────┐
│ DHCP Snooping │
├──────────────────┬──────────────────────────────────────┤
│ Puerto confiado │ Puerto no confiado │
│ (trusted) │ (untrusted) │
├──────────────────┼──────────────────────────────────────┤
│ Uplinks a SW L3 │ Puertos de acceso (usuarios) │
│ Servidor DHCP │ Descarta DHCP Offer/Ack de aquí │
│ legítimo │ Limita tasa de DHCP Discover │
└──────────────────┴──────────────────────────────────────┘
DHCP Snooping crea una tabla de vinculación (binding table):
MAC Address IP Address Lease(sec) Type VLAN Interface
00:1A:2B:3C:4D:5E 192.168.10.10 86400 dhcp 10 Fa0/1
AA:BB:CC:DD:EE:FF 192.168.10.11 86400 dhcp 10 Fa0/2
Usa la tabla de DHCP Snooping para validar respuestas ARP y prevenir ARP Spoofing / ARP Poisoning.
PC atacante envía ARP Reply: "IP 192.168.10.1 tiene MAC AA:BB:CC"
│
Switch verifica contra tabla DHCP Snooping:
"192.168.10.1 → 00:1A:2B:3C:4D:5E" (real)
│
¡No coincide! → Trama DESCARTADA
Filtra tráfico IP basándose en la tabla de DHCP Snooping. Solo permite tráfico de la IP asignada al puerto.
Configuración: ip verify source [port-security]
Efecto: Solo la IP+MAC correcta puede enviar tráfico desde ese puerto
Limita el tráfico de broadcast, multicast y unicast desconocido para prevenir tormentas de red.
Umbrales configurables:
- Porcentaje del ancho de banda (ej: 20%)
- Paquetes por segundo (pps)
- Bits por segundo (bps)
Acciones: shutdown | trap (SNMP) | drop (silencioso)
! ── Crear VLANs ──────────────────────────────────────────────────────────────
Switch# configure terminal
Switch(config)# vlan 10
Switch(config-vlan)# name VENTAS
Switch(config-vlan)# exit
Switch(config)# vlan 20
Switch(config-vlan)# name RRHH
Switch(config-vlan)# exit
Switch(config)# vlan 30
Switch(config-vlan)# name IT
Switch(config-vlan)# exit
Switch(config)# vlan 99
Switch(config-vlan)# name GESTION
Switch(config-vlan)# exit
Switch(config)# vlan 999
Switch(config-vlan)# name PARKING
Switch(config-vlan)# state suspend
Switch(config-vlan)# exit
! ── Crear múltiples VLANs de una vez ─────────────────────────────────────────
Switch(config)# vlan 10,20,30,40,99,999
! ── Verificar VLANs ─────────────────────────────────────────────────────────
Switch# show vlan brief
Switch# show vlan id 10
Switch# show vlan name VENTAS
! ── Puerto de acceso básico ──────────────────────────────────────────────────
Switch(config)# interface FastEthernet 0/1
Switch(config-if)# description PC-Ventas-01
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 10
Switch(config-if)# no shutdown
! ── Puerto con voz (teléfono IP + PC) ────────────────────────────────────────
Switch(config)# interface FastEthernet 0/5
Switch(config-if)# description Telefono-IP-Ventas
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 10 ! VLAN datos (PC)
Switch(config-if)# switchport voice vlan 20 ! VLAN voz (teléfono)
Switch(config-if)# mls qos trust cos ! Confiar en marcado CoS del teléfono
Switch(config-if)# spanning-tree portfast ! PortFast para acceso rápido
Switch(config-if)# no shutdown
! ── Configurar rango de puertos ──────────────────────────────────────────────
Switch(config)# interface range FastEthernet 0/1 - 12
Switch(config-if-range)# description Usuarios-Ventas
Switch(config-if-range)# switchport mode access
Switch(config-if-range)# switchport access vlan 10
Switch(config-if-range)# spanning-tree portfast
Switch(config-if-range)# no shutdown
! ── Puertos sin usar (buena práctica) ────────────────────────────────────────
Switch(config)# interface range FastEthernet 0/20 - 24
Switch(config-if-range)# description NO-USADO
Switch(config-if-range)# switchport mode access
Switch(config-if-range)# switchport access vlan 999
Switch(config-if-range)# shutdown
! ── Trunk básico ─────────────────────────────────────────────────────────────
Switch(config)# interface GigabitEthernet 0/1
Switch(config-if)# description Uplink-a-SwitchCore
Switch(config-if)# switchport trunk encapsulation dot1q ! En switches que soportan ISL también
Switch(config-if)# switchport mode trunk
Switch(config-if)# switchport nonegotiate ! Desactivar DTP
Switch(config-if)# switchport trunk native vlan 999 ! VLAN nativa segura
Switch(config-if)# switchport trunk allowed vlan 10,20,30,99 ! Solo las VLANs necesarias
Switch(config-if)# no shutdown
! ── Gestionar VLANs permitidas en trunk ──────────────────────────────────────
Switch(config-if)# switchport trunk allowed vlan add 40 ! Añadir VLAN
Switch(config-if)# switchport trunk allowed vlan remove 30 ! Eliminar VLAN
Switch(config-if)# switchport trunk allowed vlan except 999 ! Todas menos 999
Switch(config-if)# switchport trunk allowed vlan all ! Todas (no recomendado)
! ── Verificar trunks ──────────────────────────────────────────────────────────
Switch# show interfaces trunk
Switch# show interfaces GigabitEthernet 0/1 trunk
Switch# show interfaces GigabitEthernet 0/1 switchport
! ── Seleccionar Root Bridge (prioridad) ──────────────────────────────────────
Switch(config)# spanning-tree vlan 10 priority 4096 ! Root primario
Switch(config)# spanning-tree vlan 10 priority 8192 ! Root secundario
! ── Método abreviado (Cisco) ──────────────────────────────────────────────────
Switch(config)# spanning-tree vlan 10 root primary ! Ajusta automáticamente
Switch(config)# spanning-tree vlan 20 root secondary ! 28672 de prioridad
! ── Activar Rapid PVST+ ──────────────────────────────────────────────────────
Switch(config)# spanning-tree mode rapid-pvst
! ── PortFast y BPDU Guard ─────────────────────────────────────────────────────
! En puerto individual:
Switch(config-if)# spanning-tree portfast
Switch(config-if)# spanning-tree bpduguard enable
! Globalmente (aplica a todos los puertos PortFast):
Switch(config)# spanning-tree portfast default ! PortFast en todos los puertos de acceso
Switch(config)# spanning-tree portfast bpduguard default ! BPDU Guard global
! ── BPDU Filter ──────────────────────────────────────────────────────────────
Switch(config-if)# spanning-tree bpdufilter enable
! ── Root Guard ────────────────────────────────────────────────────────────────
Switch(config-if)# spanning-tree guard root
! ── Loop Guard ────────────────────────────────────────────────────────────────
Switch(config-if)# spanning-tree guard loop
Switch(config)# spanning-tree loopguard default ! Global
! ── Modificar coste y prioridad de puerto ────────────────────────────────────
Switch(config-if)# spanning-tree vlan 10 cost 10
Switch(config-if)# spanning-tree vlan 10 port-priority 64
! ── Verificar STP ─────────────────────────────────────────────────────────────
Switch# show spanning-tree
Switch# show spanning-tree vlan 10
Switch# show spanning-tree vlan 10 detail
Switch# show spanning-tree summary
Switch# show spanning-tree interface GigabitEthernet 0/1 detail
! ── En el SWITCH: puerto hacia el router en modo trunk ───────────────────────
Switch(config)# interface GigabitEthernet 0/24
Switch(config-if)# switchport trunk encapsulation dot1q
Switch(config-if)# switchport mode trunk
Switch(config-if)# switchport trunk native vlan 999
Switch(config-if)# switchport trunk allowed vlan 10,20,30,99
Switch(config-if)# no shutdown
! ── En el ROUTER: subinterfaces por cada VLAN ────────────────────────────────
Router(config)# interface GigabitEthernet 0/0
Router(config-if)# no shutdown
Router(config)# interface GigabitEthernet 0/0.10
Router(config-subif)# description Gateway-VLAN10-Ventas
Router(config-subif)# encapsulation dot1Q 10
Router(config-subif)# ip address 192.168.10.1 255.255.255.0
Router(config)# interface GigabitEthernet 0/0.20
Router(config-subif)# description Gateway-VLAN20-RRHH
Router(config-subif)# encapsulation dot1Q 20
Router(config-subif)# ip address 192.168.20.1 255.255.255.0
Router(config)# interface GigabitEthernet 0/0.30
Router(config-subif)# description Gateway-VLAN30-IT
Router(config-subif)# encapsulation dot1Q 30
Router(config-subif)# ip address 192.168.30.1 255.255.255.0
Router(config)# interface GigabitEthernet 0/0.99
Router(config-subif)# description Gateway-VLAN99-Gestion
Router(config-subif)# encapsulation dot1Q 99 native ! VLAN nativa
Router(config-subif)# ip address 192.168.99.1 255.255.255.0
! ── Activar enrutamiento IP en el switch L3 ──────────────────────────────────
Switch(config)# ip routing
! ── Crear SVIs (Switch Virtual Interfaces) ───────────────────────────────────
Switch(config)# interface vlan 10
Switch(config-if)# description Gateway-VLAN10-Ventas
Switch(config-if)# ip address 192.168.10.1 255.255.255.0
Switch(config-if)# no shutdown
Switch(config)# interface vlan 20
Switch(config-if)# description Gateway-VLAN20-RRHH
Switch(config-if)# ip address 192.168.20.1 255.255.255.0
Switch(config-if)# no shutdown
Switch(config)# interface vlan 30
Switch(config-if)# description Gateway-VLAN30-IT
Switch(config-if)# ip address 192.168.30.1 255.255.255.0
Switch(config-if)# no shutdown
Switch(config)# interface vlan 99
Switch(config-if)# description Gestion
Switch(config-if)# ip address 192.168.99.1 255.255.255.0
Switch(config-if)# no shutdown
! ── Ruta por defecto hacia el router/firewall ────────────────────────────────
Switch(config)# ip route 0.0.0.0 0.0.0.0 10.0.0.1 ! Gateway de salida a Internet
! ── Enlace punto a punto hacia el router (routed port) ───────────────────────
Switch(config)# interface GigabitEthernet 0/24
Switch(config-if)# description Enlace-a-Router
Switch(config-if)# no switchport ! Convierte en puerto capa 3
Switch(config-if)# ip address 10.0.0.2 255.255.255.252
Switch(config-if)# no shutdown
! ── Verificar enrutamiento ───────────────────────────────────────────────────
Switch# show ip route
Switch# show interfaces vlan 10
Switch# show ip interface brief
! ── Configurar VTP Server ────────────────────────────────────────────────────
Switch(config)# vtp mode server
Switch(config)# vtp domain EMPRESA
Switch(config)# vtp password Cisco123
Switch(config)# vtp version 2 ! o version 3
! ── Configurar VTP Client ────────────────────────────────────────────────────
Switch(config)# vtp mode client
Switch(config)# vtp domain EMPRESA
Switch(config)# vtp password Cisco123
! ── Configurar VTP Transparent ───────────────────────────────────────────────
Switch(config)# vtp mode transparent
! ── Desactivar VTP (recomendado en redes modernas) ───────────────────────────
Switch(config)# vtp mode off ! Solo VTPv3
! o en v1/v2: usar modo transparent en todos los switches
! ── Habilitar VTP Pruning ─────────────────────────────────────────────────────
Switch(config)# vtp pruning ! Solo en VTP Server; se propaga
! ── Verificar VTP ────────────────────────────────────────────────────────────
Switch# show vtp status
Switch# show vtp counters
Switch# show vtp password
! ── EtherChannel con LACP (recomendado, estándar IEEE) ──────────────────────
Switch(config)# interface range GigabitEthernet 0/1 - 3
Switch(config-if-range)# channel-group 1 mode active ! LACP activo
Switch(config-if-range)# no shutdown
! ── EtherChannel con PAgP (Cisco propietario) ────────────────────────────────
Switch(config)# interface range GigabitEthernet 0/1 - 3
Switch(config-if-range)# channel-group 1 mode desirable ! PAgP desirable
! ── EtherChannel estático (sin protocolo) ────────────────────────────────────
Switch(config)# interface range GigabitEthernet 0/1 - 3
Switch(config-if-range)# channel-group 1 mode on ! Ambos lados deben ser 'on'
! ── Configurar la interfaz port-channel ──────────────────────────────────────
Switch(config)# interface port-channel 1
Switch(config-if)# description EtherChannel-a-SwitchCore
Switch(config-if)# switchport trunk encapsulation dot1q
Switch(config-if)# switchport mode trunk
Switch(config-if)# switchport trunk native vlan 999
Switch(config-if)# switchport trunk allowed vlan 10,20,30,99
! ── Configurar balanceo de carga global ──────────────────────────────────────
Switch(config)# port-channel load-balance src-dst-ip
! ── Verificar EtherChannel ───────────────────────────────────────────────────
Switch# show etherchannel summary
Switch# show etherchannel 1 detail
Switch# show etherchannel load-balance
Switch# show lacp neighbor
Switch# show pagp neighbor
Switch# show interfaces port-channel 1
! ── Port Security ────────────────────────────────────────────────────────────
Switch(config)# interface FastEthernet 0/1
Switch(config-if)# switchport mode access
Switch(config-if)# switchport port-security ! Activar
Switch(config-if)# switchport port-security maximum 2 ! Máx. 2 MACs
Switch(config-if)# switchport port-security violation shutdown ! Acción
Switch(config-if)# switchport port-security mac-address sticky ! MACs dinámicas persistentes
! O MAC estática:
Switch(config-if)# switchport port-security mac-address 00:1A:2B:3C:4D:5E
! Recuperar puerto err-disabled manualmente:
Switch(config-if)# shutdown
Switch(config-if)# no shutdown
! O automáticamente:
Switch(config)# errdisable recovery cause psecure-violation
Switch(config)# errdisable recovery interval 300
! ── DHCP Snooping ────────────────────────────────────────────────────────────
Switch(config)# ip dhcp snooping ! Activar globalmente
Switch(config)# ip dhcp snooping vlan 10,20,30 ! En qué VLANs
Switch(config)# no ip dhcp snooping information option ! Desactivar opción 82 (si problemas)
! Puerto confiado (uplink/servidor DHCP)
Switch(config)# interface GigabitEthernet 0/1
Switch(config-if)# ip dhcp snooping trust
! Limitar tasa en puertos no confiados (protección DoS)
Switch(config)# interface FastEthernet 0/1
Switch(config-if)# ip dhcp snooping limit rate 15 ! 15 paquetes/seg
! ── Dynamic ARP Inspection ───────────────────────────────────────────────────
Switch(config)# ip arp inspection vlan 10,20,30
! Puerto confiado (uplink)
Switch(config)# interface GigabitEthernet 0/1
Switch(config-if)# ip arp inspection trust
! Limitar tasa ARP en puertos de acceso
Switch(config)# interface FastEthernet 0/1
Switch(config-if)# ip arp inspection limit rate 100 burst interval 1
! ── IP Source Guard ──────────────────────────────────────────────────────────
Switch(config)# interface FastEthernet 0/1
Switch(config-if)# ip verify source ! Solo IP
Switch(config-if)# ip verify source port-security ! IP + MAC
! ── Storm Control ────────────────────────────────────────────────────────────
Switch(config)# interface FastEthernet 0/1
Switch(config-if)# storm-control broadcast level 20 ! Máx 20% broadcast
Switch(config-if)# storm-control multicast level 20 ! Máx 20% multicast
Switch(config-if)# storm-control unicast level 40 ! Máx 40% unicast desconocido
Switch(config-if)# storm-control action shutdown ! Acción: desactivar
! o:
Switch(config-if)# storm-control action trap ! Solo SNMP
! ── Interfaz de gestión (SVI) ────────────────────────────────────────────────
Switch(config)# interface vlan 99
Switch(config-if)# ip address 192.168.99.10 255.255.255.0
Switch(config-if)# no shutdown
Switch(config)# ip default-gateway 192.168.99.1
! ── Acceso SSH seguro ─────────────────────────────────────────────────────────
Switch(config)# hostname SW-CORE-01
Switch(config)# ip domain-name empresa.local
Switch(config)# crypto key generate rsa modulus 2048
Switch(config)# ip ssh version 2
Switch(config)# ip ssh time-out 60
Switch(config)# ip ssh authentication-retries 3
Switch(config)# username admin privilege 15 secret MiPasswordSegura
Switch(config)# line vty 0 15
Switch(config-line)# transport input ssh
Switch(config-line)# login local
Switch(config-line)# exec-timeout 10 0
# Instalar soporte VLAN
apt install vlan # Debian/Ubuntu
modprobe 8021q
echo "8021q" >> /etc/modules
# Crear interfaz VLAN
ip link add link eth0 name eth0.10 type vlan id 10
ip link add link eth0 name eth0.20 type vlan id 20
# Asignar IPs
ip addr add 192.168.10.100/24 dev eth0.10
ip addr add 192.168.20.100/24 dev eth0.20
# Activar interfaces
ip link set eth0.10 up
ip link set eth0.20 up
# Verificar
ip -d link show eth0.10
cat /proc/net/vlan/config
# Configuración permanente (Debian/Ubuntu – /etc/network/interfaces)
cat >> /etc/network/interfaces << 'EOF'
auto eth0.10
iface eth0.10 inet static
address 192.168.10.100/24
gateway 192.168.10.1
vlan-raw-device eth0
auto eth0.20
iface eth0.20 inet static
address 192.168.20.100/24
vlan-raw-device eth0
EOF
# Con NetworkManager (nmcli)
nmcli connection add type vlan con-name VLAN10 dev eth0 id 10 ip4 192.168.10.100/24 gw4 192.168.10.1
nmcli connection add type vlan con-name VLAN20 dev eth0 id 20 ip4 192.168.20.100/24
nmcli connection up VLAN10
# ── Con bridge-utils (Linux bridge nativo) ────────────────────────────────────
apt install bridge-utils
# Crear bridge
brctl addbr br0
brctl addif br0 eth0
ip link set br0 up
# ── Con Open vSwitch (OVS) ───────────────────────────────────────────────────
apt install openvswitch-switch
# Crear bridge OVS
ovs-vsctl add-br ovs-br0
# Añadir puerto trunk
ovs-vsctl add-port ovs-br0 eth0
ovs-vsctl set port eth0 trunks=10,20,30
# Añadir puerto de acceso (VLAN 10)
ovs-vsctl add-port ovs-br0 veth0
ovs-vsctl set port veth0 tag=10
# Ver configuración
ovs-vsctl show
ovs-ofctl show ovs-br0
# Crear NIC Team con soporte VLAN
New-NetLbfoTeam -Name "NICTeam" -TeamMembers "Ethernet1","Ethernet2" -TeamingMode LACP -LoadBalancingAlgorithm TransportPorts
# Crear interfaz VLAN en Hyper-V vSwitch
Add-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName "vEthernet" -Access -VlanId 10
# Ver VLANs configuradas
Get-VMNetworkAdapterVlan
# En switch virtual Hyper-V – modo trunk
Set-VMNetworkAdapterVlan -VMName "MiVM" -Trunk -AllowedVlanIdList "10,20,30" -NativeVlanId 1
! ── VLANs ────────────────────────────────────────────────────────────────────
show vlan brief ! Resumen de VLANs y puertos
show vlan id 10 ! Detalle de VLAN 10
show interfaces FastEthernet 0/1 switchport ! Estado L2 del puerto
show mac address-table ! Tabla CAM completa
show mac address-table vlan 10 ! Tabla CAM filtrada por VLAN
show mac address-table interface Fa0/1 ! MACs aprendidas en un puerto
show mac address-table aging-time ! Tiempo de envejecimiento
! ── Trunks ───────────────────────────────────────────────────────────────────
show interfaces trunk ! Todos los trunks activos
show interfaces GigabitEthernet 0/1 trunk
show dtp interface GigabitEthernet 0/1 ! Estado DTP
! ── VTP ──────────────────────────────────────────────────────────────────────
show vtp status ! Versión, modo, revisión, dominio
show vtp counters ! Estadísticas de mensajes VTP
show vtp password ! Ver contraseña configurada
! ── STP ──────────────────────────────────────────────────────────────────────
show spanning-tree ! STP en todas las VLANs
show spanning-tree vlan 10 ! STP en VLAN 10
show spanning-tree vlan 10 detail ! Detalle con timers y costes
show spanning-tree vlan 10 root ! Info del Root Bridge
show spanning-tree summary ! Resumen por VLAN
show spanning-tree interface Gi0/1 ! STP en interfaz específica
show spanning-tree inconsistentports ! Puertos en estado inconsistente
! ── EtherChannel ─────────────────────────────────────────────────────────────
show etherchannel summary ! Estado de todos los EC
show etherchannel 1 detail ! Detalle del EC grupo 1
show etherchannel load-balance ! Método de balanceo
show lacp neighbor ! Vecinos LACP
show pagp neighbor ! Vecinos PAgP
show interfaces port-channel 1 ! Estado interfaz lógica
! ── Seguridad ────────────────────────────────────────────────────────────────
show port-security ! Resumen de port security
show port-security interface Fa0/1 ! Detalle de un puerto
show port-security address ! MACs seguras registradas
show ip dhcp snooping ! Estado global DHCP Snooping
show ip dhcp snooping binding ! Tabla de vinculación DHCP
show ip arp inspection vlan 10 ! Estadísticas DAI
show ip arp inspection interfaces ! Estado DAI por interfaz
show storm-control ! Estado storm control
! ── Enrutamiento inter-VLAN ───────────────────────────────────────────────────
show ip route ! Tabla de enrutamiento
show ip interface brief ! Estado de interfaces IP
show interfaces vlan 10 ! Estado SVI VLAN 10
show ip arp ! Tabla ARP
! ── General ──────────────────────────────────────────────────────────────────
show interfaces status ! Estado de todos los puertos
show interfaces FastEthernet 0/1 ! Estadísticas de interfaz
show cdp neighbors detail ! Vecinos CDP (verificar topología)
show lldp neighbors ! Vecinos LLDP
show errdisable recovery ! Estado de recuperación err-disabled
show errdisable detect ! Causas de err-disabled activas
| Síntoma | Posible Causa | Verificación | Solución |
|---|---|---|---|
| Hosts en misma VLAN no se comunican | Puerto en VLAN incorrecta | show interfaces Fa0/X switchport |
switchport access vlan X |
| Hosts no cruzan a otra VLAN | Sin inter-VLAN routing | show ip route / ping gateway |
Configurar SVI o RoaS |
| VLAN no aparece en trunk | No permitida en trunk | show interfaces trunk |
switchport trunk allowed vlan add X |
| Bucle de red / tormenta | STP no convergió | show spanning-tree |
Verificar root bridge, activar RSTP |
| Puerto en err-disabled | BPDU Guard, Port Security... | show errdisable detect |
Corregir causa + shut/no shut |
| Trunk no se forma | Modos DTP incompatibles | show interfaces Gi0/1 switchport |
Configurar switchport mode trunk manual |
| VLAN creada pero sin tráfico | VLAN suspendida o inactiva | show vlan id X |
no state suspend |
| Hosts no obtienen IP | Rogue DHCP o DHCP Snooping | show ip dhcp snooping binding |
Verificar puerto trusted del servidor DHCP |
| EtherChannel no forma | Velocidad/dúplex distintos | show etherchannel summary |
Igualar velocidad, dúplex y modo trunking en todos los miembros |
| VLANs desaparecen tras añadir switch | VTP con revisión mayor | show vtp status |
Resetear revisión (cambiar dominio y volver) o desactivar VTP |
| Baja latencia STP al arrancar | PortFast no configurado | show spanning-tree interface Fa0/1 |
spanning-tree portfast en puertos de acceso |
! Activar debug (puede saturar CPU en producción)
debug spanning-tree events ! Eventos STP
debug spanning-tree bpdu ! BPDUs recibidas/enviadas
debug vtp events ! Eventos VTP
debug etherchannel ! Negociación EtherChannel
debug lacp all ! Todo LACP
! Desactivar todos los debugs
undebug all
no debug all
! Ver mensajes en tiempo real
terminal monitor ! Ver logs en sesión remota
logging console debugging ! Nivel de log en consola
ID Nombre Subred Gateway Uso
────────────────────────────────────────────────────────────────
1 DEFAULT (no usar) — Sin uso activo
10 VENTAS 192.168.10.0/24 192.168.10.1 Comerciales
20 RRHH 192.168.20.0/24 192.168.20.1 Recursos Humanos
30 IT 192.168.30.0/24 192.168.30.1 Informática
40 SERVIDORES 10.10.40.0/24 10.10.40.1 DMZ interna
50 WIFI-CORP 172.16.50.0/23 172.16.50.1 Wi-Fi corporativo
60 WIFI-GUEST 172.16.60.0/23 172.16.60.1 Wi-Fi invitados
70 VOIP 10.10.70.0/24 10.10.70.1 Telefonía IP
99 GESTION 10.99.99.0/24 10.99.99.1 Gestión de red
999 PARKING (sin IP) — Puertos sin usar
! Crear VLAN y nombrar
vlan 10 / name VENTAS
! Puerto acceso
switchport mode access
switchport access vlan 10
spanning-tree portfast
spanning-tree bpduguard enable
! Puerto trunk
switchport trunk encapsulation dot1q
switchport mode trunk
switchport nonegotiate
switchport trunk native vlan 999
switchport trunk allowed vlan 10,20,30,99
! STP
spanning-tree mode rapid-pvst
spanning-tree vlan 10 root primary
spanning-tree portfast default
spanning-tree portfast bpduguard default
! Inter-VLAN L3
ip routing
interface vlan 10 / ip address X.X.X.1 /24
! EtherChannel LACP
channel-group 1 mode active
interface port-channel 1
! Seguridad
switchport port-security maximum 2
switchport port-security violation shutdown
switchport port-security mac-address sticky
ip dhcp snooping vlan 10
ip dhcp snooping trust (en uplinks)
ip arp inspection vlan 10
! Verificación rápida
show vlan brief
show interfaces trunk
show spanning-tree summary
show etherchannel summary
show port-security
show ip dhcp snooping binding
Compatible con: Cisco IOS 12.x / 15.x / 16.x, Cisco NX-OS, Linux kernel 4.x+, Windows Server 2016/2019/2022
Estándares: IEEE 802.1Q, IEEE 802.1D, IEEE 802.1w, IEEE 802.1s, IEEE 802.3ad