SNMP server construction in Ubuntu

Source: Internet
Author: User
Tags snmpwalk snmpv3
Snmp Server SETUP (v1, v2, v3) apt-getinstallsnmpdvi/etc/snmp/snmpd. conf1. add a line of agentaddress110.1.1.2 (local IP address) 2. modify one line to add accessMyROSystem "" any

Snmp server construction (v1, v2, v3)

Ubuntu System
Apt-get install snmpd
Vi/etc/snmp/snmpd. conf
1. Add a row
Agentaddress 110.1.1.2 (local IP address)
2. modify a row
Set
Access MyROSystem "" any noauth exact system none
Change
Access MyROSystem "" any noauth exact all none

Type snmpwalk-v 2c-c public localhost. If data exists, it indicates it is normal.

# Vi/etc/default/snmpd

SnmpDOPTS = '-Lsd-Lf/dev/null-u snmp-I-smux-p/var/run/snmpd. pid 127.0.0.1 ′

Modify it:

SnmpDOPTS = '-Lsd-Lf/dev/null-u snmp-I-smux-p/var/run/snmpd. Pi'

/Etc/init. d/snmpd restart

Access commands for v1 and v2:
Snmpwalk-v 2c (1)-c public 110.1.1.3 (peer IP)

V3 Configuration

Vi/etc/snmp/snmpd. conf
Add:
CreateUser testsnmp123 MD5. "123456789"

Stop Service:
/Etc/init. d/snmpd stop
Add username and password:
Net-snmp-config -- create-snmpv3-user-a "my_password" myuser
Enable the service:
/Etc/init. d/snmpd start
V3 access command:
Snmpget-v 3-u myuser-l authNoPriv-a MD5-A my_password localhost sysUpTime.0

Snmp-trap configuration for v1 and v2:
1. in/etc/hosts. allow, add the acceptable network segment snmptrapd: 110.1.

2. Create/usr/share/snmp/snmptrapd. conf (this is the one on my machine. Different machines may be stored in/etc/snmp,/usr/local/share/snmp/, and experiment slowly according to different situations ), add the following line:
Authcommunity execute | log | net public

3. Add the following lines to snmptrapd. conf.
Traphandle. 1.3.6.1.6.3.1.5.1 page_me up
Traphandle. 1.3.6.1.4.1.2021.251.1 page_me up
Traphandle. 1.3.6.1.4.1.2021.251.2 page_me down
Traphandle default log_it

4. Start snmptrapd with snmptrapd-d-f-Lo
Enter snmptrap-v 2c-c public 192.168.213.64: 162 "" UCD-SNMP-MIB: ucdStart

Trap of snmpv2 completed

Snmpv1 trap:
Write two mib files, including snmp1 and snmp2 traps.
Mib of Snmp1: TRAP-TEST-MIB.txt
TRAP-TEST-MIB DEFINITIONS: = BEGIN
IMPORTS ucdExperimental FROM UCD-SNMP-MIB;
Demotraps object identifier ::={ ucdExperimental 990}
Demo-trap TRAP-TYPE
STATUS current
ENTERPRISE demotraps
VARIABLES {sysLocation}
DESCRIPTION "This is just a demo"
::= 17
END
Mib of Snmp2: NOTIFICATION-TEST-MIB.txt
NOTIFICATION-TEST-MIB DEFINITIONS: = BEGIN
IMPORTS ucdavis FROM UCD-SNMP-MIB;
Demonotifs object identifier ::={ ucdavis 991}
Demo-notif NOTIFICATION-TYPE
STATUS current
OBJECTS {sysLocation}
DESCRIPTION "Just a test notification"
::={ Demonotifs 17}
END
And put it in the mibs folder.

Run snmptrap-v 2c-c public 192.168.213.64: 162 "" NOTIFICATION-TEST-MIB: demo-notif SNMPv2-MIB: sysLocation.0 s "just here"

Trap completion for snmpv1

Snmpv3-trap
Vi/var/net-snmp/snmptrapd. conf
Add: createUser-e 0x0102030405 myuser MD5 mypassword DES mytherpassword

Access: snmptrap-e 0x0102030405-v 3-u myuser-a MD5-A mypassword-l authNoPriv localhost 42 coldStart.0

The following is for reference only:
1. Write and process the trap script by yourself.
Create the root/bin/traps file and enter the following content:
#! /Bin/sh
Read host
Read ip
Vars =
While read oid val
Do
If ["$ vars" = ""]
Then
Vars = "$ oid = $ val"
Else
Vars = "$ vars, $ oid = $ val"
Fi
Done
Echo trap: $1 $ host $ ip $ vars
 
Add the following lines to manager's snmptrapd. conf:
Traphandle: SNMPv2-MIB: coldStart/root/bin/traps cold
The traphandle SNMPv2-MIB: warmStart/root/bin/traps warm
Traphandle IF-MIB: linkDown/root/bin/traps down
Traphandle: IF-MIB: linkUp/root/bin/traps up
Traphandle SNMPv2-MIB: authenticationFailure/root/bin/traps auth
# This one is deprecated
Traphandle. 1.3.6.1.6.3.1.1.5.6/root/bin/traps egp-neighbor-loss
 
Restart snmptrapd: snmptrapd-d-f-Lo 161. Listen to port 161.
Enter the following command on the agent:
Snmptrap-v 1-c public 110.1.1.2 TRAP-TEST-MIB: demotraps 110.1.1.2 2 0 "" IF-MIB: ifIndex I 1

2. Enable the agent to automatically generate traps
Configure the snmpd. conf of the agent and add the following lines: (this may be due to a configuration file problem, and the manager cannot receive any traps)
# Send v1 traps
Trapsink 110.1.1.2: 162 public
# Also send v2 traps
Trap2sink 110.1.1.2: 162 secret
# Send traps on authentication failures
Authtrapenable 1

For more information about Ubuntu, see Ubuntu special page http://www.linuxidc.com/topicnews.aspx? Tid = 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.