windows 下安装/配置/测试 net-snmp
1. 安装
安装前准备:
1)ActivePerl-5.10.0.1004-MSWin32-x86-287188.msi (Perl安装程序).
2)net-snmp-5.4.2.1-1.win32.exe (net-snmp安装程序)
安装 Windows下安装net-snmp很简单,只需要执行安装程序,使用默认设置一步步点即可完成安装过程。安装net-snmp前可能需要安装Perl,一样是使用默认配置一步步点即可。
安装文件下载可参考net-snmp Install Steps(http://hi.baidu.com/%CE%A8%B2%CA%D0%F9/blog/item/149eb6b5b2c9cbfd31add1f7.html)中的II. windows 下安装net-snmp 部分提供的链接,很好用。(该博文还提供了linux下的安装方法,以及一些链路,感觉很不错!)
2. 配置
配置snmpd.conf 说明:
每次改变snmpd.conf都必须重启snmp服务以使更改生效。对于自动配置,网上有介绍,但需要熟悉各种参数,这里采用手工创建方法。如果需要深入学习配置方法,可参考“net-snmp安装配置手册”(东软的张兵写的,很不错!) 手工创建配置文件的方法:
配置文件中路径分隔符都要使用斜杆“/”,而不要使用反斜杆 All paths in configuration files should use forward slashes (Unix style), NOT back slashes. Example: c:/usr ?在c:\usr\etc\snmp\下新建一文本文件,重命名为snmpd.conf(不要有.txt的扩展名)。
最简单的应用,在snmpd.conf中加入以下指令:
rocommunity public
rwcommunity private 这样系统就可以运行了。但是这样的配置很不安全,任何人只要使用public(public相当于密码),都可以获得本机信息,网上有很多更好的配置方法,大家可参考文后附加的网址,举例如下:
# sec.name source community
com2sec local localhost public
com2sec mynetwork IP public
#以上用来设置允许访问本机信息的IP地址,除此之外的地址都无法获得本机信息。
# sec.model sec.name group
MyRWGroup v1 local group
MyRWGroup v2c local group
MyRWGroup usm local group
MyROGroup v1 mynetwork group
MyROGroup v2c mynetwork group
MyROGroup usm mynetwork
# incl/excl subtree mask
view all included .1 80
# context sec.model sec.level match read write notif access
MyROGroup "" any noauth exact all none none access
MyRWGroup "" any noauth exact all all none syslocation China load 12 14 14
3. 启动snmp:
(1)根据http://www.net-snmp.org/docs/README.win32.html所提供的信息,如下:
***************************************************************************
*
* Running Net-SNMP as a replacement for the Microsoft SNMP service
*
***************************************************************************
As of Net-SNMP 5.4, the Net-SNMP agent is able to load the Windows SNMP
service extension DLLs by using the Net-SNMP winExtDLL extension.
The Windows SNMP service must be installed, but the service must be disabled.
This is required so that the extension DLLs are available for loading, and
also because this extension and the existing Windows extensions use the
Windows SNMP API from snmpapi.dll.
An alternative to winExtDLL is to proxy requests from Net-SNMP to the Windows
SNMP service. See the section 'Co-existence with Microsoft SNMP services'.
可知,我们需要安装Windows SNMP service,但安装完后需要将其禁掉,因为NET-SNMP会用到snmpapi.dll(这个文件在win32目录下,可以直接本地搜索到)。这一点很重要,一定要做,很多网上的文档都没有写,不知道为什么。
(2)用cmd启动一个命令窗口,将工作目录改到C:\usr(我装在这个目录的)下,执行
c:\usr>bin\snmpd -v
NET-SNMP version: 5.4.2.1
Web: http://www.net-snmp.org/
Email: net-snmp-coders@lists.sourceforge.net
主文件正常,下一步将它安装为windows服务,执行
c:\usr>registeragent.bat
Registering snmpd as a service using the following additional options:
.
-Lf “c:/usr/log/snmpd.log”
.
.
For information on running snmpd.exe and snmptrapd.exe as a Windows
service, see ‘How to Register the Net-SNMP Agent and Trap Daemon as
Windows services’ in README.win32.
.
请按任意键继续. . .
c:\usr>
服务注册成功,接着注册trap,命令
c:\usr>registeragent.bat
同样看到类似信息。
下面启动net-snmp
c:\usr>net start “net-snmp agent”
Net-SNMP Agent 服务已经启动成功。
c:\usr>
这样,我们便可以在windows的任务管理器中看到snmpd.exe这个进程。
4. 测试net-snmp
(1)启动net-snmp后我们先确认版本,用snmpd -v ,结果:
C:\usr>snmpd -v
NET-SNMP version: 5.4.2.1
Web: http://www.net-snmp.org/
Email: net-snmp-coders@lists.sourceforge.net
(2)可以使用以下指令测试net-snmp是否正常工作:
snmpwalk -v 2c -c public localhost system 这条指令用于查看本机系统信息,若正确返回信息则netsnmp正常工作。
(3)依据张兵的测试方法,我们可以进行如下三种方法测试网卡的属性:
本地通过localhost测试:
snmpwalk -v 2c -c public localhost if
本地通过IP(下面是我的IP)测试:
snmpwalk -v 2c -c public 59.69.64.101 if
远程通过IP测试:
在客户机上可能没安装net-snmp,因此不能运行net-snmp命令,需要通过第三方软件进行测试。我们使用AdventNet MibBorwser,用这个是因为我们之前使用过SNMP Simulator Toolkits 7.0.4,里面自带了这个MIB库工具。加载RFC1213-MIB库,之后输入信息如下:
Host: 59.69.64.101
Port:161
Community:public
如我们查看system下的sysContact或sysName,可以在org/dod/internet/mgmt/mib-2/system子树下找到这些键值,选中,然后,通过菜单Opersations/Get获取值。获取的值可以在窗口显示出来。