本文說明如何使用簡單網路管理通訊協定(SNMP)來取得您知道MAC位址的Cisco Catalyst交換器上的連線埠號碼。
本文檔的讀者應瞭解以下主題:
如何使用SNMP從Catalyst交換器取得VLAN
如何在SNMP中使用社群字串索引
SNMP get命令和walk命令的一般用法
本檔案適用於執行常規Catalyst OS(CatOS)或Cisco IOS®軟體的Catalyst交換器。軟體支援BRIDGE-MIB和IF-MIB。
本文中的資訊係根據以下軟體和硬體版本:
執行Cisco IOS軟體版本12.0(5)WC5a的Catalyst 3524XL
Net-SNMP 5.0.6版
注意:要獲取此軟體,請參閱Net-SNMP 。
本文中的資訊是根據特定實驗室環境內的裝置所建立。文中使用到的所有裝置皆從已清除(預設)的組態來啟動。如果您的網路正在作用,請確保您已瞭解任何指令可能造成的影響。
如需文件慣例的詳細資訊,請參閱思科技術提示慣例。
有關如何查詢內容可定址記憶體(CAM)表、VLAN和所有相關MIB(例如CISCO-VTP-MIB和BRIDGE-MIB)的更多資訊,請參閱如何使用SNMP為Catalyst交換器取得動態CAM專案(CAM表)的背景一節。
.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 }
完成本節中的步驟,以便使用SNMP取得已識別MAC位址的連線埠號碼。假設連線埠號位於VLAN1中。
注意:在本節中的命令中:
public是讀取的社群字串。
@1 是讀取社群字串的VLAN 1部分。
crumpy 是裝置主機名。
注意:您還可以將此主機名的IP地址用於此主機。
註:結論部分使用命令輸出中以斜體顯示的值。
擷取VLAN。對vtpVlanState對象(.1.3.6.1.4.1.9.9.46.1.3.1.1.2)使用snmpwalk命令:
%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) ...
注意:此命令使用社群字串索引。此命令還使用vtpVlanState,該狀態包含OID .1.3.6.1.4.1.9.9.46.1.3.1.1.2。如果已經將MIB載入到網路管理系統(NMS)中,則可以使用對象名稱而不是OID。請改為發出以下命令:
%snmpwalk -c public@1 crumpy vtpVlanState
注意:也可以在步驟2至6中使用對象名稱。
核發此命令,以便考慮到連線埠屬於VLAN1,而取得MAC位址表:
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 ...
注意:在團體字串後提供適當的VLAN編號。在本範例中,它是VLAN1。
此命令列出所有屬於VLAN 1的埠上獲知的所有MAC地址。
發出此命令以確定VLAN 1的網橋埠號:
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 ...
註:VLAN 1是dot1dTpFdbPort 或.1.3.6.1.2.1.17.4.3.1.2。
發出此命令,將網橋埠對映到IfIndex,OID .1.3.6.1.2.1.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
此命令查詢dot1dBasePortIfIndex,該索引具有OID .1.3.6.1.2.1.17.1.4.1.2。
將walk命令與ifName一起使用,以便將ifIndex值與正確的埠名稱相關聯。
發出以下命令:
註: IfName具有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 ...
將MAC位址連結到獲知位址的連線埠。
在步驟1中,MAC地址為:
17.4.3.1.1.0.0.12.7.172.8 = Hex: 00 00 0C 07 AC 08
在步驟2中,網橋埠告知MAC地址屬於網橋埠號13:
17.4.3.1.2.0.0.12.7.172.8 = 13
在步驟3中,網橋埠號13的ifIndex編號為2:
17.1.4.1.2.13 = 2
在步驟4中,ifIndex 2對應於連線埠Fast Ethernet 0/1:
ifMIB.ifMIBObjects.ifXTable.ifXEntry.ifName.2 = Fa0/1
在埠Fa0/1上獲取MAC地址00 00 0C 07 AC 08。
將此結論與以下輸出進行比較:
適用於CatOS交換器的show cam dynamic命令
適用於Cisco IOS軟體交換器的show mac命令
以下是輸出範例:
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 …