SNMP(簡易網路管理協定)是網管系統(如 Cacti、Zabbix、PRTG)監控裝置的基礎協定。本文涵蓋 Windows 內建 SNMP、Linux net-snmp 安裝與安全配置。
public(或自訂複雜字串),權限設「唯讀」net stop snmp && net start snmp
# RHEL/CentOS/Fedora
yum install -y net-snmp net-snmp-utils
# Debian/Ubuntu
apt update && apt install -y snmpd snmp
tar xzf net-snmp-5.9.3.tar.gz
cd net-snmp-5.9.3
./configure --prefix=/usr/local/snmp --with-default-snmp-version=2c
make && make install
# 1. 定義社群與來源限制
# com2sec 名稱 來源 社群字串
com2sec readonly 192.168.1.100 MySecretCommunity
# 2. 群組對應
group MyROGroup v1 readonly
group MyROGroup v2c readonly
# 3. 視圖定義(開放完整樹)
view all included .1 80
# 4. 權限授予
access MyROGroup "" any noauth exact all none none
# 5. 系統資訊(選填)
syslocation "Server Room A, Rack 3"
syscontact admin@example.com
# 6. 僅監聽特定介面(安全強化)
agentaddress udp:161@eth0
systemctl enable --now snmpd
# 或舊版:service snmpd start
# 本機測試
snmpwalk -v2c -c MySecretCommunity localhost system
# 遠端測試(從監控伺服器)
snmpwalk -v2c -c MySecretCommunity 192.168.1.50 system
iptables -A INPUT -p udp --dport 161 -s 192.168.1.100 -j ACCEPTfirewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.100" port protocol="udp" port="161" accept'public/privatenet-snmp-create-v3-user| OID | 說明 |
|---|---|
| .1.3.6.1.2.1.1.1.0 | sysDescr 系統描述 |
| .1.3.6.1.2.1.1.3.0 | sysUpTime 開機時間 |
| .1.3.6.1.2.1.2.2.1.10 | ifInOctets 介面入流量 |
| .1.3.6.1.2.1.2.2.1.16 | ifOutOctets 介面出流量 |
| .1.3.6.1.4.1.2021.10.1.3.1 | laLoad.1 1 分鐘負載 |
| .1.3.6.1.4.1.2021.4.5.0 | memTotalSwap 總 Swap |
| .1.3.6.1.4.1.2021.4.6.0 | memAvailSwap 可用 Swap |
完成 SNMP 部署後,即可接入 Cacti/Zabbix/Prometheus(snmp_exporter)等監控平台,實現基礎設施可視化與告警。