본문 바로가기

work/snmp

linux에서 net-snmp설치

* net-snmp-5.1.2를 사용하여 snmp agent를 구현
* snmp V1, mib-2를 사용


# root 계정으로 로그인

$ guest 계정으로 로그인

 

기존 net-snmp 패키지 삭제

리눅스에서 SNMP 데몬이 있는지 확인
# ps -aux | grep snmpd

 

rpm 패키지가 설치되어 있는지 확인하고 설치되어 있다면 삭제

# rpm -qa|grep net-snmp
  # net-snmp-utils-5.0.1-6
  # net-snmp-5.0.1-6
  # net-snmp-devel-5.0.1-6

# rpm -e net-snmp-devel

# rpm -e net-snmp-utils

# rpm -e net-snmp     
    오류: Failed dependencies:
        libsnmp.so.5 is needed by (installed) kernel-utils-2.4-8.13
        libsnmp.so.5 is needed by (installed) ethereal-0.9.6-1
        libsnmp.so.5 is needed by (installed) ethereal-gnome-0.9.6-1
        net-snmp >= 5.0 is needed by (installed) ethereal-0.9.6-1

# rpm -e net-snmp --nodeps



새로운 net-snmp 패키지를 소스로 설치

$ tar -xvzf net-snmp-5.1.2.tar.gz

 

설치 문서 참고

net-snmp-5.1.2$ INSTALL


소스 컴파일

net-snmp-5.1.2$ ./configure

  configure시 다음 사항 입력. 입력하지 않은 것은 디폴트 사용.
  Default version of SNMP to use (3): 1   <-- 여기서 버전 2c를 입력한답시고 2c로 입력하면 make에서 오류 그냥 2를 입력
  System Contact Information (root@):
o2tree@netsgo.com
  System Location (Unknown): YoungTongGu, Suwon city, Kyung-Gi do, Republic of Korea
  Location to write logfile (/var/log/snmpd.log):
  Location to write persistent information (/var/net-snmp):

   --> net-snmp-5.1.2$ config.log
   --> net-snmp-5.1.2/include/net-snmp$ net-snmp-config.h, If necessary edit.

 

net-snmp-5.1.2$ make;

net-snmp-5.1.2# make test;

   --> 44/44 succeeded

net-snmp-5.1.2# make install

   --> /usr/local/bin
   --> /usr/local/man


삭제하고 다시 설치할 경우
net-snmp-5.1.2# make clean, program binaries and object files
net-snmp-5.1.2# make uninstall, application
net-snmp-5.1.2# make distclean, configure created

 

net-snmp-5.1.2$ cp EXAMPLE.conf /usr/local/share/snmp/snmpd.conf

변경한 설정사항 일부

#            sec.name    source           community
com2sec local           localhost         public
com2sec mynetwork   192.168.1.0/24  public
com2sec public         default            public

 

####
# Second, map the security names into group names:

#                    sec.model  sec.name
group local      v1               local
group local      v2c             local
group local      usm            local
group mygroup    v1            mynetwork
group mygroup    v2c          mynetwork
group mygroup    usm          mynetwork
group public     v1               public
group public     v2c             public
group public     usm            public

 

####
# Third, create a view for us to let the groups have rights to:

#                   incl/excl   subtree                                                           mask
view  all         included    .1                                                                   80
view  system   included    system                                                           fe
view  mib2      included    .iso.org.dod.internet.private.enterprises.ghost      fc


####
# Finally, grant the 2 groups access to the 1 view with different
# write permissions:

#                         context   sec.model  sec.level  match  read    write    notif
access  mygroup  ""           any           noauth     exact  mib2      none   none
access  public      ""           any           noauth     exact  system  all      all
access  local        ""           any           noauth     exact  all         all      all


syslocation SuwonCity$YoungTongGu
syscontact ghost o2tree@netsgo.com

 

설정파일을 검색하는 곳
/usr/local/share/snmp
/usr/local/lib/snmp
$HOME/.snmp
환경변수 SNMPCONFPATH


SNMP Agent가 제대로 되지 않으면 로그와 FAQ, 문서를 보도록 하자.
/var/log/snmpd.log
http://www.net-snmp.org/FAQ.html

 

서버실행(-h 옵션을 주면 도움말을 볼 수 있다)
/usr/local/sbin/snmpd -D -L -f -c /usr/local/share/snmp/snmpd.conf
/usr/local/sbin/snmpd -d -L -f -> default directory : -c /usr/local/share/snmp/snmpd.conf


데몬 실행 확인하기
# netstat -an | grep udp
   udp        0      0 0.0.0.0:1024            0.0.0.0:*
   udp        0      0 0.0.0.0:161             0.0.0.0:*
   udp        0      0 192.168.71.217:53       0.0.0.0:*
   udp        0      0 127.0.0.1:53            0.0.0.0:*

부팅 시 자동실행 지정
: /etc/rc.d/rc.local 파일에 아래 문장을 입력한다.
   - [/etc/rc.d/rc.local] ------------------------------------
   # snmpd start
   /usr/local/sbin/snmpd  
   -----------------------------------------------------------

테스트
/usr/local/sbin# snmpget -v1 -c public localhost system.sysLocation.0
 SNMPv2-MIB::sysLocation.0 = STRING: Right here, right now.

 

/usr/local/sbin# snmpwalk -v1 -c public localhost system
 SNMPv2-MIB::sysDescr.0 = STRING: Linux ns 2.4.20-31.9 #1 Tue Apr 13 17:38:16 EDT 2004 i686
 SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
 SNMPv2-MIB::sysUpTime.0 = Timeticks: (48581) 0:08:05.81
 ... 중략 ...
 SNMPv2-MIB::sysORUpTime.7 = Timeticks: (0) 0:00:00.00
 SNMPv2-MIB::sysORUpTime.8 = Timeticks: (0) 0:00:00.00
 SNMPv2-MIB::sysORUpTime.9 = Timeticks: (0) 0:00:00.00
 End of MIB

 

 snmpget -v 1 -c public -d -Of localhost .1.3.6.1.4.1.15000.1.1.1.0
 snmpget -v 1 -c public localhost .enterprises.ghost.ap.apSystem.apSysDescr.0

 snmpset -v 1 -c public localhost .1.3.6.1.4.1.15000.1.1.2.0 s string
 snmptrap -v 1 -c public 192.168.1.51 .1.3.6.1.4.1.15000 192.168.1.23 0 0 0 .1.3.6.1.4.1.15000.1.1.1.0 s "Hello"
 snmptrap -v 1 -c public -d -Of 192.168.1.51 enterprises.ghost 192.168.1.23 1 0 '' .1.3.6.1.4.1.15000.1.1.1.0 s "HI"

 

OPTIONS:
 -d : Dump (in Hexadecimal) the sent and received SNMP packets
 -Of : *Gives you the complete OID
 -Ou : *Removing a series of "standard" prefixes
 -On : *The OID numerically
 -Ox : Display strings as Hex

 

Install SNMP perl module for using mib2c

net-snmp-5.1.2$ cd perl

net-snmp-5.1.2$perl Makefile.PL

net-snmp-5.1.2$ make

net-snmp-5.1.2$ make test

net-snmp-5.1.2# make install

 

참고 매뉴얼 페이지
snmpd.conf, snmp.conf, snmptrapd.conf, snmp_config