Cómo instalar y usar snmpwalk
Hola amigas y amigos, en el artículo de hoy vamos a hablar de la herramienta Snmpwalk. Con ella podemos enumerar fácilmente todos los OID que un host, con el servicio SNMP activo, tiene pare ofrecer. Para más tarde poder filtrar los resultados según nuestras necesidades y encontrar los OID para utilizar, en plataformas como Cacti.
Instalación y algunos ejemplos de Snmpwalk
Snmpwalk se encuentra en la mayoría de los repositorios de GNU/Linux.
Veamos algunos ejemplos:
En sistemas RPM como RHEL o Centos:
1 | yum install net-snmp-utils |
En sistemas DEB como Debian o Ubuntu
1 | apt install snmp |
La sintaxis para utilizar snmpwalk es simple y amplia:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | # snmpwalk --help USAGE: snmpwalk [OPTIONS] AGENT [OID] Version: 5.7.2 Web: http://www.net-snmp.org/ Email: net-snmp-coders@lists.sourceforge.net OPTIONS: -h, --help display this help message -H display configuration file directives understood -v 1|2c|3 specifies SNMP version to use -V, --version display package version number SNMP Version 1 or 2c specific -c COMMUNITY set the community string SNMP Version 3 specific -a PROTOCOL set authentication protocol (MD5|SHA) -A PASSPHRASE set authentication protocol pass phrase -e ENGINE-ID set security engine ID (e.g. 800000020109840301) -E ENGINE-ID set context engine ID (e.g. 800000020109840301) -l LEVEL set security level (noAuthNoPriv|authNoPriv|authPriv) -n CONTEXT set context name (e.g. bridge1) -u USER-NAME set security name (e.g. bert) -x PROTOCOL set privacy protocol (DES|AES) -X PASSPHRASE set privacy protocol pass phrase -Z BOOTS,TIME set destination engine boots/time General communication options -r RETRIES set the number of retries -t TIMEOUT set the request timeout (in seconds) Debugging -d dump input/output packets in hexadecimal -D[TOKEN[,...]] turn on debugging output for the specified TOKENs (ALL gives extremely verbose debugging output) |
Podemos encontrar la información de la página de man.
Vamos a ver la información mostrada de un servidor virtual con Centos 7, para ello debemos utilizar la versión de snmp, que debe ser la versión 2, además de la comunidad que tengamos configurada en el host.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | [root@servcentos1 ~]# snmpwalk -v 2c -c public localhost SNMPv2-MIB::sysDescr.0 = STRING: Linux servcentos1 3.10.0-862.14.4.el7.x86_64 #1 SMP Wed Sep 26 15:12:11 UTC 2018 x86_64 SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10 DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (1124) 0:00:11.24 SNMPv2-MIB::sysContact.0 = STRING: Root <root@localhost> (configure /etc/snmp/snmp.local.conf) SNMPv2-MIB::sysName.0 = STRING: servcentos1 SNMPv2-MIB::sysLocation.0 = STRING: Unknown (edit /etc/snmp/snmpd.conf) SNMPv2-MIB::sysORLastChange.0 = Timeticks: (25) 0:00:00.25 SNMPv2-MIB::sysORID.1 = OID: SNMP-MPD-MIB::snmpMPDCompliance SNMPv2-MIB::sysORID.2 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance SNMPv2-MIB::sysORID.3 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance SNMPv2-MIB::sysORID.4 = OID: SNMPv2-MIB::snmpMIB SNMPv2-MIB::sysORID.5 = OID: TCP-MIB::tcpMIB SNMPv2-MIB::sysORID.6 = OID: IP-MIB::ip SNMPv2-MIB::sysORID.7 = OID: UDP-MIB::udpMIB SNMPv2-MIB::sysORID.8 = OID: SNMP-VIEW-BASED-ACM-MIB::vacmBasicGroup SNMPv2-MIB::sysORID.9 = OID: SNMP-NOTIFICATION-MIB::snmpNotifyFullCompliance SNMPv2-MIB::sysORID.10 = OID: NOTIFICATION-LOG-MIB::notificationLogMIB SNMPv2-MIB::sysORDescr.1 = STRING: The MIB for Message Processing and Dispatching. SNMPv2-MIB::sysORDescr.2 = STRING: The management information definitions for the SNMP User-based Security Model. SNMPv2-MIB::sysORDescr.3 = STRING: The SNMP Management Architecture MIB. SNMPv2-MIB::sysORDescr.4 = STRING: The MIB module for SNMPv2 entities SNMPv2-MIB::sysORDescr.5 = STRING: The MIB module for managing TCP implementations SNMPv2-MIB::sysORDescr.6 = STRING: The MIB module for managing IP and ICMP implementations SNMPv2-MIB::sysORDescr.7 = STRING: The MIB module for managing UDP implementations SNMPv2-MIB::sysORDescr.8 = STRING: View-based Access Control Model for SNMP. SNMPv2-MIB::sysORDescr.9 = STRING: The MIB modules for managing SNMP Notification, plus filtering. SNMPv2-MIB::sysORDescr.10 = STRING: The MIB module for logging SNMP Notifications. SNMPv2-MIB::sysORUpTime.1 = Timeticks: (25) 0:00:00.25 SNMPv2-MIB::sysORUpTime.2 = Timeticks: (25) 0:00:00.25 SNMPv2-MIB::sysORUpTime.3 = Timeticks: (25) 0:00:00.25 SNMPv2-MIB::sysORUpTime.4 = Timeticks: (25) 0:00:00.25 SNMPv2-MIB::sysORUpTime.5 = Timeticks: (25) 0:00:00.25 SNMPv2-MIB::sysORUpTime.6 = Timeticks: (25) 0:00:00.25 SNMPv2-MIB::sysORUpTime.7 = Timeticks: (25) 0:00:00.25 SNMPv2-MIB::sysORUpTime.8 = Timeticks: (25) 0:00:00.25 SNMPv2-MIB::sysORUpTime.9 = Timeticks: (25) 0:00:00.25 SNMPv2-MIB::sysORUpTime.10 = Timeticks: (25) 0:00:00.25 HOST-RESOURCES-MIB::hrSystemUptime.0 = Timeticks: (19721) 0:03:17.21 HOST-RESOURCES-MIB::hrSystemUptime.0 = No more variables left in this MIB View (It is past the end of the MIB tree) |
Para ver únicamente la información de un solo OID
1 2 3 4 5 6 | [root@servcentos1 ~]# snmpwalk -v 2c -c public localhost SNMPv2-MIB::sysLocation.0 SNMPv2-MIB::sysLocation.0 = STRING: Barcelona [root@servcentos1 ~]# snmpwalk -v 2c -c public localhost SNMPv2-MIB::sysName.0 SNMPv2-MIB::sysName.0 = STRING: servcentos1 [root@servcentos1 ~]# snmpwalk -v 2c -c public localhost SNMPv2-MIB::sysContact.0 SNMPv2-MIB::sysContact.0 = STRING: davidochobits@colaboratorio.net |
Si queremos ver el OID numérico por cada valor SNMP, usamos el parámetro “-O n”, muy útil para Cacti, ya que solo nos devuelve el valor OID numérico.
1 2 3 4 5 6 | [root@servcentos1 ~]# snmpwalk -v 2c -O n -c public localhost SNMPv2-MIB::sysLocation.0 .1.3.6.1.2.1.1.6.0 = STRING: Barcelona [root@servcentos1 ~]# snmpwalk -v 2c -O n -c public localhost SNMPv2-MIB::sysName.0 .1.3.6.1.2.1.1.5.0 = STRING: servcentos1 [root@servcentos1 ~]# snmpwalk -v 2c -O n -c public localhost SNMPv2-MIB::sysContact.0 .1.3.6.1.2.1.1.4.0 = STRING: davidochobits@colaboratorio.net |
También podemos utilizar el valor OID para refinar los resultados.
1 2 3 4 5 6 | [root@servcentos1 ~]# snmpwalk -v 2c -O n -c public localhost .1.3.6.1.2.1.1.6.0 .1.3.6.1.2.1.1.6.0 = STRING: Barcelona [root@servcentos1 ~]# snmpwalk -v 2c -O n -c public localhost .1.3.6.1.2.1.1.5.0 .1.3.6.1.2.1.1.5.0 = STRING: servcentos1 [root@servcentos1 ~]# snmpwalk -v 2c -O n -c public localhost .1.3.6.1.2.1.1.4.0 .1.3.6.1.2.1.1.4.0 = STRING: davidochobits@colaboratorio.ne |
Como hemos visto, con esta herramienta podemos obtener la información SNMP deseada, para así crear gráficas en Cacti para que nos muestre la información deseada.
M00nie.com – How to install and use snmpwalk