我需要查询Ubuntu终端的MAC地址,记得几年前我用OID .1.3.6.1.2.1.2.2.1.6.2 (IF-MIB::ifPhysAddress.2)查询过OpenSUSE终端。
此 OID 不适用于 Ubuntu:
$ snmpget -v 2c -c public localhost .1.3.6.1.2.1.2.2.1.6.2
IF-MIB::ifPhysAddress.2 = No Such Object available on this agent at this OID
也不:
$ snmpget -v 2c -c public localhost .1.3.6.1.2.1.2.2.1.6
IF-MIB::ifPhysAddress = No Such Object available on this agent at this OID
看起来所有的网络接口根本就不可用:
$ snmpwalk -v 2c -c public localhost .1.3.6.1.2.1.2
IF-MIB::interfaces = No more variables left in this MIB View (It is past the end of the MIB tree)
而如果我从 .1.3.6.1.2.1(SNMPv2-SMI::mib-2)开始执行 snmpwalk,我会得到一些结果。
为什么?我需要启用某些功能才能获取 MAC 地址吗?
我已经检查过,ifPhysAddress 在 /usr/share/mibs/ietf/IF-MIB 中定义,并且 MIBS 似乎配置正确:
$ net-snmp-config --default-mibs | grep IF-MIB
:HOST-RESOURCES-MIB:HOST-RESOURCES-TYPES:UCD-DLMOD-MIB:UCD-DISKIO-MIB:LM-SENSORS-MIB:IP-MIB:IF-MIB:TCP-MIB:UDP-MIB:SNMPv2-MIB:RFC1213-MIB:NOTIFICATION-LOG-MIB:DISMAN-EVENT-MIB:DISMAN-SCHEDULE-MIB:UCD-SNMP-MIB:UCD-DEMO-MIB:SNMP-TARGET-MIB:NET-SNMP-AGENT-MIB:SNMP-FRAMEWORK-MIB:SNMP-MPD-MIB:SNMP-USER-BASED-SM-MIB:SNMP-VIEW-BASED-ACM-MIB:SNMP-COMMUNITY-MIB:IPV6-ICMP-MIB:IPV6-MIB:IPV6-TCP-MIB:IPV6-UDP-MIB:IP-FORWARD-MIB:NET-SNMP-EXTEND-MIB:SNMP-NOTIFICATION-MIB:SNMPv2-TM:NET-SNMP-VACM-MIB
我安装的软件包是:
ii libsnmp-base 4.4.1~dfsg-12ubuntu7 SNMP (Simple Network Management Protocol) MIBs and documen
ii libsnmp15 5.4.1~dfsg-12ubuntu7 SNMP (Simple Network Management Protocol) library
ii snmp 5.4.1~dfsg-12ubuntu7 SNMP (Simple Network Management Protocol) applications
ii snmpd 5.4.1~dfsg-12ubuntu7 SNMP (Simple Network Management Protocol) agents
更新:
下面是目标机器的 snmpd.conf:
com2sec paranoid default public
group MyROSystem v1 paranoid
group MyROSystem v2c paranoid
group MyROSystem usm paranoid
group MyROGroup v1 readonly
group MyROGroup v2c readonly
group MyROGroup usm readonly
group MyRWGroup v1 readwrite
group MyRWGroup v2c readwrite
group MyRWGroup usm readwrite
view all included .1 80
view system included .iso.org.dod.internet.mgmt.mib-2.system
access MyROSystem "" any noauth exact system none none
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all none
syslocation Unknown (configure /etc/snmp/snmpd.local.conf)
syscontact Root <root@localhost> (configure /etc/snmp/snmpd.local.conf)
答案1
社区public
字符串映射到paranoid
组,组又映射到MyROSystem access
,从而允许查看视图system
。您可以更改:
com2sec paranoid default public
读书
com2sec readonly default public
这会将其映射到readonly
并赋予它整棵树。