CentOS 64位, 内核(3.10.0-957.el7.x86_64)
CentOS Linux release 7.6.1810 (Core)
以下所有步骤都以root
的身份来操作, 只是为了实验而已
yum install -y net-snmp*
$ cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak $ vim /etc/snmp/snmpd.conf # 添加如下内容 rocommunity mycommunity # community值, 类似于密码 group notConfigGroup v1 notConfigUser group notConfigGroup v2c notConfigUser access notConfigGroup "" any noauth exact all none none view all included .1 80 syslocation Unknown syscontact Root <root@localhost> dontLogTCPWrappersConnects yes
$ systemctl restart snmpd # snmp服务默认开启161端口(UDP), 可以这样查看启动没有 $ netstat -tlunp | grep :161 udp 0 0 0.0.0.0:161 0.0.0.0:* 86881/snmpd 86881/snmpd
$ cat /etc/hostname # 显示: localhost.localdomain # 调snmp协议查看本机主机名 # 其中'1.3.6.1.2.1.1.5.0'是主机名对就的OID $ snmpget -v 2c -c mycommunity localhost '1.3.6.1.2.1.1.5.0' #显示: SNMPv2-MIB::sysName.0 = STRING: localhost.localdomain # 设置hostname $ echo my-machine > /etc/hostname $ hostname `cat /etc/hostname` $ systemctl restart snmpd # 再次调snmp协议查看本机主机名 $ snmpget -v 2c -c mycommunity localhost '1.3.6.1.2.1.1.5.0' # 显示: SNMPv2-MIB::sysName.0 = STRING: my-machine
最新评论: