개요
리눅스에서 사용 가능한 SNMP 통신용 프로그램은 CMU-SNMP가 있었다. 이것은 이 후 UCD-SNMP로 변경되었고 UCD-SNMP는 다시 Net-SNMP 프로젝트로 변경되었다.
설치
Net-SNMP Source Download
$ wget http://downloads.sourceforge.net/project/net-snmp/net-snmp/5.7.2/net-snmp-5.7.2.tar.gz
최신 패키지 소스는 http://www.net-snmp.org/download.html 에서 확인 가능하다.
의존 패키지 설치
$ sudo apt-get install libperl-dev
Source Compile
$ tar xzf net-snmp-5.7.2.tar.gz $ cd net-snmp-5.7.2 $ ./configure $ sudo make $ sudo make install
설정
Library Directory 설정
일반적으로 다음과 같이 등록한다.
$ vi ~/.bashrc
다음 내용 추가
export LD_LIBRARY_PATH=/usr/local/lib
우분투에서는 다음 명령을 사용하면 된다.
$ sudo ldconfig
snmpd.conf 설정
$ cp net-snmp-5.7.2/EXAMPLE.conf /usr/local/share/snmp/snmpd.conf
외부 접속을 허용하려면 다음과 같이 설정한다.
$ sudo vi /usr/local/share/snmp/snmpd.conf
# Listen for connections from the local system only #agentAddress udp:127.0.0.1:161 # Listen for connections on all interfaces (both IPv4 *and* IPv6) agentAddress udp:161,udp6:[::1]:161
테스트
$ sudo /usr/local/sbin/snmpd -f -L & $ snmpwalk -v1 localhost -c public system
다음과 같은 메시지 출력 시
Turning on AgentX master support. Error opening specified endpoint "udp6:[::1]:161" Server Exiting with code 1
다음 명령을 사용한다.
$ snmpd -f -Lo -C --rwcommunity=public -x /var/agentx/master
configure 실행시에 새로 추가한 MIB를 같이 컴파일 할 수 있다. ex) –with-mib-modules=“nstAgentModuleObject”
자세한 사항은 MIB 참고
디렉토리
/var/log/snmpd.log /var/net-snmp /usr/local/share/snmp/snmpd.conf /usr/local/sbin/snmpd /usr/local/lib/ - Net-SNMP를 인스톨하면 라이브러리가 위치하는 곳 /usr/lib/ - snmpd 가 라이브러리를 검색하는 곳
The NET-SNMP snmpwalk command is a really good tool , but it has a really big help output, to simplify things just use one of the below examples and, if needed add the adequate parameters: SNMP v1: snmpwalk -v1 -c <community> <ipaddress>[:<dest_port>] <oid> example: snmpwalk -v1 -cpublic 127.0.0.1:161 system SNMP v2: snmpwalk -v2c -c <community> <ipaddress>[:<dest_port>] [oid] example: snmpwalk -v2c -c public 127.0.0.1:161 system SNMP v3: snmpwalk -v3 -l <noAuthNoPriv|authNoPriv|authPriv> -u <username> [-a <MD5|SHA>] [-A <authphrase>] [-x DES] [-X <privaphrase>] <ipaddress>[:<dest_port>] [oid] example: snmpwalk -v3 -l authPriv -u snmpadmin -a MD5 -A PaSSword -x DES -X PRIvPassWord 127.0.0.1:161 system
SNMP Sub Agent
Build the subagent
테스트 MIB 파일을 agent가 요구하는 위치로 복사한다.
$ cp NET-SNMP-TUTORIAL-MIB.txt usr/local/share/snmp/mibs/
테스트 소스파일을 사용하여 net-snmp-config 명령어로 subagent를 생성한다.
$ net-snmp-config --compile-subagent mysubagent nstAgentSubagentObject.c generating the temporary code file: netsnmptmp.13399.c void init_nstAgentSubagentObject(void); checking for init_nstAgentSubagentObject in nstAgentSubagentObject.c init_nstAgentSubagentObject(void) checking for shutdown_nstAgentSubagentObject in nstAgentSubagentObject.c running: gcc -fno-strict-aliasing -g -O2 -Ulinux -Dlinux=linux -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/lib/perl/5.14/CORE -I. -I/usr/local/include -o mysubagent netsnmptmp.13399.c nstAgentSubagentObject.c -L/usr/local/lib -lnetsnmpmibs -lnetsnmpagent -lnetsnmp -lnetsnmpmibs -ldl -lnetsnmpagent -Wl,-E -lnetsnmp -lrt nstAgentSubagentObject.c: In function ‘init_nstAgentSubagentObject’: nstAgentSubagentObject.c:47:5: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long int’ [-Wformat] nstAgentSubagentObject.c:47:5: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long int’ [-Wformat] removing the temporary code file: netsnmptmp.13399.c subagent program mysubagent create
Start the master agent
$ snmpd -f -Lo -C --rwcommunity=public -x /var/agentx/master
Test
Test object without subagent
$ snmpget -v2c -c public localhost NET-SNMP-TUTORIAL-MIB::nstAgentSubagentObject.0 NET-SNMP-TUTORIAL-MIB::nstAgentSubagentObject.0 = No Such Object available on this agent at this OID
subagent를 실행하지 않고 테스트하였을 때에 위와 같은 메시지가 출력되어야 한다.
Start the subagent
subagent 실행
$ ./mysubagent
테스트
$ snmpget -v2c -c public localhost NET-SNMP-TUTORIAL-MIB::nstAgentSubagentObject.0 NET-SNMP-TUTORIAL-MIB::nstAgentSubagentObject.0 = INTEGER: 2 $ snmpset -v2c -c public localhost NET-SNMP-TUTORIAL-MIB::nstAgentSubagentObject.0 = 5 NET-SNMP-TUTORIAL-MIB::nstAgentSubagentObject.0 = INTEGER: 5 $ snmpget -v2c -c public localhost NET-SNMP-TUTORIAL-MIB::nstAgentSubagentObject.0 NET-SNMP-TUTORIAL-MIB::nstAgentSubagentObject.0 = INTEGER: 5
ERROR
ERROR #01
ERROR Message
Error opening specified endpoint "" Server Exiting with code 1
Solution
root 모드로 전환하여 실행한다.
ERROR #02
ERROR Message
libnetsnmpagent.so.30: cannot open shared object file
Solution
라이브러리 설정이 제대로 먹히지 않아 /usr/local/lib에 있는 파일들을 /usr/lib에 복사해줌
참고
- http://www.net-snmp.org/wiki/index.php/Net-Snmp_on_Ubuntu - 우분투에 SNMP 설치
- http://www.superuser.co.kr/linux/dbakorea/page23.htm - SNMP 설치 및 테스트