SNMP (Simple Network Management Protocol) ist der Standard für Netzwerk-Monitoring. Es ermöglicht die Abfrage von Systemdaten wie CPU, RAM, Netzwerk und Festplatten.
Grundlagen
SNMP-Versionen
| Version | Sicherheit | Verwendung | |---------|------------|------------| | SNMPv1 | Keine | Legacy | | SNMPv2c | Community String | Weit verbreitet | | SNMPv3 | Authentifizierung, Verschlüsselung | Empfohlen |
Komponenten
Manager: Überwachungssystem (Nagios, Zabbix, etc.)
Agent: Läuft auf überwachtem Gerät
MIB: Management Information Base (Datenstruktur)
OID: Object Identifier (eindeutige Kennung)Wichtige OIDs
.1.3.6.1.2.1.1.1.0 System Description
.1.3.6.1.2.1.1.3.0 System Uptime
.1.3.6.1.2.1.1.5.0 System Name
.1.3.6.1.4.1.2021.10.1 CPU Load
.1.3.6.1.4.1.2021.4 Memory
.1.3.6.1.2.1.25.2 Storage
.1.3.6.1.2.1.2.2 Network InterfacesAgent installieren
Debian/Ubuntu
apt update
apt install snmpd snmpCentOS/RHEL
dnf install net-snmp net-snmp-utilsService aktivieren
systemctl enable --now snmpdSNMPv2c konfigurieren
Basis-Konfiguration
# /etc/snmp/snmpd.conf
# System-Informationen
sysLocation Rechenzentrum Frankfurt
sysContact admin@example.com
sysName server01.example.com
# Community (Passwort)
rocommunity public localhost
rocommunity monitoring 192.168.1.0/24
# Zugriff von Monitoring-Server
rocommunity geheim 192.168.1.100
# Erweiterte Daten
view all included .1
rouser monitoring priv -V allSicherere Konfiguration
# /etc/snmp/snmpd.conf
# Nur von bestimmten IPs
agentAddress udp:161
# Sicherere Community
rocommunity SicheresGeheimnis 192.168.1.100
rocommunity SicheresGeheimnis 192.168.1.101
# System-Info
sysLocation "Rack 5, RZ Frankfurt"
sysContact "NOC <noc@example.com>"
sysName "web01.example.com"
# Erweiterte Metriken
includeAllDisks 10%Service neu starten
systemctl restart snmpdSNMPv3 konfigurieren
Benutzer erstellen
# Service stoppen
systemctl stop snmpd
# Benutzer erstellen
net-snmp-config --create-snmpv3-user -ro -a SHA -A "authpassword" -x AES -X "privpassword" monitoringKonfiguration
# /etc/snmp/snmpd.conf
# SNMPv3 Benutzer
rouser monitoring priv
# View definieren
view all included .1
# Zugriff
access monitoring "" any priv exact all none noneService starten
systemctl start snmpdAbfragen durchführen
SNMPv2c
# Einzelner Wert
snmpget -v2c -c public localhost .1.3.6.1.2.1.1.1.0
# System-Beschreibung lesbar
snmpget -v2c -c public localhost sysDescr.0
# Walk (alle Werte eines Zweigs)
snmpwalk -v2c -c public localhost system
# Alle Werte
snmpwalk -v2c -c public localhost .1SNMPv3
# Mit Authentifizierung und Verschlüsselung
snmpget -v3 -l authPriv -u monitoring -a SHA -A "authpassword" -x AES -X "privpassword" localhost sysDescr.0
# Walk
snmpwalk -v3 -l authPriv -u monitoring -a SHA -A "authpassword" -x AES -X "privpassword" localhost systemNützliche Abfragen
# System-Uptime
snmpget -v2c -c public localhost .1.3.6.1.2.1.1.3.0
# CPU Load (1, 5, 15 min)
snmpwalk -v2c -c public localhost .1.3.6.1.4.1.2021.10.1.3
# Memory
snmpwalk -v2c -c public localhost .1.3.6.1.4.1.2021.4
# Disk Usage
snmpwalk -v2c -c public localhost .1.3.6.1.4.1.2021.9
# Network Interfaces
snmpwalk -v2c -c public localhost .1.3.6.1.2.1.2.2
# TCP Connections
snmpwalk -v2c -c public localhost .1.3.6.1.2.1.6.13MIBs installieren
Standard-MIBs
apt install snmp-mibs-downloaderMIB-Pfad
# /etc/snmp/snmp.conf
mibs +ALL
mibdirs +/usr/share/snmp/mibsMIB-Namen verwenden
# Mit MIB-Namen statt OID
snmpget -v2c -c public localhost SNMPv2-MIB::sysDescr.0
snmpwalk -v2c -c public localhost IF-MIB::ifTableErweiterte Metriken
Disk-Überwachung
# /etc/snmp/snmpd.conf
# Alle Festplatten mit 10% Warnschwelle
includeAllDisks 10%
# Oder spezifisch
disk / 10%
disk /var 20%
disk /home 30%Prozess-Überwachung
# /etc/snmp/snmpd.conf
# Prozess muss laufen
proc apache2
proc mysql
proc sshd
# Mit min/max Instanzen
proc httpd 1 10Load-Überwachung
# /etc/snmp/snmpd.conf
load 12 10 5Custom Scripts
# /etc/snmp/snmpd.conf
extend test /usr/local/bin/test-script.sh
exec custom /usr/local/bin/custom-check.sh# /usr/local/bin/custom-check.sh
#!/bin/bash
echo "OK: System running"
exit 0chmod +x /usr/local/bin/custom-check.shScript-Ergebnis abfragen
snmpwalk -v2c -c public localhost NET-SNMP-EXTEND-MIB::nsExtendOutput1LineSNMP Traps
Trap-Empfänger konfigurieren
# /etc/snmp/snmpd.conf
# Traps an Monitoring-Server senden
trap2sink 192.168.1.100 public
informsink 192.168.1.100 public
# Auth-Failures melden
authtrapenable 1Trap-Handler (Empfänger)
# /etc/snmp/snmptrapd.conf
disableAuthorization yes
traphandle default /usr/local/bin/trap-handler.sh# /usr/local/bin/trap-handler.sh
#!/bin/bash
read host
read ip
vars=()
while read oid val; do
vars+=("$oid = $val")
done
echo "$(date): Trap from $host ($ip)" >> /var/log/snmp-traps.log
printf '%s\n' "${vars[@]}" >> /var/log/snmp-traps.logTrap-Daemon
apt install snmptrapd
systemctl enable --now snmptrapdIntegration mit Monitoring
Nagios/Icinga
# check_snmp Plugin
/usr/lib/nagios/plugins/check_snmp -H 192.168.1.10 -C public -o .1.3.6.1.4.1.2021.10.1.3.1 -w 5 -c 10
# CPU Load
check_snmp -H $HOSTADDRESS$ -C $COMMUNITY$ -o .1.3.6.1.4.1.2021.10.1.3.1 -w 4 -c 8
# Disk
check_snmp -H $HOSTADDRESS$ -C $COMMUNITY$ -o .1.3.6.1.4.1.2021.9.1.9.1 -w 80 -c 90Zabbix
# Template für Linux SNMP
items:
- snmp.cpu.load1:
oid: .1.3.6.1.4.1.2021.10.1.3.1
- snmp.memory.total:
oid: .1.3.6.1.4.1.2021.4.5.0
- snmp.memory.available:
oid: .1.3.6.1.4.1.2021.4.6.0Prometheus (SNMP Exporter)
# snmp.yml
modules:
if_mib:
walk:
- 1.3.6.1.2.1.2
metrics:
- name: ifNumber
oid: 1.3.6.1.2.1.2.1Sicherheit
Firewall
# Nur von Monitoring-Server
ufw allow from 192.168.1.100 to any port 161 proto udpSNMPv3 Best Practices
# Starke Passwörter
# Auth: SHA (nicht MD5)
# Priv: AES (nicht DES)
# Level: authPriv
net-snmp-config --create-snmpv3-user -ro \
-a SHA -A "LangesAuthPasswort123!" \
-x AES -X "LangesPrivPasswort456!" \
monitoringCommunity-Strings
- Nie "public" oder "private" verwenden
- Komplexe, zufällige Strings
- Unterschiedliche pro Gerät/UmfeldTroubleshooting
Verbindung testen
# Erreichbarkeit
snmpget -v2c -c public localhost sysDescr.0
# Timeout erhöhen
snmpget -v2c -c public -t 10 192.168.1.10 sysDescr.0
# Debug
snmpget -v2c -c public -d localhost sysDescr.0Logs prüfen
journalctl -u snmpd -fHäufige Fehler
# Timeout - Firewall oder falsche IP
# No response - Community falsch oder Agent nicht aktiv
# Unknown OID - MIBs nicht installiertPort prüfen
netstat -ulnp | grep 161
ss -ulnp | grep snmpZusammenfassung
| Befehl | Funktion | |--------|----------| | snmpget | Einzelwert abfragen | | snmpwalk | Bereich abfragen | | snmptable | Tabelle anzeigen | | snmptranslate | OID ↔ Name | | snmpset | Wert setzen |
| OID-Bereich | Inhalt | |-------------|--------| | .1.3.6.1.2.1.1 | System | | .1.3.6.1.2.1.2 | Interfaces | | .1.3.6.1.4.1.2021.4 | Memory (UCD) | | .1.3.6.1.4.1.2021.9 | Disk (UCD) | | .1.3.6.1.4.1.2021.10 | Load (UCD) |
Fazit
SNMP ist der Standard für Netzwerk-Monitoring und wird von fast allen Geräten unterstützt. SNMPv3 sollte für Produktivumgebungen verwendet werden. Die Integration mit Monitoring-Systemen wie Nagios, Zabbix oder Prometheus ermöglicht umfassende Überwachung. Achten Sie auf sichere Community-Strings und Firewall-Regeln.