zoukankan      html  css  js  c++  java
  • 在CentOS和RHEL中配置SNMPv3

    首先,使用yum安装必要的软件

    [root@server ~]# yum install net-snmp-utils net-snmp-devel
    安装完成之后, 先停止snmpd,再创建具有只读属性的SNMP 账户。 .
    [root@server ~]# service snmpd stop
    [root@server ~]# net-snmp-create-v3-user -A snmpv3pass -a MD5 -x DES snmpv3user
    ==================================================================
    snmp V3的方式设置简单,而且安全性更高。

    配置方法:
    1.停止snmpd服务
      #service snmpd stop

    2.增加snmpv3用户,并设置认证以及加密方式
      # net-snmp-create-v3-user
        Enter a SNMPv3 user name to create:
        enocsnmpv3
        Enter authentication pass-phrase:
        enocsnmpv3pw
        Enter encryption pass-phrase:
        [press return to reuse the authentication pass-phrase]
        enocsnmpv3pk
        adding the following line to /var/lib/net-snmp/snmpd.conf:
           createUser enocsnmpv3 MD5 "enocsnmpv3pw" DES enocsnmpv3pk
        adding the following line to /etc/snmp/snmpd.conf:
           rwuser enocsnmpv3


    3.启动snmpd服务
     # service snmpd restart

    现通过snmpwalk测试一下:
    # snmpwalk -v3 -uenocsnmpv3 -lauth -aMD5 -A"enocsnmpv3pw" -X"enocsnmpv3pk" localhost  | more
    SNMPv2-MIB::sysDescr.0 = STRING: Linux CentOS60A 2.6.32-71.el6.i686 #1 SMP Fri Nov 12 04:17:17 GMT 2010 i686
    SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::org
    DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (9443) 0:01:34.43


    或:
    # snmpwalk -v3 -uenocsnmpv3 -lauth -aMD5 -A"enocsnmpv3pw"  localhost .1 | more
    或:
    # snmpwalk -v3 -lauth -uenocsnmpv3 -aMD5 -xDES -A"enocsnmpv3pw" -X"enocsnmpv3pk" localhost .1 | more

    补充:
    SNMP Version 3 specific
      -a PROTOCOL           set authentication protocol (MD5|SHA)
      -A PASSPHRASE         set authentication protocol pass phrase
      -e ENGINE-ID          set security engine ID (e.g. 800000020109840301)
      -E ENGINE-ID          set context engine ID (e.g. 800000020109840301)
      -l LEVEL              set security level (noAuthNoPriv|authNoPriv|authPriv)
      -n CONTEXT            set context name (e.g. bridge1)
      -u USER-NAME          set security name (e.g. bert)
      -x PROTOCOL           set privacy protocol (DES|AES)
      -X PASSPHRASE         set privacy protocol pass phrase
      -Z BOOTS,TIME         set destination engine boots/time
    ==================================================================
    ## OUTPUT ##
    adding the following line to /var/lib/net-snmp/snmpd.conf:
    createUser snmpv3user MD5 "snmpv3pass" DES
    adding the following line to /etc/snmp/snmpd.conf:
    rouser snmpv3user
    [root@server ~]# service snmpd start
    SNMPv3测试
    snmpwalk 是测试SNMP配置和输出出色的工具。成功的测试结果应当有大量的输出数据。
    [root@server ~]# snmpwalk -u snmpv3user -A snmpv3pass -a MD5 -l authnoPriv 192.168.1.2 -v3
    ### OUTPUT ###
    SNMPv2-MIB::sysDescr.0 = STRING: Linux server.example.tst 2.6.32-71.el6.i686 #1 SMP Fri Nov 12 04:17:17 GMT 2010 i686
    SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
    DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (28963) 0:04:49.63
    SNMPv2-MIB::sysORLastChange.0 = Timeticks: (1) 0:00:00.01
    SNMPv2-MIB::sysORID.1 = OID: SNMP-MPD-MIB::snmpMPDMIBObjects.3.1.1
    SNMPv2-MIB::sysORID.2 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance
    SNMPv2-MIB::sysORID.3 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance
    SNMPv2-MIB::sysORID.4 = OID: SNMPv2-MIB::snmpMIB
    SNMPv2-MIB::sysORID.5 = OID: TCP-MIB::tcpMIB
    SNMPv2-MIB::sysORID.6 = OID: IP-MIB::ip
    SNMPv2-MIB::sysORID.7 = OID: UDP-MIB::udpMIB
    SNMPv2-MIB::sysORID.8 = OID: SNMP-VIEW-BASED-ACM-MIB::vacmBasicGroup
    SNMPv2-MIB::sysORDescr.1 = STRING: The MIB for Message Processing and Dispatching.
    SNMPv2-MIB::sysORDescr.2 = STRING: The MIB for Message Processing and Dispatching.
    SNMPv2-MIB::sysORDescr.3 = STRING: The SNMP Management Architecture MIB.
    SNMPv2-MIB::sysORDescr.4 = STRING: The MIB module for SNMPv2 entities
    SNMPv2-MIB::sysORDescr.5 = STRING: The MIB module for managing TCP implementation
    ## and the output continues ##
    删除SNMPv3账户
    SNMPv3 账户信息被包含在两个文件之中。删除账户即删除这个文件中的信息即可。
    root@server:~# service snmpd stop
    root@server:~# vim /var/lib/net-snmp/snmpd.conf
    ## there should be a similar encrypted line that contains information on the user ##
    ## this line is removed ##
    usmUser 1 3 0x80001f8880056e06573a1e895100000000 0x736e6d70763375736572000x736e6d7076337573657200 NULL .1.3.6.1.6.3.10.1.1.2 0x945ed3c9708ea5493f53f953b45a4513 .1.3.6.1.6.3.10.1.2.2 0x945ed3c9708ea5493f53f953b45a4513 ""
    root@server:~# vim /etc/snmp/snmpd.conf
    ## The following line is removed ##
    rouser snmpv3user
    root@server:~# service snmpd start
    防火墙调节(可选)
    下面的例子中的防火墙规则可以被用于限制被允许进行SNMP查询的源IP地址。两个IP地址(例如,192.168.1.100/101)被置于白名单中。
    root@server:~# iptables -A INPUT -s 192.168.1.100/32 -p udp –dport 161 -j ACCEPT
    root@server:~# iptables -A INPUT -s 192.168.1.101/32 -p udp –dport 161 -j ACCEPT
    root@server:~# iptables -A INPUT -p udp –dport 161 -j DROP
    思科交换机和路由器配置SNMPv3
    思科交换机和路由器同样支持SNMPv3。下面的例子将创建一个访问控制列表(ACL)限制允许做SNMP查询的源IP地址。但是,这步被跳过了。
    设置访问控制列表(ACL)(可选)
    ## global config mode ##
    ip access-list standard SNMP_ACL
    permit 192.168.1.100
    permit 192.168.1.100
    SNMPv3 配置
    下面的配置创建一个名为v3Group与认证AuthNoPriv安全级别v3的组。前面定义的可选访问列表也支持设定。
    ## global config mode ##
    ## With ACL ##
    snmp-server group v3Group v3 auth access SNMP_ACL
    ## Without ACL ##
    snmp-server group v3Group v3 auth
    用户v3user被创建并添加在v3Group下。 
     
    DES加密密钥
    snmp-server user snmpv3user v3Group v3 auth md5 snmpv3pass priv DES snmpv3pass
     
    AES加密密钥
    snmp-server user snmpv3user v3Group v3 auth md5 snmpv3pass priv AES 128 snmpv3pass
     

    SNMPv3测试
    SNMP用户和相关组可以在Cisco设备中查看。
    ### privileged EXEC mode ##
    show snmp user
    User name: v3user
    Engine ID: ************************
    storage-type: nonvolatile active
    Authentication Protocol: MD5
    Privacy Protocol: AES128
    Group-name: v3Group
    任何Linux设备中的snmpwalk的都可以用来验证配置和检查输出。
    snmpwalk -u snmpv3user -A snmpv3pass -a MD5 -l authnoPriv 192.168.1.3 -v3
    iso.3.6.1.2.1.1.1.0 = STRING: "Cisco IOS Software”
    Technical Support: http://www.cisco.com/techsupport
    Copyright (c) 1986-2012 by Cisco Systems, Inc.
    iso.3.6.1.2.1.1.2.0 = OID: iso.3.6.1.4.1.9.1.1166
    iso.3.6.1.2.1.1.7.0 = INTEGER: 78
    iso.3.6.1.2.1.1.8.0 = Timeticks: (0) 0:00:00.00
    iso.3.6.1.2.1.2.1.0 = INTEGER: 54
    iso.3.6.1.2.1.2.2.1.1.1 = INTEGER: 1
    iso.3.6.1.2.1.2.2.1.1.2 = INTEGER: 2
    iso.3.6.1.2.1.2.2.1.1.3 = INTEGER: 3
    ## output truncated ##
  • 相关阅读:
    Oracle备份 还原命令
    maven错误解决一:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile)
    maven File encoding has not been set
    maven 错误: 程序包org.junit不存在
    <转>JDBC获取DB元数据
    <转>SQL语句执行顺序说明
    Oracle 创建/删除 表空间、用户、授权
    lucene/solr 修改评分规则方法总结
    Solr入门之(8)中文分词器配置
    Solr入门之(7)Solr客户端界面简介
  • 原文地址:https://www.cnblogs.com/luckyall/p/10460972.html
Copyright © 2011-2022 走看看