본문 바로가기
IT/리눅스 이론

리눅스 snmp 설정 NMS snmp 설치 과정(OID,trap 설정)

by 꾸꾸웍스 2022. 10. 22.
반응형

리눅스 snmp 설정 썸네일
linux snmp

 

네트워크 장비와 각 서버들의 모니터링을 하기 위한 리눅스 snmp 프로토콜 서비스를 사용하기 위해 snmp 설명 및 snmp community에 대한 설명과 snmp 옵션 설정을 위해 어떠한 파일을 수정해야 되는지 snmp 설정, snmp 서버 구축에 대한 절차에 대해 알아보겠습니다.

 

※ 목차 구성
1) 리눅스 snmp 서비스란?
2) 리눅스 snmp 패키지 설치
3) 리눅스 snmp 설정
  - snmp.conf 설정, snmptrap.conf 설정
4) 리눅스 snmp 서비스
  - snmp 서비스 시작, 서비스 부팅 시 자동실행 설정
5) 리눅스 snmp 방화벽 설정
  - snmp 서비스 설정, snmp 포트 설정, snmp 포트 확인
6) 리눅스 snmp 서비스 구동 확인

 

리눅스 snmp 서비스란?

 

리눅스 snmp 구성도 사진
linux snmp 구성도

 

SNMP는 Simple Network Management Protocol의 약자로 OSI 7 계층의 Application 계층에 속하는 통신 프로토콜을 의미하며 snmp Manager 서버에서 UDP 통신에 의해 네트워크로 연결된 snmp Agent 서버의 네트워크 장비, 리눅스 서버, 윈도우 서버 등 모니터링을 할 수 있는 정보를 수집하여 실시간으로 운영을 할 수 있도록 해주는 서비스입니다.

 

SNMP Community란?

snmp 커뮤니티는 snmp Manager서버와 snmp Agent 간의 패스워드 같은 역할을 하며 Manager에서 Agent로 요청을 할 때 커뮤니티 값이 올바르지 않거나 지정하지 않으면 정상적인 접근이라고 판단하지 않으며 상호 간의 통신을 할 때는 snmp community 값을 동일하게 설정합니다.

 

snmp 패키지 설치와 snmp 설정 옵션 등의 예시 설명은 위 사진의 host와 IP로 예를 들었습니다.

 

 

반응형

 

리눅스 snmp 패키지 설치

snmp 패키지를 설치하기 위해 사용 중인 리눅스 서버에서 설치 유무와 repository 설치 리스트에 있는지 확인합니다. 설치할 snmp의 대상은 net-snmp와 net-snmp-utils 2개인데 net-snmp-utils는 snmp 구동 유무를 확인하거나 메시지 및 로그를 확인하기 위한 툴입니다.

설치 전 snmp 설치 확인

# rpm -qa | grep snmp

root@server # rpm -qa | grep snmp
net-snmp-libs-5.7.2-49.el7_9.2.x86_64

 

# yum list | grep snmp

root@server # yum list | grep snmp
...
net-snmp.x86_64			1:5.7.2-49.el7_9.2		@updates
...
net-snmp-utils.			1:5.7.2-49.el7_9.2		@updates
...

 

net-snmp와 net-snmp-utils 설치

# yum -y install net-snmp net-snmp-utils

net-snmp와 net-snmp-utils를 설치하면 패키지 의존성이 있는 agent 등 패키지가 함께 설치됩니다. 설치 후 아래와 같이 rpm 명령어로 설치가 되었는지 다시 확인합니다.

 

# rpm -qa | grep snmp

root@server # rpm -qa | grep snmp
net-snmp-utils-5.7.2-49.el7_9.2.x86_64
net-snmp-libs-5.7.2-49.el7_9.2.x86_64
net-snmp-5.7.2-49.el7_9.2.x86_64
net-snmp-agent-libs-5.7.2-49.el7_9.2.x86_64

 

또한 snmp가 성공적으로 설치가 되었다면 /etc 하위에 snmp 디렉토리가 생성되며 snmpd.conf파일과 snmptrap.conf 파일이 생성됩니다.

root@server # ls -l /etc/snmp
total 24
-rw------- 1 root root 19144 Oct 19 10:58 snmpd.conf
-rw------- 1 root root 19144 Oct 19 09:54 snmptrapd.conf

 

 

 

 

리눅스 snmp 설정

 

리눅스 snmpd.conf 파일 내용
linux snmpd.conf 파일 내용

snmp.conf 설정

com2sec [hostname] [Server_IP] [community]
  • 수정 전
    com2sec notConfigUser default public
  • 수정 후
    # com2sec notConfigUser default public
    com2sec server 192.168.2.100 qwer1234abcd
    com2sec nms 192.168.2.50 qwer1234abcd

snmp Manager 서버와 Agent 서버의 정보를 매핑시키는 단계입니다. 기존에 설정된 값은 복원을 위해 주석 처리 후 새로운 snmp Manager 서버와 Agent 서버의 호스트네임과 아이피, 커뮤니티 값을 입력합니다.

 

group [group_name] [version] [hostname]
  • 수정 전
    group notConfigGroup v1 notConfigUser
    group notConfigGroup v2c notConfigUser
  • 수정 후
    # group notConfigGroup v1 notConfigUser
    # group notConfigGroup v2c notConfigUser
    group NMS v2c server
    group NMS v2c nms

snmp Manager 서버와 Agent 서버를 각 호스트 이름을 입력 후 access 설정을 위해 NMS의 하나로 그룹을 묶어줍니다.

 

view all included .1 80
  • 수정 전
    view systemview included .1.3.6.1.2.1.1
    view systemview included .1.3.6.1.2.1.25.1.1
  • 수정 후
    view systemview included .1.3.6.1.2.1.1
    view systemview included .1.3.6.1.2.1.25.1.1
    view all included .1 80

snmp Agent가 가지고 있는 시스템 및 네트워크의 자료를 MID에 저장하여 수집된 정보를 snmp Manager로 보내게 되는데 이때 MID에 저장되어 있는 각각의 객체를 트리구조로 구성된 것을 OID(Object IDentifler)라고 부릅니다. OID는 숫자로 구분되며 snmpd.conf 파일 내 표기 방식은 subtree이며 1.2.6...으로 표기하는데 '.1'은 1개 이상의 인덱스를 지정하며 특정한 세부 자료가 아닌 상위에 있는 자료를 수집할 수 있도록 설정하는 것입니다.

 

access [group_name] "" any noauth exact [all | none] [all | none] none
  • 수정 전
    access notConfigGroup "" any noauth exact systemview none none
  • 수정 후
    # access notConfigGroup "" any noauth exact systemview none none
    access NMS "" any noauth exact all all none

snmp Manager와 Agent가 데이터를 교환하기 위해 패스워드 역할을 하는 커뮤니티 값을 설정하게 되는데 이때 read only와 read write 모드를 설정할 수 있습니다. read와 write에 사용할 모드에 all 또는 none의 값을 설정합니다.

 

- 리눅스 snmp RO(read only) 설정

group context sec.model sec.level prefix read write notif
NMS "" any noauth exact all none none

- 리눅스 snmp RW(read write) 설정

group context sec.model sec.level prefix read write notif
NMS "" any noauth exact all all none

RO(read only) 모드는 write의 값이 none으로 설정해주는 것이며 NMS의 그룹이 read only로 설정됩니다. 이것은 KISA의 보안 취약점 양호 상태이며 RW(read write) 모드를 사용한다면 KISA의 보안 취약점 취약 상태가 되며 수정 등의 보안에 문제가 생길 수 있으니 설정 권고사항은 RO(read only)입니다.

 

snmptrapd.conf 설정

authCommunity log,execute,net {community}

 

root@server # vim snmptrapd.conf
...
# autoCommunity log,execute,net public
...
autoCommunity log,execute,net qwer1234abcd

리눅스 snmptrapd.conf 파일의 내용을 보면 설명에도 나와있듯이 snmp Agent 서버에서 자료를 수집해 snmp Manager 서버로 전달을 하는 역할의 파일입니다. 즉 리눅스 snmp trap 설정 방법으로 따라서 public의 값만 설정해둔 커뮤니티(community) 값만 일치시켜서 snmptrap.conf 파일 맨 아래에 작성합니다.

 

 

 

리눅스 snmp 서비스

위에서 설정한 snmp.conf와 snmptrapd.conf 파일의 설정이 완료되었다면 systemctl 명령어로 snmp 서비스를 구동하고 부팅 시 자동으로 서비스가 구동되게 enable을 설정합니다.

 

리눅스 snmp 서비스 구동

# systemctl start snmpd

# systemctl start snmptrapd

root@server # systemctl start snmpd

root@server # systemctl start snmptrapd

 

리눅스 snmp 서비스 enable

# systemctl enable snmpd

# systemctl enable snmptrapd

root@server # systemctl enable snmpd
Created symlink from /etc/systemd/system/multi-user.target.wants/snmpd.service to /usr/lib/systemd/system/snmpd.service.

root@server # systemctl enable snmptrapd
Created symlink from /etc/systemd/system/multi-user.target.wants/snmptrapd.service to /usr/lib/systemd/system/snmptrapd.service.

 

리눅스 snmpd 서비스 구동 확인

# systemctl status snmpd

# systemctl status snmptrapd

root@server # systemctl status snmpd
● snmpd.service - Simple Network Management Protocol (SNMP) Daemon.
   Loaded: loaded (/usr/lib/systemd/system/snmpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2022-10-19 10:59:09 KST; 2 days ago
 Main PID: 25926 (snmpd)
   CGroup: /system.slice/snmpd.service
           └─25926 /usr/sbin/snmpd -LS0-6d -f

Oct 19 10:59:09 server systemd[1]: Starting Simple Network Management Protocol (SNMP) Daemon....
Oct 19 10:59:09 server snmpd[25926]: NET-SNMP version 5.7.2
Oct 19 10:59:09 server systemd[1]: Started Simple Network Management Protocol (SNMP) Daemon..

root@server # systemctl status snmptrapd
● snmptrapd.service - Simple Network Management Protocol (SNMP) Trap Daemon.
   Loaded: loaded (/usr/lib/systemd/system/snmptrapd.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2022-10-19 10:59:19 KST; 2 days ago
 Main PID: 25961 (snmptrapd)
   CGroup: /system.slice/snmptrapd.service
           └─25961 /usr/sbin/snmptrapd -Lsd -f

Oct 19 10:59:13 server systemd[1]: Starting Simple Network Management Protocol (SNMP) Trap Daemon....
Oct 19 10:59:19 server snmptrapd[25961]: NET-SNMP version 5.7.2
Oct 19 10:59:19 server systemd[1]: Started Simple Network Management Protocol (SNMP) Trap Daemon..
Oct 19 11:16:23 server snmptrapd[25961]: AgentX master disconnected us, reconnecting in 15

 

 

300x250

 

리눅스 snmp 방화벽 설정

snmp 서비스와 포트를 설정하기 위해서는 firewalld 서비스가 동작하고 있어야 됩니다.

 

리눅스 방화벽 snmp 서비스 설정

# firewall-cmd --permanent --add-service=snmp

root@server # firewall-cmd --permanent --add-service=snmp
success

 

리눅스 방화벽 snmp 포트 설정

# firewall-cmd --permanent --zone=public --add-port=161/udp

root@server # firewall-cmd --permanent --zone=public --add-port=161/udp
success

snmp Agent 서버는 포트 UDP 161로 snmp Manager 서버와 통신을 하기 때문에 방화벽 포트를 설정합니다. snmp Agent 서버는 udp 161번 포트를 사용하고 snmp Manager 서버는 udp 162번 포트를 사용합니다.

 

snmp 방화벽 설정 후 다시 로드

# firewall-cmd --reload

root@server # firewall-cmd --reload
success

 

snmp 서비스 포트 확인

# netstat -nap | grep udp

root@server # netstat -nap | grep udp
...
udp        0      0 0.0.0.0:161             0.0.0.0:*                           25926/snmpd
udp        0      0 0.0.0.0:162             0.0.0.0:*                           25961/snmptrapd
...

netstat 명령어를 이용해 snmp 서비스 포트 udp 161 설정되었는지 확인합니다.

 

 

리눅스 snmp 서비스 구동 확인

snmpwalk 명령어는 각종 서브 트리를 확인할 수 있으며 MID의 특정 OID값을 사용하여 추가적인 데이터의 정보를 볼 수 있는 명령어입니다.

 

# snmpwalk -v {version} -c {community} {Agent Server_IP} system

root@server # snmpwalk -v -2c -c qwer1234abcd 192.168.2.100 system
SNMPv2-MIB::sysDescr.0 = STRING: Linux xcat 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (18088504) 2 days, 2:14:45.04
SNMPv2-MIB::sysContact.0 = STRING: Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
SNMPv2-MIB::sysName.0 = STRING: server
SNMPv2-MIB::sysLocation.0 = STRING: Unknown (edit /etc/snmp/snmpd.conf)
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (6) 0:00:00.06
SNMPv2-MIB::sysORID.1 = OID: SNMP-MPD-MIB::snmpMPDCompliance
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::sysORID.9 = OID: SNMP-NOTIFICATION-MIB::snmpNotifyFullCompliance
SNMPv2-MIB::sysORID.10 = OID: NOTIFICATION-LOG-MIB::notificationLogMIB
SNMPv2-MIB::sysORDescr.1 = STRING: The MIB for Message Processing and Dispatching.
SNMPv2-MIB::sysORDescr.2 = STRING: The management information definitions for the SNMP User-based Security Model.
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 implementations
SNMPv2-MIB::sysORDescr.6 = STRING: The MIB module for managing IP and ICMP implementations
SNMPv2-MIB::sysORDescr.7 = STRING: The MIB module for managing UDP implementations
SNMPv2-MIB::sysORDescr.8 = STRING: View-based Access Control Model for SNMP.
SNMPv2-MIB::sysORDescr.9 = STRING: The MIB modules for managing SNMP Notification, plus filtering.
SNMPv2-MIB::sysORDescr.10 = STRING: The MIB module for logging SNMP Notifications.
SNMPv2-MIB::sysORUpTime.1 = Timeticks: (6) 0:00:00.06
SNMPv2-MIB::sysORUpTime.2 = Timeticks: (6) 0:00:00.06
SNMPv2-MIB::sysORUpTime.3 = Timeticks: (6) 0:00:00.06
SNMPv2-MIB::sysORUpTime.4 = Timeticks: (6) 0:00:00.06
SNMPv2-MIB::sysORUpTime.5 = Timeticks: (6) 0:00:00.06
SNMPv2-MIB::sysORUpTime.6 = Timeticks: (6) 0:00:00.06
SNMPv2-MIB::sysORUpTime.7 = Timeticks: (6) 0:00:00.06
SNMPv2-MIB::sysORUpTime.8 = Timeticks: (6) 0:00:00.06
SNMPv2-MIB::sysORUpTime.9 = Timeticks: (6) 0:00:00.06
SNMPv2-MIB::sysORUpTime.10 = Timeticks: (6) 0:00:00.06

리눅스 snmpwalk 명령어의 -v 옵션은 버전으로 1은 버전 1, 2c는 버전 2, 3은 버전 3입니다. -c 옵션은 snmpd.conf에서 설정한 커뮤니티의 값을 넣어줍니다.

 

 

 

반응형
그리드형

댓글