Objectifs de certification

CCNA 200-301

  • 5.7 Configurer les fonctionnalités de sécurité Layer 2 (DHCP snooping, dynamic ARP inspection, et port security)


Lab Switchport Port-Security (Sécurité sur les ports) Cisco en IOS

On trouvera ici un lab démonstration de la fonction port-security qui permet de contrôler les adresses MAC autorisées sur un port de commutateur Cisco.

1. Topologie de base

Topologie de lab Switchport Port-Security (Sécurité sur les ports) Cisco en IOS

Dans cette topologie deux stations de travail accèdent de manière concurrente au même port du commutateur Gi0/1.

Switch#show mac address-table
          Mac Address Table
-------------------------------------------

Vlan    Mac Address       Type        Ports
----    -----------       --------    -----
   1    0000.0000.0001    DYNAMIC     Gi0/1
   1    0000.0000.0002    DYNAMIC     Gi0/1
   1    5254.0076.3d0e    DYNAMIC     Gi0/0
   1    ce6a.b50a.eb03    DYNAMIC     Gi0/0
Total Mac Addresses for this criterion: 4

Par défaut, Switchport Port-Security est désactivé.

Si la fonction est simplement activée, par défaut :

  • Une seule adresse MAC apprise dynamiquement
  • En cas de “violation”, le port tombe en mode shutdown

2. Rappel des commandes de diagnostic port-security

#show port-security
#show port-security address
#show port-security interface G0/1
#show running-config
#clear port-security {all | configured | dynamic | sticky}

3. Activation de port-security

(config)#interface G0/1
(config-if)#switchport mode access
(config-if)#switchport port-security

Dans le contexte de la démonstration, le port Gi0/1 tombe.

*Jul  1 17:27:03.944: %PM-4-ERR_DISABLE: psecure-violation error detected on Gi0/1, putting Gi0/1 in err-disable state

4. Diagnostic d’un port port-security shutdown

Le port Gi0/1 est bien en statut “err-disabled”.

Switch#show interfaces status | include Gi0/1
Gi0/1                        err-disabled 1            auto   auto RJ45
Switch#show port-security
Secure Port  MaxSecureAddr  CurrentAddr  SecurityViolation  Security Action
                (Count)       (Count)          (Count)
---------------------------------------------------------------------------
      Gi0/1              1            0                  1         Shutdown
---------------------------------------------------------------------------
Total Addresses in System (excluding one mac per port)     : 0
Max Addresses limit in System (excluding one mac per port) : 4096
Switch#show port-security interface G0/1
Port Security              : Enabled
Port Status                : Secure-shutdown
Violation Mode             : Shutdown
Aging Time                 : 0 mins
Aging Type                 : Absolute
SecureStatic Address Aging : Disabled
Maximum MAC Addresses      : 1
Total MAC Addresses        : 0
Configured MAC Addresses   : 0
Sticky MAC Addresses       : 0
Last Source Address:Vlan   : 0000.0000.0002:1
Security Violation Count   : 1

5. Réactivation du port

Nous allons désactiver l’hôte autorisé et remonter le port qui est tombé.

Switch(config)#int g0/1
Switch(config-if)#shut
Switch(config-if)#no shut
Switch(config-if)#
*Jul  1 17:35:34.104: %LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to administratively down
*Jul  1 17:35:36.188: %LINK-3-UPDOWN: Interface GigabitEthernet0/1, changed state to up
*Jul  1 17:35:37.188: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1, changed state to up

Switch#show port-security
Secure Port  MaxSecureAddr  CurrentAddr  SecurityViolation  Security Action
                (Count)       (Count)          (Count)
---------------------------------------------------------------------------
      Gi0/1              1            1                  0         Shutdown
---------------------------------------------------------------------------
Total Addresses in System (excluding one mac per port)     : 0
Max Addresses limit in System (excluding one mac per port) : 4096

Le second hôte devient alors le seul autorisé.

Switch#show port-security address
               Secure Mac Address Table
-----------------------------------------------------------------------------
Vlan    Mac Address       Type                          Ports   Remaining Age
                                                                   (mins)
----    -----------       ----                          -----   -------------
   1    0000.0000.0002    SecureDynamic                 Gi0/1        -
-----------------------------------------------------------------------------
Total Addresses in System (excluding one mac per port)     : 0
Max Addresses limit in System (excluding one mac per port) : 4096

6. Fixer automatiquement une adresse MAC

On peut fixer automatiquement une adresse MAC autorisée avec la fonction “Sticky” qui enregistre l’adresse en dur dans la configuration courante.

Pour enregistrer l’adresse du premier hêtre, désactiver le second hôte, réactiver le premier hôte et fixer son adresse MAC.

Switch#show port-security address
               Secure Mac Address Table
-----------------------------------------------------------------------------
Vlan    Mac Address       Type                          Ports   Remaining Age
                                                                   (mins)
----    -----------       ----                          -----   -------------
   1    0000.0000.0001    SecureDynamic                 Gi0/1        -
-----------------------------------------------------------------------------
Total Addresses in System (excluding one mac per port)     : 0
Max Addresses limit in System (excluding one mac per port) : 4096
Switch(config)#int g0/1
Switch(config-if)#switchport port-security mac-address sticky
Switch(config-if)#^Z

Switch#show port-security address
               Secure Mac Address Table
-----------------------------------------------------------------------------
Vlan    Mac Address       Type                          Ports   Remaining Age
                                                                   (mins)
----    -----------       ----                          -----   -------------
   1    0000.0000.0001    SecureSticky                  Gi0/1        -
-----------------------------------------------------------------------------
Total Addresses in System (excluding one mac per port)     : 0
Max Addresses limit in System (excluding one mac per port) : 4096

7. Changer de mode de “violation”

Une “Violation” est une action prise en cas de non-respect d’une règle port-security.

(config-if)#switchport port-security violation {protect | restrict | shutdown}
  • Mode protect : dès que la “violation” est constatée, le port arrête de transférer le trafic des adresses non autorisées sans envoyer de message de log.
  • Mode restrict : dès que la “violation” est constatée, le port arrête de transférer le trafic des adresses non autorisées et transmet un message de log.
  • Mode shutdown : dès que la “violation” est constatée, le port passe en état err-disabled (shutdown) et un message de log est envoyé.

Pour passer en mode “restrict” :

Switch(config)#int g0/1
Switch(config-if)#switchport port-security violation restrict
Switch#show port-security
Secure Port  MaxSecureAddr  CurrentAddr  SecurityViolation  Security Action
                (Count)       (Count)          (Count)
---------------------------------------------------------------------------
      Gi0/1              1            1                  0         Restrict
---------------------------------------------------------------------------
Total Addresses in System (excluding one mac per port)     : 0
Max Addresses limit in System (excluding one mac per port) : 4096

Réactiver le second hôte.

*Jul  1 17:47:43.435: %PORT_SECURITY-2-PSECURE_VIOLATION: Security violation occurred, caused by MAC address 0000.0000.0002 on port GigabitEthernet0/1.
Switch#show interfaces status | include Gi0/1
Gi0/1                        connected    1          a-full   auto RJ45
Switch#show port-security
Secure Port  MaxSecureAddr  CurrentAddr  SecurityViolation  Security Action
                (Count)       (Count)          (Count)
---------------------------------------------------------------------------
      Gi0/1              1            1                 39         Restrict
---------------------------------------------------------------------------
Total Addresses in System (excluding one mac per port)     : 0
Max Addresses limit in System (excluding one mac per port) : 4096