Search code examples
loggingcentossnmpsnmptrapd

How do write snmptrapd configuration file?


I need snmptrapd configuration file, ı does not find any configuration file. If ı run "snmptrapd -Le -A -Lf /var/log/snmptrapd.log" command from commandline, snmptrapd process is running. And ı try this snmptrapd -Le -A -Lf /var/log/snmptrapd.log --install , but service not running or create. How ı write manually snmptrapd.conf


Solution

  • In Linux, If you are using net-snmp package. You can find the configuration files at /etc/snmp/snmptrapd,conf. According to the NET-SNMP man page, the tool looks for the configuration of snmp and snmptrapd in the following directories in order:

    ROOTDIR/etc/snmp, ROOTDIR/usr/share/snmp, ROOTDIR/usr/lib/snmp, and $HOME/.snmp
    

    You can also check the configuration directory by executing.

    sudo net-snmp-config --snmpconfpath
    

    You can create the snmptrapd.conf file in the location and start adding configuration to it.

    For testing purposes, you can provide the parameter '-c' in snmptrapd command to specify config file location.

    # eg. sudo snmptrapd -f -C -c snmptrapd.conf -Le -m ALL
    sudo snmptrapd -f -C -c <config file location> -Le -m ALL
    

    There are different SNMP versions (snmp v1, snmp v2 and snmp v3) which can be used for sending/receiving traps.

    SNMP v1 is the least secure (also used less), snmp v2 uses 'community string' as a key for authentication and snmp v3 is the most secure till now which has 'User based'(USM) and 'TLS/DTLS based'(TSM) authentication.

    For SNMP v2, the very basic configuration to receive a trap is as follow

    # SNMP v2 configuration
    
    # Access control
    # Eg: authCommunity log,execute,net public
    authCommunity log <community-string>
    

    After saving this configuration and restart snmptrapd server. You can try this command from your system to send the trap.

    snmptrap -v2c -c public 127.0.0.1 '' 1.3.6.1.4.1.33095.0.1000 1.3.6.1.4.1.33095.0.1000 s "This is my first snmp trap."
    

    You can add more options listed in snmptrapd.conf doc.

    For SNMP v3(USM), You can use the following configuration for receiving traps.

    # SNMPv3 config with AuthPriv security level.
    
    # Create a user for authentication
    # Eg. createUser snmptestuser SHA shapassword AES aespassword
    createUser <username> <AuthProtocol> <authpass> <PrivProtocol> <privpass>
    
    # Access control
    # Eg. authuser log,execute,net snmptestuser
    authuser log <username>
    

    Restart snmptrapd server and run the following to command to send the trap

    snmptrap -Ci -v 3 -a SHA -A shapassword -x AES -X aespassword -l authPriv -u snmptestuser 127.0.0.1 1.3.6.1.4.1.33095.0.1000 1.3.6.1.4.1.33095.0.1000 s "This is my first snmp v3 trap."
    

    You can refer to this doc for snmp v3 configuration.

    I faced some problem while receiving the traps because of firewall, so make sure the firewall is configured properly or disable it completely if you want to test the initial configuration.