12
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ciscoルータのポート一覧をSNMPで取得する

Last updated at Posted at 2015-11-09

ルータやスイッチなどのネットワーク機器のポート一覧を表示する方法です。
snmpwalkコマンドを利用して、ポート一覧を表示します。
この記事ではUbuntu15.04からSNMPでCisco1812Jのポート一覧を取得します。

Ciscoルータの準備

中古のCisco1812Jに、最低限のIPアドレスとSNMPの設定をする。
SNMPのコミュニティ名はpublicで、アクセスリストの設定は省略します。

Cisco
R1#show run | sec snmp|FastEthernet0
interface FastEthernet0
 description WAN
 ip address 192.168.88.101 255.255.255.0
 duplex auto
 speed auto
ip route 0.0.0.0 0.0.0.0 FastEthernet0 192.168.88.1
snmp-server community public RO
snmp-server ifindex persist
snmp-server chassis-id R1

Ubuntu(Linux)側の準備

snmpwalkコマンドのパッケージsnmpとMIBをダウンロードするsnmp-mibs-downloaderをインストール。

Ubuntu15.04
% sudo apt-get install snmp snmp-mibs-downloader
% sudo download-mibs

CISCOのプライベートMIBは下記の設定ファイルでダウンロードできます。

/etc/snmp-mibs-downloader/cisco.conf
HOST=ftp://ftp.cisco.com
DIR=pub/mibs/v2/
CONF=ciscolist
DEST=cisco

必要なMIBを定義します。

/etc/snmp-mibs-downloader/ciscolist
CISCO-IMAGE-MIB.my CISCO-IMAGE-MIB
CISCO-SMI.my CISCO-SMI
MPLS-VPN-MIB.my MPLS-VPN-MIB
CISCO-BGP4-MIB.my CISCO-BGP4-MIB
CISCO-PING-MIB.my CISCO-PING-MIB
CISCO-TC.my CISCO-TC
CiscoのプライベートMIBをダウンロード
% sudo download-mibs cisco

snmpwalkコマンドの実行時にMIBを参照させるために設定ファイルを記述する。

/etc/snmp/snmp.conf
mibdirs /var/lib/mibs/iana:/var/lib/mibs/ietf:/var/lib/mibs/cisco
mibs all
showMibErrors no
mibWarningLevel 0
strictCommentTerm no
mibAllowUnderline no

試しにsnmpwalkを実行すると、MIBのエラーを吐く。

snmpwalk実行結果
% snmpwalk -v 2c -c public 192.168.88.101 system
Bad operator (INTEGER): At line 73 in /var/lib/mibs/ietf/SNMPv2-PDU
Unlinked OID in IPATM-IPMC-MIB: marsMIB ::= { mib-2 57 }
Undefined identifier: mib-2 near line 18 of /var/lib/mibs/ietf/IPATM-IPMC-MIB
Expected "::=" (RFC5644): At line 493 in /var/lib/mibs/iana/IANA-IPPM-METRICS-REGISTRY-MIB
Expected "{" (EOF): At line 651 in /var/lib/mibs/iana/IANA-IPPM-METRICS-REGISTRY-MIB
Bad object identifier: At line 651 in /var/lib/mibs/iana/IANA-IPPM-METRICS-REGISTRY-MIB
Bad parse of OBJECT-IDENTITY: At line 651 in /var/lib/mibs/iana/IANA-IPPM-METRICS-REGISTRY-MIB
SNMPv2-MIB::sysDescr.0 = STRING: Cisco IOS Software, C181X Software (C181X-ADVENTERPRISEK9-M), Version 15.1(4)M4, RELEASE SOFTWARE (fc1)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2012 by Cisco Systems, Inc.
Compiled Tue 20-Mar-12 23:34 by prod_rel_team
SNMPv2-MIB::sysObjectID.0 = OID: CISCO-SMI::ciscoProducts.642
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (22380) 0:03:43.80
SNMPv2-MIB::sysContact.0 = STRING: 
SNMPv2-MIB::sysName.0 = STRING: R1.cisco.com
SNMPv2-MIB::sysLocation.0 = STRING: 
SNMPv2-MIB::sysServices.0 = INTEGER: 78
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (0) 0:00:00.00

エラーを吐くMIBは不要なので場当たり的に削除する。

sudo rm /var/lib/mibs/ietf/SNMPv2-PDU
sudo rm /var/lib/mibs/ietf/IPATM-IPMC-MIB
sudo rm /var/lib/mibs/iana/IANA-IPPM-METRICS-REGISTRY-MIB

不要なMIBの削除後はエラーが消えました。これで準備が完了。

snmpwalk実行結果
% snmpwalk -v 2c -c public 192.168.88.101 system
SNMPv2-MIB::sysDescr.0 = STRING: Cisco IOS Software, C181X Software (C181X-ADVENTERPRISEK9-M), Version 15.1(4)M4, RELEASE SOFTWARE (fc1)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2012 by Cisco Systems, Inc.
Compiled Tue 20-Mar-12 23:34 by prod_rel_team
SNMPv2-MIB::sysObjectID.0 = OID: CISCO-SMI::ciscoProducts.642
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (54935) 0:09:09.35
SNMPv2-MIB::sysContact.0 = STRING: 
SNMPv2-MIB::sysName.0 = STRING: R1.cisco.com
SNMPv2-MIB::sysLocation.0 = STRING: 
SNMPv2-MIB::sysServices.0 = INTEGER: 78
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (0) 0:00:00.00

SNMPのOID

SNMPでポート一覧を表示するMIBのObjectID(OID)です。
詳細はCisco SNMP オブジェクトナビゲータで確認することができます。

  • ポートの名前
    • ifDescr(1.3.6.1.2.1.2.2.1.2):インタフェース名(FastEthernet0)
    • ifName(1.3.6.1.2.1.31.1.1.1.1:インタフェース名(上記の省略形、Fa0)
    • ifAlias(1.3.6.1.2.1.31.1.1.1.18):Ciscoルータの場合、descriptionの文字列を取得できる
  • ポートの状態
    • ifAdminStatus(1.3.6.1.2.1.2.2.1.7):設定の状態(shutdown / no shutdown)
    • ifOperStatus(1.3.6.1.2.1.2.2.1.8):現在の状態(LinkDown / LinkUp)

SNMP実行例

インタフェース名の一覧

ifDescr(1.3.6.1.2.1.2.2.1.2):インタフェース名(FastEthernet0)

snmpwalk実行結果
% snmpwalk -v 2c -c public 192.168.88.101 ifDescr
IF-MIB::ifDescr.1 = STRING: FastEthernet0
IF-MIB::ifDescr.2 = STRING: FastEthernet1
IF-MIB::ifDescr.3 = STRING: BRI0
IF-MIB::ifDescr.4 = STRING: BRI0:1
IF-MIB::ifDescr.5 = STRING: BRI0:2
IF-MIB::ifDescr.6 = STRING: FastEthernet2
IF-MIB::ifDescr.7 = STRING: FastEthernet3
IF-MIB::ifDescr.8 = STRING: FastEthernet4
IF-MIB::ifDescr.9 = STRING: FastEthernet5
IF-MIB::ifDescr.10 = STRING: FastEthernet6
IF-MIB::ifDescr.11 = STRING: FastEthernet7
IF-MIB::ifDescr.12 = STRING: FastEthernet8
IF-MIB::ifDescr.13 = STRING: FastEthernet9
IF-MIB::ifDescr.14 = STRING: Null0
IF-MIB::ifDescr.15 = STRING: Vlan1
IF-MIB::ifDescr.16 = STRING: BRI0-Physical
IF-MIB::ifDescr.17 = STRING: BRI0-Signaling
IF-MIB::ifDescr.18 = STRING: BRI0:1-Bearer Channel
IF-MIB::ifDescr.19 = STRING: BRI0:2-Bearer Channel

インタフェース名(省略形)の一覧

ifName(1.3.6.1.2.1.31.1.1.1.1:インタフェース名(上記の省略形、Fa0)

snmpwalk実行結果
% snmpwalk -v 2c -c public 192.168.88.101 ifName
IF-MIB::ifName.1 = STRING: Fa0
IF-MIB::ifName.2 = STRING: Fa1
IF-MIB::ifName.3 = STRING: BR0
IF-MIB::ifName.4 = STRING: BR0:1
IF-MIB::ifName.5 = STRING: BR0:2
IF-MIB::ifName.6 = STRING: Fa2
IF-MIB::ifName.7 = STRING: Fa3
IF-MIB::ifName.8 = STRING: Fa4
IF-MIB::ifName.9 = STRING: Fa5
IF-MIB::ifName.10 = STRING: Fa6
IF-MIB::ifName.11 = STRING: Fa7
IF-MIB::ifName.12 = STRING: Fa8
IF-MIB::ifName.13 = STRING: Fa9
IF-MIB::ifName.14 = STRING: Nu0
IF-MIB::ifName.15 = STRING: Vl1
IF-MIB::ifName.16 = STRING: BR0
IF-MIB::ifName.17 = STRING: BR0
IF-MIB::ifName.18 = STRING: BR0:1
IF-MIB::ifName.19 = STRING: BR0:2

descriptionの一覧

ifAlias(1.3.6.1.2.1.31.1.1.1.18):Ciscoルータの場合、descriptionの文字列を取得できる

snmpwalk実行結果
% snmpwalk -v 2c -c public 192.168.88.101 ifAlias
IF-MIB::ifAlias.1 = STRING: WAN
IF-MIB::ifAlias.2 = STRING: LAN
IF-MIB::ifAlias.3 = STRING: 
IF-MIB::ifAlias.4 = STRING: 
IF-MIB::ifAlias.5 = STRING: 
IF-MIB::ifAlias.6 = STRING: SW1
IF-MIB::ifAlias.7 = STRING: SW2
IF-MIB::ifAlias.8 = STRING: 
IF-MIB::ifAlias.9 = STRING: 
IF-MIB::ifAlias.10 = STRING: 
IF-MIB::ifAlias.11 = STRING: 
IF-MIB::ifAlias.12 = STRING: 
IF-MIB::ifAlias.13 = STRING: 
IF-MIB::ifAlias.14 = STRING: 
IF-MIB::ifAlias.15 = STRING: 
IF-MIB::ifAlias.16 = STRING: 
IF-MIB::ifAlias.17 = STRING: 
IF-MIB::ifAlias.18 = STRING: 
IF-MIB::ifAlias.19 = STRING: 

インタフェースの設定状態一覧

ifAdminStatus(1.3.6.1.2.1.2.2.1.7):設定の状態(shutdown / no shutdown)

snmpwalk実行結果
% snmpwalk -v 2c -c public 192.168.88.101 ifAdminStatus
IF-MIB::ifAdminStatus.1 = INTEGER: up(1)
IF-MIB::ifAdminStatus.2 = INTEGER: down(2)
IF-MIB::ifAdminStatus.3 = INTEGER: down(2)
IF-MIB::ifAdminStatus.4 = INTEGER: down(2)
IF-MIB::ifAdminStatus.5 = INTEGER: down(2)
IF-MIB::ifAdminStatus.6 = INTEGER: up(1)
IF-MIB::ifAdminStatus.7 = INTEGER: up(1)
IF-MIB::ifAdminStatus.8 = INTEGER: up(1)
IF-MIB::ifAdminStatus.9 = INTEGER: up(1)
IF-MIB::ifAdminStatus.10 = INTEGER: up(1)
IF-MIB::ifAdminStatus.11 = INTEGER: up(1)
IF-MIB::ifAdminStatus.12 = INTEGER: up(1)
IF-MIB::ifAdminStatus.13 = INTEGER: up(1)
IF-MIB::ifAdminStatus.14 = INTEGER: up(1)
IF-MIB::ifAdminStatus.15 = INTEGER: up(1)
IF-MIB::ifAdminStatus.16 = INTEGER: down(2)
IF-MIB::ifAdminStatus.17 = INTEGER: down(2)
IF-MIB::ifAdminStatus.18 = INTEGER: down(2)
IF-MIB::ifAdminStatus.19 = INTEGER: down(2)

インタフェースの現在の状態一覧

ifOperStatus(1.3.6.1.2.1.2.2.1.8):現在の状態(LinkDown / LinkUp)

snmpwalk実行結果
% snmpwalk -v 2c -c public 192.168.88.101 ifOperStatus
IF-MIB::ifOperStatus.1 = INTEGER: up(1)
IF-MIB::ifOperStatus.2 = INTEGER: down(2)
IF-MIB::ifOperStatus.3 = INTEGER: down(2)
IF-MIB::ifOperStatus.4 = INTEGER: down(2)
IF-MIB::ifOperStatus.5 = INTEGER: down(2)
IF-MIB::ifOperStatus.6 = INTEGER: down(2)
IF-MIB::ifOperStatus.7 = INTEGER: down(2)
IF-MIB::ifOperStatus.8 = INTEGER: down(2)
IF-MIB::ifOperStatus.9 = INTEGER: down(2)
IF-MIB::ifOperStatus.10 = INTEGER: down(2)
IF-MIB::ifOperStatus.11 = INTEGER: down(2)
IF-MIB::ifOperStatus.12 = INTEGER: down(2)
IF-MIB::ifOperStatus.13 = INTEGER: down(2)
IF-MIB::ifOperStatus.14 = INTEGER: up(1)
IF-MIB::ifOperStatus.15 = INTEGER: down(2)
IF-MIB::ifOperStatus.16 = INTEGER: down(2)
IF-MIB::ifOperStatus.17 = INTEGER: down(2)
IF-MIB::ifOperStatus.18 = INTEGER: down(2)
IF-MIB::ifOperStatus.19 = INTEGER: down(2)
12
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?