本文說明如何使用簡單網路管理通訊協定(SNMP)清除路由器中的單一位址解析通訊協定(ARP)專案。
本文件沒有特定需求。
本檔案中的資訊是根據支援執行Cisco IOS®軟體的RFC1213MIB的所有裝置而編寫的。
本文中的資訊是根據特定實驗室環境內的裝置所建立。文中使用到的所有裝置皆從已清除(預設)的組態來啟動。如果您的網路正在作用,請確保您已瞭解任何指令可能造成的影響。
如需文件慣例的詳細資訊,請參閱思科技術提示慣例。
沒有用於清除單個ARP表條目的Cisco IOS軟體命令。Cisco IOS軟體clear arp-cache命令清除整個表。
您可以將SNMP用於RFC1213 MIB中tableipNetToMediaTable(.1.3.6.1.2.1.4.22.22)內的MIB對象ipNetToMediaType(.1.3.6.1.2.1.4.4)。
.1.3.6.1.2.1.4.22 ipNetToMediaTable OBJECT-TYPE -- FROM RFC1213-MIB DESCRIPTION "The IP Address Translation table used for mapping from IP addresses to physical addresses." ::= { iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1) ip(4) 22 } .1.3.6.1.2.1.4.22.1.4 ipNetToMediaType OBJECT-TYPE -- FROM RFC1213-MIB SYNTAX Integer { other(1), invalid(2), dynamic(3), static(4) } MAX-ACCESS read-create STATUS Current DESCRIPTION "The type of mapping. Setting this object to the value invalid(2) has the effect of invalidating the corresponding entry in the ipNetToMediaTable. That is, it effectively disassociates the interface identified with said entry from the mapping identified with said entry. It is an implementation-specific matter as to whether the agent removes an invalidated entry from the table. Accordingly, management stations must be prepared to receive tabular information from agents that corresponds to entries not currently in use. Proper interpretation of such entries requires examination of the relevant ipNetToMediaType object." ::= { iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1) ip(4) ipNetToMediaTable(22) ipNetToMediaEntry(1) 4 }
將MIB對象ipNetToMediaType(.1.3.6.1.2.1.4.22.1.4)運行並設定為invalid=2時,可以刪除單個ARP條目。
註:請確保在路由器上設定SNMP唯讀(RO)/讀取/寫入(RW)社群字串。
以下是在路由器上MIB對象ipNetToMediaType的snmpwalk輸出:
snmpwalk 172.16.99.1 public .1.3.6.1.2.1.4.22.1.4 ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType.1.172.16.98.1 = other(1) ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType.1.172.16.98.2 = dynamic(3) ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType.2.172.16.98.36 = dynamic(3) ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType.2.172.16.98.37 = other(1) ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType.3.172.16.97.1 = other(1) ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType.3.172.16.97.101 = other(1) ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType.3.172.16.97.254 = dynamic(3) ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType.4.172.16.98.41 = dynamic(3) ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType.4.172.16.98.45 = other(1) ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType.7.172.16.96.1 = other(1) --<snip>--
當您對一個ARP條目執行snmpset時,例如:
ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType.1.172.16.98.2 = dynamic(3)
並根據MIB定義將其值設定為2=無效:
snmpset 172.16.99.1 private ipNetToMediaType.1.172.16.98.2 i 2 ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType.1.172.16.98.2 = invalid(2)
如果在路由器上執行另一個snmpwalk的MIB對象ipNetToMediaType,則會看到以下輸出:
snmpwalk 172.16.99.1 public .1.3.6.1.2.1.4.22.1.4 ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType.1.172.16.98.1 = other(1) ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType.2.172.16.98.36 = dynamic(3) ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType.2.172.16.98.37 = other(1) ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType.3.172.16.97.1 = other(1) ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType.3.172.16.97.101 = other(1) ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType.3.172.16.97.254 = dynamic(3) ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType.4.172.16.98.41 = dynamic(3) ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType.4.172.16.98.45 = other(1) ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType.7.172.16.96.1 = other(1) ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType.7.172.16.96.31 = dynamic(3) ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType.7.172.16.96.40 = dynamic(3) --<snip>--
目標輸出不再位於輸出中。
ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType.1.172.16.98.2 = dynamic(3)
以下是對上述變數的解釋:
172.16.99.1 =本示例中使用的路由器的IP地址。
private = RW SNMP路由器的社群字串
public = RO SNMP路由器的社群字串
.1.3.6.1.2.1.4.22.1.4= MIB對象ipNetToMediaType的對象ID(OID)
i = MIB中定義的SYNTAX的整數
2(無效)= MIB對象的值