SNMP Traps - Complete Guide
1. What is an SNMP Trap?
An SNMP Trap is an unsolicited, asynchronous message sent by a network device (SNMP Agent) to an SNMP Manager whenever a predefined event occurs.
Unlike polling (where the manager asks for data), traps are pushed immediately from the device, making them ideal for real-time alerts such as:
- Interface failure (e.g., link down)
- Device reboot
- High CPU or memory utilization
2. SNMP Trap vs. Polling (GET Requests)
Feature | SNMP Trap | SNMP Polling (GET) |
---|---|---|
Direction | Agent → Manager | Manager → Agent |
Trigger | Event-based | Scheduled/Timed |
Network Load | Low | Higher |
Latency | Immediate | Based on interval |
3. SNMP Trap Types
A. Generic Traps
- coldStart – Device restarted
- linkDown – Interface failure
- authenticationFailure – Unauthorized SNMP access
B. Specific (Enterprise) Traps
Vendor-specific traps like Cisco’s high CPU or BGP flaps, defined in proprietary MIBs.
4. SNMP Trap Message Format
A standard trap includes:
- Agent IP Address
- Trap OID (Object Identifier)
- Timestamp
- Variable Bindings (contextual data)
Example:
SNMPv2-MIB::snmpTrapOID.0 = IF-MIB::linkDown
IF-MIB::ifIndex.1 = 1 (Interface GigabitEthernet0/0)
5. Configuring SNMP Traps (Cisco IOS)
Router(config)# snmp-server host 192.168.1.100 traps MyROString
Router(config)# snmp-server enable traps
Router(config)# snmp-server enable traps snmp linkdown
Router# show snmp host
6. SNMP Trap Ports & Protocols
- UDP 162: Used by managers to receive traps
- UDP 161: Used for standard SNMP polling
7. Trap Severity Levels
Level | Example Trap |
---|---|
Critical | linkDown, bgpBackwardTransition |
Warning | highCpuThreshold |
Informational | configChange |
8. SNMPv1 vs v2c vs v3 Traps
Version | Authentication | Encryption | Trap Format |
---|---|---|---|
v1 | Community String | None | Basic, limited |
v2c | Community String | None | Enhanced (varbinds) |
v3 | User-based (SHA, MD5) | Yes (AES, DES) | Secure, reliable |
9. SNMP Trap vs. Inform
Feature | Trap | Inform |
---|---|---|
Acknowledgment | No | Yes |
Reliability | Low | High (retries supported) |
Use Case | Non-critical alerts | Critical events |
Example (Cisco):
Router(config)# snmp-server host 192.168.1.100 informs MyROString
10. MIBs for Traps
- Standard: SNMPv2-MIB, IF-MIB
- Vendor: CISCO-PROCESS-MIB, JUNIPER-BGP-MIB, etc.
11. Testing SNMP Traps
From Agent (Linux)
snmptrap -v 2c -c public 192.168.1.100 '' IF-MIB::linkDown ifIndex.1 i 1
On Receiver
snmptrapd -f -Lo
12. Security Considerations
- ✅ Use SNMPv3 with encryption
- ✅ Allow UDP 162 only from trusted devices
- ✅ Apply ACLs to limit trap sources
Router(config)# access-list 10 permit 192.168.1.100
Router(config)# snmp-server host 192.168.1.100 traps MyROString 10
13. Use Cases
Network Devices
- Interface down (linkDown)
- BGP peer failure (bgpStateChange)
Servers
- High CPU usage (hrProcessorLoad)
- Disk full alert (diskFull)
14. Monitoring Traps in NMS
- SolarWinds: Trap viewer & alert generation
- PRTG: Custom trap sensors
- ELK Stack: Integrate traps via syslog/logstash
15. Troubleshooting
- ❌ Not receiving traps? → Verify
snmp-server host
and port 162 access - ❌ Invalid community string? → Match it with your NMS
- ❌ MIB error? → Import vendor-specific MIBs into your NMS
16. Summary
- SNMP Traps = Real-time, event-driven alerts
- Setup: Define
snmp-server host
and enable trap types - Security: Use SNMPv3 and ACLs
- Test: Use
snmptrap
andsnmptrapd