net-snmp开发教程
康林(kl222@126.com)
可以下载word文档:http://download.csdn.net/detail/kl222/4366325
目录
1.2.1 scalar:变量,就是一个量(包括整数理、字符串型、IPADDRESS等)...3
1.2.3 notification:通知消息。以前叫trap.3
4.1 snmpd:响应snmp请求包的代理服务器。...4
4.2 snmptrapd:接收并记录snmp
trap消息服务器。...5
4.4 snmpget、snmpgetnext、snmpwalk:得到请求...5
4.6 snmptranslate:mib oid数字到文本互相转换工具...5
4.8 net-snmp-config:返回编译和安装信息,建立SNMPV3配置...5
4.9 net-snmp-create-v3-user:建立SNMPV3认证配置...5
4.10 mib2c:用于从mib文件生成扩展模块c代码的工具。...5
4.11 net-snmp-cert:用于认证信息产生...5
5.1 snmp.conf:用于代理和应用程序的公共配置。...5
5.2 snmpd.conf:用于配置snmpd代理...6
5.2.5.2 interprets在一个实体类上的请求运行命令...7
5.2.5.3 interprets一个实体类上的请求运行一个执久的进程...7
5.3 snmptrap.conf:用于配置snmptrapd.7
5.4 用net-snmp-config配置V3存储控制...7
8.1.1 接收网管发过来的snmp包,并对接收到的snmp包进行解析,校验后,找到并调用相应的处理函数进行处理。 8
8.1.2 调用注册了的告警函数,向网管发送告警信息。...8
8.3.2.1 为mib2c工具配置mibs搜索路径:有两种方法...10
1.1 snmp协议
请参阅《TCP-IP详解卷1》——《第25章SNMP:简单网络管理协议》
MIBS rfc详见源码目录下的doc\rfc\smiV2
MIBS总共有三种实体:
1.2.1 scalar:变量,就是一个量(包括整数理、字符串型、IPADDRESS等)
1.2.2 table:表,一组变量
1.2.3 notification:通知消息。以前叫trap
snmp认证目前有三个版本:snmpv1、snmpv2、snmpv3
snmpv1(rfc1157)、snmpv2(rfc1901)都是基于密码字符串的认证,且密码为明文。
snmpv3(rfc2571)认证分为使用USM(基于用户的安全模式)和VACM(基于查看的访问控制模式)。认证的加协议有:MD5、SHA;加密协议有:DES、AES;加密协议用于加密PDU数据。
2 下载net-snmp代码。
./configure –help #查看配置
./configure
make
make install
4.1 snmpd:响应snmp请求包的代理服务器。
用法:-f 不调用fork,即不进入daemon,如果不用这个参数,则进入daemon模式
-L[efos]日志输出到指定的位置
-Le Log messages to the standard error stream.
-Lf FILE
Log messages to the specified file.
-Lo Log messages to the standard output stream.
-Ls FACILITY
Log messages via syslog, using the specified facility
('d' for LOG_DAEMON, 'u' for LOG_USER, or '0'-'7' for
LOG_LOCAL0 through LOG_LOCAL7).
4.2 snmptrapd:接收并记录snmp
trap消息服务器。
4.3 snmpset:设置请求
4.4 snmpget、snmpgetnext、snmpwalk:得到请求
4.5 snmptrap:trap产生工具
4.6 snmptranslate:mib oid数字到文本互相转换工具
4.7 snmpconf:配置工具
4.8 net-snmp-config:返回编译和安装信息,建立SNMPV3配置
4.9 net-snmp-create-v3-user:建立SNMPV3认证配置
4.10 mib2c:用于从mib文件生成扩展模块c代码的工具。
4.11 net-snmp-cert:用于认证信息产生
-v 1|2c|3 指定SNMP使用的版本
-V, --version 显示命令的版本号
SNMP Version 1 or 2c specific
-c COMMUNITY 设置团体名
SNMP Version 3 specific
-a PROTOCOL 设置认证协议 (MD5|SHA)
-A PASSPHRASE 设置认证协议密码
-e ENGINE-ID set security engine ID (e.g. 800000020109840301)
-E ENGINE-ID set context engine ID (e.g. 800000020109840301)
-l LEVEL set security level (noAuthNoPriv|authNoPriv|authPriv)
-n CONTEXT set context name (e.g. bridge1)
-u USER-NAME set security name (e.g. bert)
-x PROTOCOL 设置加密协议 (DES|AES)
-X PASSPHRASE 设置加密协议密码
-Z BOOTS,TIME set destination engine boots/time
例子:
snmpgetnext -v 1 -c public 127.0.0.1 sysUpTime
snmpget –v 3 –a MD5 –A 1235678 –u name 127.0.0.1 oid
用配置工具 snmpconf
进行配置
配置包括三个部分:
5.1 snmp.conf:用于代理和应用程序的公共配置。
###########################################################################
# SECTION: Textual mib parsing
#
# This section controls the textual mib parser. Textual
# mibs are parsed in order to convert OIDs, enumerated
# lists, and ... to and from textual representations
# and numerical representations.
# mibs: Specifies a list of mibs to be searched for and loaded.
# Adding a '+' sign to the front of the argument appends the new
# mib name to the list of mibs already being searched for.
# arguments: [+]mibname[:mibname...]
mibs +/root/test/NET-SNMP-EXAMPLES-MIB.txt
5.2 snmpd.conf:用于配置snmpd代理
###########################################################################
# SECTION: Access Control Setup
#
# This section defines who is allowed to talk to your running
# snmp agent.
# rwcommunity: a SNMPv1/SNMPv2c read-write access community name
# arguments: community [default|hostname|network/bits] [oid]
rwcommunity public 127.0.0.1
rwcommunity public 192.168.0.1
# rwuser: a SNMPv3 read-write user
# arguments: user [noauth|auth|priv] [restriction_oid]
rwuser public #这里定义用户名和验证方式,密码保存在/var/net-snmp/snmpd.conf中
# rouser: a SNMPv3 read-only user
# arguments: user [noauth|auth|priv] [restriction_oid]
rouser public #这里定义用户名和验证方式,密码保存在/var/net-snmp/snmpd.conf中,详见——用net-snmp-config配置V3
5.2.4 trap目的地定义
###########################################################################
# SECTION: Trap Destinations
#
# Here we define who the agent will send traps to.
# trap2sink: A SNMPv2c trap receiver
# arguments: host [community] [portnum]
trap2sink 127.0.0.1 public 162
trap2sink 192.168.0.1 public 162
5.2.5.1 用exec运行一个简单的命令
5.2.5.2 interprets在一个实体类上的请求运行命令
5.2.5.3 interprets一个实体类上的请求运行一个执久的进程
5.2.5.5 用system运行一个简单的命令
###########################################################################
# SECTION: Extending the Agent
#
# You can extend the snmp agent to have it return information
# that you yourself define.
# dlmod: dynamically extend the agent using a shared-object
# arguments: module-name module-path
dlmod notification /data/snmp/test/.libs/ libnetsnmpmibs.so
5.3 snmptrap.conf:用于配置snmptrapd
5.3.2 trap外理者
5.3.3 接收的traps输出格式
#authCommunity TYPES COMMUNITY [SOURCE [OID | -v VIEW ]]
authCommunity log,execute,net public
5.4 用net-snmp-config配置V3存储控制
root@ubuntu:~# net-snmp-config --create-snmpv3-user --help
Usage:
net-snmp-create-v3-user [-ro] [-A authpass] [-X privpass]
[-a MD5|SHA] [-x DES|AES] [username]
root@ubuntu:~# net-snmp-create-v3-user -ro -A SHA -a public1234 -x DES -X abcdefgmok public
adding the following line to /var/net-snmp/snmpd.conf:
createUser public SHA "public1234" DES abcdefgmok
adding the following line to /usr/local/share/snmp/snmpd.conf:
rouser public
net-snmp-create-v3-user实质上是个脚本文件
它实质上是把V3的用户配置(createUser public SHA "public1234" DES abcdefgmok)加到/var/net-snmp/snmpd.conf文件中。然后agent从这个文件中读取v3的用户配置信息。然后生成相应的密码并保存在这个文件中。
读写权限设置是在$SNMPCONF/snmpd.conf中配置的,详见——5.2 snmpd.conf:用于配置snmpd代理
SNMP Version 3 参数:
-a PROTOCOL 设置认证协议 (MD5|SHA)
-A PASSPHRASE 设置认证协议密码
-x PROTOCOL 设置加密协议 (DES|AES)
-X privpass 设置加密协议密码
执行 snmpd –f –Lo
后台方式 snmpd
root@ubuntu:~# snmpget -v 1 -c public 127.0.0.1 UDP-MIB::udpInDatagrams.0
UDP-MIB::udpInDatagrams.0 = Counter32: 7822
如果出现错误,请检查配置是否正确。