In questo documento viene descritto come usare il protocollo SNMP (Simple Network Management Protocol) per ottenere il numero di porta su uno switch Cisco Catalyst da cui si conosce l'indirizzo MAC.
Questo documento è utile per conoscere i seguenti argomenti:
Come ottenere le VLAN da uno switch Catalyst con SNMP
Come utilizzare l'indicizzazione delle stringhe della community con SNMP
Uso generale del comando get SNMP e del comando walk
Questo documento è relativo agli switch Catalyst che eseguono software Catalyst OS (CatOS) o Cisco IOS® standard. Il software supporta BRIDGE-MIB e IF-MIB.
Le informazioni fornite in questo documento si basano sulle seguenti versioni software e hardware:
Catalyst 3524XL con software Cisco IOS versione 12.0(5)WC5a
Net-SNMP versione 5.0.6
Nota: per ottenere questo software, consultare il documento Net-SNMP
.
Le informazioni discusse in questo documento fanno riferimento a dispositivi usati in uno specifico ambiente di emulazione. Su tutti i dispositivi menzionati nel documento la configurazione è stata ripristinata ai valori predefiniti. Se la rete è operativa, valutare attentamente eventuali conseguenze derivanti dall'uso dei comandi.
Per ulteriori informazioni sulle convenzioni usate, consultare il documento Cisco sulle convenzioni nei suggerimenti tecnici.
Per ulteriori informazioni su come eseguire una query sulla tabella CAM (Content-Indirissable Memory), sulle VLAN e su tutti i MIB correlati, come CISCO-VTP-MIB e BRIDGE-MIB, consultare la sezione Background del documento How To Get Dynamic CAM Entries (CAM Table) for Catalyst Switch Using SNMP.
.1.3.6.1.2.1.17.4.3.1.1
dot1dTpFdbAddress OBJECT-TYPE
-- FROM BRIDGE-MIB
-- TEXTUAL CONVENTION MacAddress
SYNTAX OCTET STRING (6)
MAX-ACCESS read-only
STATUS Mandatory
DESCRIPTION "A unicast MAC address for which the bridge has forwarding
and/or filtering information."
::= { iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1) dot1dBridge(17) dot1dTp(4)
dot1dTpFdbTable(3) dot1dTpFdbEntry(1) 1 }
.1.3.6.1.2.1.17.4.3.1.2
dot1dTpFdbPort OBJECT-TYPE
-- FROM BRIDGE-MIB
SYNTAX Integer
MAX-ACCESS read-only
STATUS Mandatory
DESCRIPTION "Either the value "0", or the port number of the port on which
a frame having a source
address equal to the value of the corresponding instance of
dot1dTpFdbAddress has been seen.
A value of "0" indicates that the port number has not been learned,
but that the bridge does
have some forwarding/filtering information about this address (that is,
in the StaticTable).
Implementors are encouraged to assign the port value to this
object whenever it is
learned, even for addresses for which the corresponding value of
dot1dTpFdbStatus is not learned(3)."
::= { iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1) dot1dBridge(17) dot1dTp(4)
dot1dTpFdbTable(3) dot1dTpFdbEntry(1) 2 }
.1.3.6.1.2.1.2.2.1.1
ifIndex OBJECT-TYPE
SYNTAX InterfaceIndex
MAX-ACCESS read-only
STATUS current
DESCRIPTION "A unique value, greater than zero, for each interface. It
is recommended that values are assigned contiguously
starting from 1. The value for each interface sub-layer
must remain constant at least from one re-initialization of
the entity's network management system to the next re-
initialization."
::= { ifEntry 1 }
.1.3.6.1.2.1.17.1.4.1.2
dot1dBasePortIfIndex OBJECT-TYPE
SYNTAX INTEGER
ACCESS read-only
STATUS mandatory
DESCRIPTION
"The value of the instance of the ifIndex object,
defined in MIB-II, for the interface corresponding
to this port."
::= { dot1dBasePortEntry 2 }
.1.3.6.1.2.1.31.1.1.1.1
ifName OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION "The textual name of the interface. The value of this
object should be the name of the interface as assigned by
the local device and should be suitable for use in commands
entered at the device's `console'. This might be a text
name, such as `le0' or a simple port number, such as `1',
depending on the interface naming syntax of the device. If
several entries in the ifTable together represent a single
interface as named by the device, then each will have the
same value of ifName. Note that for an agent which responds
to SNMP queries concerning an interface on some other
(proxied) device, then the value of ifName for such an
interface is the proxied device's local name for it.
If there is no local name, or this object is otherwise not
applicable, then this object contains a zero-length string."
::= { ifXEntry 1 }
Completare la procedura descritta in questa sezione per utilizzare il protocollo SNMP per ottenere il numero di porta su cui è stato appreso un indirizzo MAC. Tenere presente che il numero di porta è nella VLAN1.
Nota: nei comandi di questa sezione:
public è la stringa della community di lettura.
@1 è la VLAN 1 che fa parte della stringa della community di lettura.
crumpy è il nome host del dispositivo.
Nota: per questo nome host è possibile utilizzare anche l'indirizzo IP.
Nota: la sezione Conclusione utilizza i valori visualizzati in corsivo nell'output del comando.
Recuperare le VLAN. Utilizzare il comando snmpwalk sull'oggetto vtpVlanState (.1.3.6.1.4.1.9.46.1.3.1.1.2 ):
%snmpwalk -c public crumpy .1.3.6.1.4.1.9.9.46.1.3.1.1.2 CISCO-VTP-MIB::vtpVlanState.1.1 = INTEGER: operational(1) CISCO-VTP-MIB::vtpVlanState.1.3 = INTEGER: operational(1) CISCO-VTP-MIB::vtpVlanState.1.7 = INTEGER: operational(1) CISCO-VTP-MIB::vtpVlanState.1.10 = INTEGER: operational(1) ...
Nota: questo comando utilizza l'indicizzazione delle stringhe della community. Il comando utilizza anche vtpVlanState, con OID .1.3.6.1.4.1.9.46.1.3.1.1.2. Se i MIB sono stati caricati nel sistema di gestione della rete (NMS), è possibile usare il nome dell'oggetto anziché l'OID. Utilizzare questo comando:
%snmpwalk -c public@1 crumpy vtpVlanState
Nota: è anche possibile utilizzare i nomi degli oggetti nei passi da 2 a 6.
Per ottenere la tabella degli indirizzi MAC tenendo presente che la porta appartiene alla VLAN1, eseguire questo comando:
snmpwalk -c public@1 crumpy .1.3.6.1.2.1.17.4.3.1.1 17.4.3.1.1.0.0.12.7.172.8 = Hex: 00 00 0C 07 AC 08 17.4.3.1.1.0.1.2.27.80.145 = Hex: 00 01 02 1B 50 91 17.4.3.1.1.0.1.3.72.77.90 = Hex: 00 01 03 48 4D 5A 17.4.3.1.1.0.1.3.72.221.191 = Hex: 00 01 03 48 DD BF ...
Nota: fornire il numero VLAN appropriato dopo la stringa della community. nell'esempio, questo valore è VLAN1.
Il comando elenca tutti gli indirizzi MAC che sono stati appresi su tutte le porte che appartengono alla VLAN 1.
Per determinare il numero di porta del bridge per la VLAN 1, eseguire questo comando:
snmpwalk -c public@1 crumpy .1.3.6.1.2.1.17.4.3.1.2 17.4.3.1.2.0.0.12.7.172.8 = 13 17.4.3.1.2.0.1.2.27.80.128 = 13 17.4.3.1.2.0.1.2.27.80.145 = 13 17.4.3.1.2.0.1.2.163.145.225 = 13 ...
Nota: la VLAN 1 è dot1dTpFdbPort , o .1.3.6.1.2.1.17.4.3.1.2.
Utilizzare questo comando per eseguire il mapping della porta bridge a ifIndex, OID .1.3.6.1.2.1.2.2.1.1:
snmpwalk -c public@1 crumpy .1.3.6.1.2.1.17.1.4.1.2 17.1.4.1.2.13 = 2 17.1.4.1.2.14 = 3 17.1.4.1.2.15 = 4 17.1.4.1.2.16 = 5
Questo comando esegue una query su dot1dBasePortIfIndex, che dispone di OID .1.3.6.1.2.1.17.1.4.1.2.
Utilizzare il comando walk con ifName per correlare il valore ifIndex a un nome di porta corretto.
Immettere questo comando
Nota: il nome ifName ha OID .1.3.6.1.2.1.31.1.1.1.1.
snmpwalk -c public@1 crumpy .1.3.6.1.2.1.31.1.1.1.1 ifMIB.ifMIBObjects.ifXTable.ifXEntry.ifName.1 = VL1 ifMIB.ifMIBObjects.ifXTable.ifXEntry.ifName.2 = Fa0/1 ifMIB.ifMIBObjects.ifXTable.ifXEntry.ifName.3 = Fa0/2 ifMIB.ifMIBObjects.ifXTable.ifXEntry.ifName.4 = Fa0/3 ifMIB.ifMIBObjects.ifXTable.ifXEntry.ifName.5 = Fa0/4 ifMIB.ifMIBObjects.ifXTable.ifXEntry.ifName.6 = Fa0/5 ifMIB.ifMIBObjects.ifXTable.ifXEntry.ifName.7 = Fa0/6 ...
Collegare un indirizzo MAC alla porta su cui è stato appreso l'indirizzo.
Dal passo 1, l'indirizzo MAC è:
17.4.3.1.1.0.0.12.7.172.8 = Hex: 00 00 0C 07 AC 08
Dal passaggio 2, la porta bridge indica che l'indirizzo MAC appartiene alla porta bridge numero 13:
17.4.3.1.2.0.0.12.7.172.8 = 13
Dal passo 3, la porta ponte numero 13 ha ifIndex numero 2:
17.1.4.1.2.13 = 2
Dal passaggio 4, l'ifIndex 2 corrisponde alla porta Fast Ethernet 0/1:
ifMIB.ifMIBObjects.ifXTable.ifXEntry.ifName.2 = Fa0/1
L'indirizzo MAC 00 00 0C 07 AC 08 viene appreso sulla porta Fa0/1.
Confronta questa conclusione con i risultati restituiti da:
Il comando show cam dynamic per gli switch CatOS
Il comando show mac per gli switch software Cisco IOS
Di seguito è riportato l'output di esempio:
crumpy# show mac Dynamic Address Count: 58 Secure Address Count: 2 Static Address (User-defined) Count: 0 System Self Address Count: 51 Total MAC addresses: 111 Maximum MAC addresses: 8192 Non-static Address Table: Destination Address Address Type VLAN Destination Port ------------------- ------------ ---- ------------------- 0000.0c07.ac08 Dynamic 1 FastEthernet0/1 0001.021b.5091 Dynamic 1 FastEthernet0/1 0001.0348.4d5a Dynamic 1 FastEthernet0/1 0001.0348.ddbf Dynamic 1 FastEthernet0/1 0001.972d.dfae Dynamic 1 FastEthernet0/1 0002.55c6.cfe7 Dynamic 1 FastEthernet0/1 0002.7d61.d400 Dynamic 1 FastEthernet0/1 …