snmp 設定

安裝過程


  • CentOS / RedHat
yum -y install net-snmp net-snmp-utils
  • Debian / Ubuntu
apt install snmpd snmp
  • 安裝完後備份預設檔
mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.org
  • 手動新增設定檔
vim /etc/snmp/snmpd.conf

# this create a  SNMPv1/SNMPv2c community named "my_servers"
# and restricts access to LAN adresses 192.168.0.0/16 (last two 0's are ranges)
rocommunity public 192.168.0.0/24
# setup info
syslocation 主機所在地
syscontact 聯絡資訊
# open up
agentAddress  udp:161
# run as
agentuser  root
# dont log connection from UDP:
dontLogTCPWrappersConnects yes
# fix for disks larger then 2TB
realStorageUnits 0
  • 設定開機啟動服務
systemctl start snmpd.service
systemctl enable snmpd.service
systemctl status snmpd.service
  • 檢查 snmp 服務是否有正常啟用
netstat -anulp | grep 161
  • 防火牆設定
在防火牆增加 161 port 來源沒有限制
firewall-cmd --permanent --add-port=161/udp
success
防火牆立即生效
firewall-cmd --reload
success
檢查看是否有成功增加 161 port 
firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources:
  services: ssh dhcpv6-client http https
  ports: 161/udp
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:



參考相關網頁