1、基本配置
其实配制一个snmpd.conf文件不算太难,
(1)首选是定义一个共同体名(community),这里是public,及可以访问这个public的用户名(sec name),这里是notConfigUser。Public相当于用户notConfigUser的密码:)
# sec.name source community
com2sec notConfigUser default public
(2)定义一个组名(groupName)这里是notConfigGroup,及组的安全级别,把notConfigGroup这个用户加到这个组中。
groupName securityModel securityName
group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser
(3)定义一个可操作的范围(view)名, 这里是all,范围是 .1
# name incl/excl subtree mask(optional)
view all included .1
(4)定义notConfigUser这个组在all这个view范围内可做的操作,这时定义了notConfigUser组的成员可对.1这个范围做只读操作。
# group context sec.model sec.level prefix read write notif
access notConfigGroup "" any noauth exact all none none
2、高级配置
3、问题
错误1:
gw firewall # snmpwalk -v 1 -c public localhost system
Cannot find module (IP-MIB): At line 0 in (none)
Cannot find module (IF-MIB): At line 0 in (none)
Cannot find module (TCP-MIB): At line 0 in (none)
Cannot find module (UDP-MIB): At line 0 in (none)
Cannot find module (HOST-RESOURCES-MIB): At line 0 in (none)
Cannot find module (SNMPv2-MIB): At line 0 in (none)
Cannot find module (SNMPv2-SMI): At line 0 in (none)
Cannot find module (NOTIFICATION-LOG-MIB): At line 0 in (none)
Cannot find module (UCD-SNMP-MIB): At line 0 in (none)
Cannot find module (UCD-DEMO-MIB): At line 0 in (none)
Cannot find module (SNMP-TARGET-MIB): At line 0 in (none)
Cannot find module (NET-SNMP-AGENT-MIB): At line 0 in (none)
Cannot find module (SNMP-VIEW-BASED-ACM-MIB): At line 0 in (none)
Cannot find module (SNMP-COMMUNITY-MIB): At line 0 in (none)
Cannot find module (NET-SNMP-EXTEND-MIB): At line 0 in (none)
Cannot find module (UCD-DLMOD-MIB): At line 0 in (none)
Cannot find module (SNMP-FRAMEWORK-MIB): At line 0 in (none)
Cannot find module (SNMP-MPD-MIB): At line 0 in (none)
Cannot find module (SNMP-USER-BASED-SM-MIB): At line 0 in (none)
Cannot find module (SNMP-NOTIFICATION-MIB): At line 0 in (none)
Cannot find module (SNMPv2-TM): At line 0 in (none)
system: Unknown Object Identifier (Sub-id not found: (top) -> system)
gw firewall #
参考资料:可以参考FAQ文档
设置MIBDIRS环境变量 == MIBS库的路径
错误2:
qu@ubuntu:~$ snmpwalk -v 2c -c public 192.168.4.12
Timeout: No Response from 192.168.4.12
dunkel <antal.pettermann@gmail.com>:
>
> The original problem was:
> "However if I run "snmpwalk -v 1 -c public 192.168.1.36 system" on the
> stable box, with 192.168.1.36 the IP address of the testing box, i get:
> Timeout: No Response from 192.168.1.36
>
> snmpd is up and running, I can ping both ways, there are no firewalls
> in place. What could be wrong?"
>
> The solution is:
> open snmpd.conf with your favourite editor and
> add these 2 lines:
> interface eth0
> agentaddress [ip address of your host]:[listening port - 161 is the default]
错误3:
sarge:/# snmpwalk -v 2c -c public localhost
Timeout: No Response from localhost
错误排除:
步骤1:
sarge:/# snmpd -f -Le
屏幕显示(net-snmpd的log文件中是同样内容)
Warning: no access control information configured.
It's unlikely this agent can serve any useful purpose in this state.
Run "snmpconf -g basic_setup" to help you configure the snmpd.conf file for this agent.
Error opening specified endpoint "udp:161"
Server Exiting with code 1
-c FILE 指定文件为配置文件
-C 不读取默认的配置文件
-d dump接收和发送SNMP数据包
-D TOKEN 对于给定的TOKEN(标志)打开调试信息 ( -Dmib_init)
-I [-]INITLIST 对于要初始化的MIB列表显示
-M DIRLIST 指定MIB库的路径
-V 显示详细信息
-Le 把错误信息输出到日志中
-Lf FILE 把错误信息输出到指定文件中
-m MIBLIST use MIBLIST instead of the default MIB list
错误4:
为什么添加代码后,也不能够访问这个变量?
排错步骤:
(1)看这个新模块是否编译进去了?
把.o目标文件删除,重新编译,看是否重新产生.o目标文件?
(2)看这个新模块是否被包含近Agent library?
运行nm libnetsnmpmibs.so.8命令查找initialisation routine and variable handlers的名称。
(3)initialisation routine(初始化例程)是否运行?
(4)这个新模块是否注册进Agent?
(Try walking the NET-SNMP-MIB::nsModuleTable)
This will also check whether the agent accepts
requests for enterprise-specific OIDs.
(5)这个新模块处理程序是否真正的执行了?
(6)这个新模块处理程是否返回了错误?
(1)mib2c配置文件的确定(参考FAQ.txt)
If the MIB contains scalar objects, then use the config file
'mib2c.scalar.conf'. This will generate template handlers for
these scalar objects (ignoring internal structural definitions,
table objects and notifications).