net-snmp配置:snmp v3的安全配置
可以参考这里:http://www.ttlsa.com/zabbix/snmp-v3-configuration/
增加snmp v3用户
增加 认证且加密只读账号(authPriv)
o@o-pc:~$ sudo service snmpd stop #停止snmpd服务
o@o-pc:~$ sudo net-snmp-create-v3-user -ro -A auth123456 -X priv123456 -a MD5 -x DES fx #创建snmpv3用户
adding the following line to /var/net-snmp/snmpd.conf:
createUser fx MD5 "auth123456" DES priv123456
adding the following line to /usr/local/net-snmp/share/snmp/snmpd.conf:
rouser fx
增加 认证且加密的读写账户
o@o-pc:~$ sudo /usr/local/net-snmp/bin/net-snmp-create-v3-user -A auth123456 -a MD5 -X priv123456 -x DES fxw
adding the following line to /var/net-snmp/snmpd.conf:
createUser fxw MD5 "auth123456" DES priv123456
adding the following line to /usr/local/net-snmp/share/snmp/snmpd.conf:
rwuser fxw
增加 认证但不加密只读账户(authNoPriv)
o@o-pc:~$ sudo net-snmp-create-v3-user -ro -A auth123456 -a MD5 fxa
adding the following line to /var/net-snmp/snmpd.conf:
createUser fxa MD5 "auth123456" DES
adding the following line to /usr/local/net-snmp/share/snmp/snmpd.conf:
rouser fxa
注意,这个操作会修改默认的snmpd.conf
文件。
参数说明
-ro
:用户读写权限,表示用户fx为只具有读权限fx
:用户名-a MD5
:认证方式,MD5散列方式-A auth123456
:设置认证密码,密码必须大于8个字符-x DES
:加密方式,这边支持AES、DES两种priv123456
:加密口令,必须大于8位
备注:增加用户的时候,snmp必须关闭,否则有如下报错
Apparently at least one snmpd demon is already running.
You must stop them in order to use this command.
Apparently at least one snmpd demon is already running.
You must stop them in order to use this command.
重新启动snmpd
o@o-pc:~$ sudo service snmpd start
测试一下
测试认证且加密只读账户fx
o@o-pc:~$ snmpwalk -v3 -u fx -a MD5 -A auth123456 -x DES -X priv123456 -l authPriv 127.0.0.1 sysUpTime
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (93687) 0:15:36.87
测试认证且加密读写账户fxw
注意,下面的节点confNewVersion.0
是一个自定义的读写节点
#认证且加密方式set
```bash
$ snmpset -v3 -u fxw -a MD5 -A auth123456 -x DES -X priv123456 -l authPriv 127.0.0.1 confNewVersion.0 s "12345"
SNMP-VC-MIB::confNewVersion.0 = STRING: "12345"
#认证但不加密方式set
```bash
$ snmpset -v3 -u fxw -a MD5 -A auth123456 -l authNoPriv 127.0.0.1 confNewVersion.0 s "12345"
SNMP54-VideoCommand-MIB::confNewVersion.0 = STRING: "12345"
测试认证不加密只读账户fxa
o@o-pc:~$ snmpwalk -v 3 -u fxa -a MD5 -A auth123456 -l authNoPriv 127.0.0.1 sysUpTime
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (8215) 0:01:22.15
注意事项
注意,对于snmpget/set
操作,代理端配置的账户与管理端使用的时候可以不完全一致。但是对于set
操作,不能使用noAuthNoPriv
方式,否则报错。
-
对于认证且加密的账户,
snmpget/walk/get
可以使用三种级别的安全方式,分别为noAuthNoPriv
(不认证也不加密)、authNoPriv
(认证但是不加密)、authPriv
(既认证又加密) -
对于认证但不加密的账户,
snmpget/walk/get
可以使用两种级别的安全方式,分别为noAuthNoPriv(不认证也不加密)、authNoPriv(认证但是不加密)
snmpwalk权限设置导致的超时
```bash
$ snmpwalk -v 3 -u fxa -a MD5 -A auth123456 -x DES -X priv123456 -l authPriv 127.0.0.1 sysUpTime
Timeout: No Response from 127.0.0.1
snmpset安全等级设置与认证和加密设置不对等时候的报错
```bash
$ snmpset -v3 -u fxw -a MD5 -A auth123456 -l authPriv 127.0.0.1 confNewVersion.0 s "12345"snmpset: USM generic error (Sub-id not found: (top) -> confNewVersion)
snmpset使用noAuthNoPriv不认证不加密方式报错
$ snmpset -v3 -u fxw -l noAuthNoPriv 127.0.0.1 confNewVersion.0 s "12345"
Error in packet.
Reason: authorizationError (access denied to that object)