GuíasGuides · Nivel 2Level 2

Cisco: encontrar en qué puerto está un equipo, descripciones de puerto, port-security con MAC sticky y una violación de seguridad al cambiar un PCCisco: finding which port a device is on, port descriptions, port-security with sticky MAC and a security violation after a PC swap

De la IP a la MAC y de la MAC al puerto, saltando de switch en switch con CDP y LLDP; descripciones que ahorran bajadas al armario; port-security con MAC sticky, máximo de direcciones y modos de violación; y un puerto que cae al cambiar el PC de un puesto con teléfono IP.From IP to MAC and from MAC to port, hopping from switch to switch with CDP and LLDP; descriptions that save trips to the cabinet; port-security with sticky MAC, address limits and violation modes; and a port that drops when the PC on a desk with an IP phone is replaced.

¿Prefieres practicarlo?Resuelve el ticket simulado «El puerto del puesto que se apagó solo» en SysAdmin Desks ↗

Qué vas a conseguir

Saber en qué boca de qué switch está conectado un equipo partiendo solo de su IP, dejar los puertos con una descripción que diga qué hay al otro lado, limitar qué equipos pueden conectarse a cada puesto con port-security y resolver la violación de seguridad que aparece cuando alguien cambia el PC de su mesa. La guía de primeros comandos en un switch Cisco cubre la entrada al switch, los show básicos y qué es un puerto en err-disabled; esta parte de ahí.

Antes de empezar

  • Acceso por SSH a los switches de acceso y al núcleo (o al router que hace de puerta de enlace), con un usuario que pueda pasar a enable.
  • La IP o el nombre del equipo que buscas y, si puedes, su MAC (ipconfig /all en Windows).
  • El plano de la sede: qué switch está en qué armario y qué VLAN es de datos y cuál de voz.

Los pasos 1 y 2 son de solo lectura. Las descripciones y port-security cambian la configuración: van con un cambio aprobado, y port-security mal puesto deja puestos sin red.

1. De la IP al puerto, switch a switch

El switch que conoce la IP es el que hace de puerta de enlace de la VLAN (el núcleo o el router). Ahí se traduce la IP a MAC y se ve por qué puerto sale:

SW-CORE-01 · de la IP a la MAC
show ip arp 10.20.0.57Protocol  Address          Age (min)  Hardware Addr   Type   InterfaceInternet  10.20.0.57              3   3c52.82a1.0f44  ARPA   Vlan20show mac address-table address 3c52.82a1.0f44          Mac Address Table-------------------------------------------Vlan    Mac Address       Type        Ports----    -----------       --------    -----  20    3c52.82a1.0f44    DYNAMIC     Gi1/0/2Total Mac Addresses for this criterion: 1show cdp neighbors Gi1/0/2 detailDevice ID: SW-P2-01Entry address(es):  IP address: 10.10.0.22Platform: cisco C9200L-48P-4G,  Capabilities: Switch IGMPInterface: GigabitEthernet1/0/2,  Port ID (outgoing port): GigabitEthernet1/1/1

Gi1/0/2 no es el puesto: es un enlace de subida a otro switch, porque por él se aprenden muchas MAC. CDP dice cuál es y su IP. Se repite allí:

SW-P2-01 · el puerto final
show mac address-table address 3c52.82a1.0f44  20    3c52.82a1.0f44    DYNAMIC     Gi1/0/14show mac address-table interface Gi1/0/14  20    3c52.82a1.0f44    DYNAMIC     Gi1/0/14  30    0004.f2aa.1c09    DYNAMIC     Gi1/0/14show interfaces Gi1/0/14 switchport | include ModeAdministrative Mode: static accessOperational Mode: static access
  • El puerto final es un puerto de acceso con una o dos MAC: el PC en la VLAN de datos y, si lo hay, el teléfono IP en la de voz. Si el puerto que sale es troncal (show interfaces trunk lo lista), hay que seguir saltando.
  • Si la MAC no aparece, el equipo lleva unos minutos sin hablar: la tabla caduca a los 300 segundos por defecto. Un ping a su IP desde el núcleo la vuelve a llenar.
  • LLDP hace lo mismo que CDP con equipos de otros fabricantes (switches HP, puntos de acceso, teléfonos que no son Cisco). En IOS viene apagado: lldp run en configuración global y después show lldp neighbors detail.

2. Descripciones de puerto

Una descripción buena evita repetir el paso 1 la próxima vez. Un formato fijo para toda la sede, por ejemplo PUESTO <número> · <roseta> para usuarios y UPLINK <switch> <puerto> para enlaces:

SW-P2-01 · descripciones
configure terminalinterface Gi1/0/14 description PUESTO 2.11 · R2-B-11interface Gi1/1/1 description UPLINK SW-CORE-01 Gi1/0/2endshow interfaces description | include 2.11|UPLINKGi1/0/14   up     up     PUESTO 2.11 · R2-B-11Gi1/1/1    up     up     UPLINK SW-CORE-01 Gi1/0/2copy running-config startup-config
  • La descripción aparece en show interfaces status, en los registros y en la monitorización por SNMP: un aviso de "Gi1/0/14 down" se entiende mejor como "PUESTO 2.11 down".
  • Cuando un puesto cambia de roseta o de uso, la descripción se cambia en el mismo ticket. Una descripción equivocada es peor que ninguna.

3. Port-security con MAC sticky

Port-security limita cuántas MAC puede aprender un puerto y cuáles. Con sticky, el switch apunta como autorizadas las primeras que ve y las guarda en la configuración:

SW-P2-01 · puerto de usuario con teléfono IP
configure terminalinterface Gi1/0/14 switchport mode access switchport access vlan 20 switchport voice vlan 30 switchport port-security maximum 2 switchport port-security mac-address sticky switchport port-security violation restrict switchport port-securityendshow port-security interface Gi1/0/14 addressVlan    Mac Address       Type                          Ports   Remaining Age----    -----------       ----                          -----   -------------  20    3c52.82a1.0f44    SecureSticky                  Gi1/0/14        -  30    0004.f2aa.1c09    SecureSticky                  Gi1/0/14        -copy running-config startup-config
  • El puerto tiene que ser de acceso fijo (switchport mode access). En un puerto en modo dinámico el switch rechaza el comando.
  • Con teléfono IP, máximo 2: el teléfono en la VLAN de voz y el PC en la de datos. Con máximo 1, el puerto cae en cuanto el teléfono arranca.
  • Las MAC sticky se guardan en la running-config: sin copy running-config startup-config, tras un reinicio el puerto vuelve a aprender las que vea.
  • No se activa en enlaces entre switches, en puertos de puntos de acceso ni en servidores de virtualización: por ellos pasan muchas MAC.

Los modos de violación, qué hace el puerto cuando llega una MAC de más:

ModoTráfico de la MAC nuevaRegistro y contadorEl puerto
protectSe descartaNada: ni log ni contadorSigue arriba
restrictSe descartaMensaje de log, trap SNMP y el contador subeSigue arriba
shutdown (por defecto)Se descartaMensaje de log y trapPasa a err-disabled

restrict es un buen punto de partida en puestos de oficina: el equipo autorizado sigue trabajando y el intruso no pasa, pero queda rastro. shutdown es para zonas donde un equipo desconocido tiene que cortar el puerto (salas de reuniones abiertas, recepción). protect no deja rastro y casi nunca compensa.

4. El ticket: "el puesto 2.11 se quedó sin red al conectar el PC nuevo"

Lunes, 9:10. Han cambiado el PC del puesto 2.11 (con teléfono IP en la mesa). El teléfono funciona; el PC nuevo no coge IP. Este switch tiene los puestos en shutdown y el puerto aparece como err-disabled, pero la clave no es reactivarlo sin más: es leer qué MAC lo provocó y cuáles tiene apuntadas.

SW-P2-01 · qué ha visto port-security
show port-security interface Gi1/0/14Port Security              : EnabledPort Status                : Secure-shutdownViolation Mode             : ShutdownAging Time                 : 0 minsMaximum MAC Addresses      : 2Total MAC Addresses        : 2Configured MAC Addresses   : 0Sticky MAC Addresses       : 2Last Source Address:Vlan   : 8c16.45d0.73b2:20Security Violation Count   : 1show port-security interface Gi1/0/14 address  20    3c52.82a1.0f44    SecureSticky                  Gi1/0/14        -  30    0004.f2aa.1c09    SecureSticky                  Gi1/0/14        -

Cómo se lee:

  • Last Source Address:Vlan es la MAC que provocó la violación y su VLAN: 8c16.45d0.73b2 en la 20, la de datos. Compárala con la del PC nuevo (la etiqueta o el inventario). Si no es la suya, alguien ha conectado otra cosa y el ticket cambia de naturaleza.
  • La tabla de sticky tiene el PC antiguo (3c52.82a1.0f44, VLAN 20) y el teléfono (VLAN 30). El máximo es 2 y ya están las dos plazas ocupadas: el PC nuevo es la tercera.
  • clear port-security sticky interface Gi1/0/14 borraría las dos, también la del teléfono. Aquí sobra solo una.

Con la confirmación de que el equipo nuevo es corporativo:

SW-P2-01 · quitar solo la MAC del PC antiguo y reactivar
clear port-security sticky address 3c52.82a1.0f44configure terminalinterface Gi1/0/14 shutdown no shutdownendshow port-security interface Gi1/0/14 address  20    8c16.45d0.73b2    SecureSticky                  Gi1/0/14        -  30    0004.f2aa.1c09    SecureSticky                  Gi1/0/14        -copy running-config startup-config

Si el contador vuelve a subir con el PC nuevo ya aprendido, hay una tercera MAC legítima que nadie había tenido en cuenta:

Lo que aparece en Last Source AddressOrigen habitualQué haces
Una MAC distinta cada pocos días en la VLAN de datosEl portátil alterna entre la tarjeta del portátil y la de la base de conexiónSe decide cuál se usa en ese puesto o se sube el máximo a 3 en ese puerto y se documenta
Una MAC de fabricante de virtualizaciónUna máquina virtual con adaptador en puente en el PCAdaptador NAT en la máquina virtual; el puente al puesto no se permite
La MAC del teléfono en la VLAN de datosTeléfono que arranca primero sin VLAN de vozSe revisa la VLAN de voz que anuncia el switch al teléfono por CDP o LLDP
Una MAC que nadie reconoceUn equipo personal o un switch pequeño bajo la mesaNo se sube el máximo: se retira el equipo y se informa a seguridad

errdisable recovery cause psecure-violation reactiva solo los puertos caídos por port-security pasado el intervalo (errdisable recovery interval, 300 segundos por defecto). Con el PC antiguo todavía en la tabla, el puerto vuelve, el PC nuevo vuelve a provocar la violación y cae otra vez: la recuperación automática no sustituye a limpiar la MAC.

En el ticket: puerto, la MAC de Last Source Address y a qué equipo corresponde, qué MAC sticky se quitó, el estado final y que la configuración está guardada. Si el inventario tiene la MAC del equipo, actualízalo.

Siguientes pasos

¿Quieres practicarlo? Resuelve el ticket «El puerto del puesto que se apagó solo» en SysAdmin Desks, gratis y en el navegador.

¿Falta algo o en tu entorno es distinto? Escríbeme y lo corrijo.

Rather practise it?Solve the simulated ticket "The desk port that switched itself off" in SysAdmin Desks ↗

What you'll get

Knowing which port on which switch a device is plugged into starting from nothing but its IP, labelling ports with a description of what sits at the other end, limiting which devices can connect at each desk with port-security, and fixing the security violation that appears when someone's desk PC is replaced. The first commands on a Cisco switch guide covers getting into the switch, the basic show commands and what a port in err-disabled is; this one picks up from there.

Before you start

  • SSH access to the access switches and the core (or the router acting as the gateway), with a user that can go into enable.
  • The IP or name of the device you are looking for and, if possible, its MAC (ipconfig /all on Windows).
  • The site map: which switch is in which cabinet and which VLAN is data and which is voice.

Steps 1 and 2 are read-only. Descriptions and port-security change the configuration: they go with an approved change, and badly applied port-security leaves desks without network.

1. From IP to port, switch by switch

The switch that knows the IP is the one acting as the VLAN's gateway (the core or the router). That is where the IP translates into a MAC and you see which port it leaves through:

SW-CORE-01 · from IP to MAC
show ip arp 10.20.0.57Protocol  Address          Age (min)  Hardware Addr   Type   InterfaceInternet  10.20.0.57              3   3c52.82a1.0f44  ARPA   Vlan20show mac address-table address 3c52.82a1.0f44          Mac Address Table-------------------------------------------Vlan    Mac Address       Type        Ports----    -----------       --------    -----  20    3c52.82a1.0f44    DYNAMIC     Gi1/0/2Total Mac Addresses for this criterion: 1show cdp neighbors Gi1/0/2 detailDevice ID: SW-P2-01Entry address(es):  IP address: 10.10.0.22Platform: cisco C9200L-48P-4G,  Capabilities: Switch IGMPInterface: GigabitEthernet1/0/2,  Port ID (outgoing port): GigabitEthernet1/1/1

Gi1/0/2 is not the desk: it is an uplink to another switch, because many MACs are learned through it. CDP tells you which one and its IP. Repeat there:

SW-P2-01 · the final port
show mac address-table address 3c52.82a1.0f44  20    3c52.82a1.0f44    DYNAMIC     Gi1/0/14show mac address-table interface Gi1/0/14  20    3c52.82a1.0f44    DYNAMIC     Gi1/0/14  30    0004.f2aa.1c09    DYNAMIC     Gi1/0/14show interfaces Gi1/0/14 switchport | include ModeAdministrative Mode: static accessOperational Mode: static access
  • The final port is an access port with one or two MACs: the PC on the data VLAN and, if there is one, the IP phone on the voice VLAN. If the port you land on is a trunk (show interfaces trunk lists them), keep hopping.
  • If the MAC does not show up, the device has been quiet for a few minutes: the table ages out after 300 seconds by default. A ping to its IP from the core fills it again.
  • LLDP does the same as CDP with other vendors' devices (HP switches, access points, non-Cisco phones). On IOS it is off: lldp run in global configuration and then show lldp neighbors detail.

2. Port descriptions

A good description saves you repeating step 1 next time. One fixed format for the whole site, for example DESK <number> · <outlet> for users and UPLINK <switch> <port> for links:

SW-P2-01 · descriptions
configure terminalinterface Gi1/0/14 description DESK 2.11 · R2-B-11interface Gi1/1/1 description UPLINK SW-CORE-01 Gi1/0/2endshow interfaces description | include 2.11|UPLINKGi1/0/14   up     up     DESK 2.11 · R2-B-11Gi1/1/1    up     up     UPLINK SW-CORE-01 Gi1/0/2copy running-config startup-config
  • The description shows up in show interfaces status, in the logs and in SNMP monitoring: a "Gi1/0/14 down" alert makes more sense as "DESK 2.11 down".
  • When a desk moves to another outlet or changes use, the description changes in the same ticket. A wrong description is worse than none.

3. Port-security with sticky MAC

Port-security limits how many MACs a port can learn and which ones. With sticky, the switch records the first ones it sees as authorised and keeps them in the configuration:

SW-P2-01 · user port with an IP phone
configure terminalinterface Gi1/0/14 switchport mode access switchport access vlan 20 switchport voice vlan 30 switchport port-security maximum 2 switchport port-security mac-address sticky switchport port-security violation restrict switchport port-securityendshow port-security interface Gi1/0/14 addressVlan    Mac Address       Type                          Ports   Remaining Age----    -----------       ----                          -----   -------------  20    3c52.82a1.0f44    SecureSticky                  Gi1/0/14        -  30    0004.f2aa.1c09    SecureSticky                  Gi1/0/14        -copy running-config startup-config
  • The port has to be a static access port (switchport mode access). On a port in dynamic mode the switch rejects the command.
  • With an IP phone, maximum 2: the phone on the voice VLAN and the PC on the data VLAN. With a maximum of 1, the port drops as soon as the phone boots.
  • Sticky MACs are stored in the running-config: without copy running-config startup-config, after a reboot the port learns whatever it sees again.
  • Do not enable it on links between switches, access point ports or virtualisation hosts: many MACs pass through them.

The violation modes, what the port does when one MAC too many arrives:

ModeTraffic from the new MACLog and counterThe port
protectDroppedNothing: no log, no counterStays up
restrictDroppedLog message, SNMP trap and the counter goes upStays up
shutdown (default)DroppedLog message and trapGoes err-disabled

restrict is a good starting point for office desks: the authorised device keeps working and the intruder gets nowhere, but it leaves a trace. shutdown is for areas where an unknown device should cut the port (open meeting rooms, reception). protect leaves no trace and is rarely worth it.

4. The ticket: "desk 2.11 lost its network when the new PC was plugged in"

Monday, 9:10. The PC at desk 2.11 (with an IP phone on the desk) has been replaced. The phone works; the new PC gets no IP. This switch has its desks in shutdown mode and the port shows as err-disabled, but the key is not simply re-enabling it: it is reading which MAC caused it and which ones it has recorded.

SW-P2-01 · what port-security has seen
show port-security interface Gi1/0/14Port Security              : EnabledPort Status                : Secure-shutdownViolation Mode             : ShutdownAging Time                 : 0 minsMaximum MAC Addresses      : 2Total MAC Addresses        : 2Configured MAC Addresses   : 0Sticky MAC Addresses       : 2Last Source Address:Vlan   : 8c16.45d0.73b2:20Security Violation Count   : 1show port-security interface Gi1/0/14 address  20    3c52.82a1.0f44    SecureSticky                  Gi1/0/14        -  30    0004.f2aa.1c09    SecureSticky                  Gi1/0/14        -

How to read it:

  • Last Source Address:Vlan is the MAC that caused the violation and its VLAN: 8c16.45d0.73b2 on 20, the data VLAN. Compare it with the new PC's (the label or the inventory). If it is not the PC's, someone has plugged in something else and the ticket changes nature.
  • The sticky table holds the old PC (3c52.82a1.0f44, VLAN 20) and the phone (VLAN 30). The maximum is 2 and both slots are taken: the new PC is the third.
  • clear port-security sticky interface Gi1/0/14 would clear both, the phone's as well. Only one has to go here.

Once it is confirmed the new device is corporate:

SW-P2-01 · remove only the old PC's MAC and re-enable
clear port-security sticky address 3c52.82a1.0f44configure terminalinterface Gi1/0/14 shutdown no shutdownendshow port-security interface Gi1/0/14 address  20    8c16.45d0.73b2    SecureSticky                  Gi1/0/14        -  30    0004.f2aa.1c09    SecureSticky                  Gi1/0/14        -copy running-config startup-config

If the counter goes up again with the new PC already learned, there is a third legitimate MAC nobody had accounted for:

What shows in Last Source AddressUsual sourceWhat you do
A different MAC every few days on the data VLANThe laptop switches between its own network card and the dock'sDecide which one is used at that desk, or raise the maximum to 3 on that port and document it
A MAC from a virtualisation vendorA virtual machine with a bridged adapter on the PCNAT adapter on the virtual machine; bridging onto the desk port is not allowed
The phone's MAC on the data VLANA phone that boots first without the voice VLANCheck the voice VLAN the switch advertises to the phone over CDP or LLDP
A MAC nobody recognisesA personal device or a small switch under the deskThe maximum is not raised: the device is removed and security is informed

errdisable recovery cause psecure-violation re-enables only ports dropped by port-security once the interval has passed (errdisable recovery interval, 300 seconds by default). With the old PC still in the table, the port comes back, the new PC triggers the violation again and it drops again: automatic recovery does not replace clearing the MAC.

In the ticket: port, the Last Source Address MAC and which device it belongs to, which sticky MAC was removed, the final state and that the configuration is saved. If the inventory holds the device's MAC, update it.

Next steps

Want to practise it? Solve the ticket “The desk port that switched itself off” in SysAdmin Desks, free and in your browser.

Is something missing, or different in your environment? Get in touch and I'll fix it.

Tech Career Lab · newsletter

¿Te ha servido? Cada dos semanas envío una idea práctica para perfiles IT: LinkedIn, proyectos, networking y procesos de selección.Found this useful? Every two weeks I send one practical idea for IT professionals: LinkedIn, projects, networking and hiring processes.

Apúntate y llévate las 33 ideasSign up and get the 33 ideas →