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 Interfaces

Agent installieren

Debian/Ubuntu

apt update
apt install snmpd snmp

CentOS/RHEL

dnf install net-snmp net-snmp-utils

Service aktivieren

systemctl enable --now snmpd

SNMPv2c 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 all

Sicherere 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 snmpd

SNMPv3 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" monitoring

Konfiguration

# /etc/snmp/snmpd.conf

# SNMPv3 Benutzer
rouser monitoring priv

# View definieren
view all included .1

# Zugriff
access monitoring "" any priv exact all none none

Service starten

systemctl start snmpd

Abfragen 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 .1

SNMPv3

# 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 system

Nü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.13

MIBs installieren

Standard-MIBs

apt install snmp-mibs-downloader

MIB-Pfad

# /etc/snmp/snmp.conf

mibs +ALL
mibdirs +/usr/share/snmp/mibs

MIB-Namen verwenden

# Mit MIB-Namen statt OID
snmpget -v2c -c public localhost SNMPv2-MIB::sysDescr.0
snmpwalk -v2c -c public localhost IF-MIB::ifTable

Erweiterte 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 10

Load-Überwachung

# /etc/snmp/snmpd.conf

load 12 10 5

Custom 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 0
chmod +x /usr/local/bin/custom-check.sh

Script-Ergebnis abfragen

snmpwalk -v2c -c public localhost NET-SNMP-EXTEND-MIB::nsExtendOutput1Line

SNMP 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 1

Trap-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.log

Trap-Daemon

apt install snmptrapd
systemctl enable --now snmptrapd

Integration 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 90

Zabbix

# 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.0

Prometheus (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.1

Sicherheit

Firewall

# Nur von Monitoring-Server
ufw allow from 192.168.1.100 to any port 161 proto udp

SNMPv3 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!" \
    monitoring

Community-Strings

- Nie "public" oder "private" verwenden
- Komplexe, zufällige Strings
- Unterschiedliche pro Gerät/Umfeld

Troubleshooting

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.0

Logs prüfen

journalctl -u snmpd -f

Häufige Fehler

# Timeout - Firewall oder falsche IP
# No response - Community falsch oder Agent nicht aktiv
# Unknown OID - MIBs nicht installiert

Port prüfen

netstat -ulnp | grep 161
ss -ulnp | grep snmp

Zusammenfassung

| 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.