為什麼 SNMP 不足夠:企業 3-Tier 網絡的真正監控需求 + Ubuntu 24.04:ntopng + InfluxDB + Grafana + Cisco C9300 Flow 完整部署教程
這份教程完整介紹了為什麼 SNMP 已經不足以支撐現代企業 3‑Tier 網絡的監控需求,並帶你部署一套真正能回答「誰在做什麼」的 Flow-based Telemetry 方案:ntopng + InfluxDB + Grafana。 同時,本教程也包含 Cisco C9300(IOS‑XE 17.06.05) 的正確 NetFlow/FNF 配置,確保你能從交換機成功匯出 Flow 資料。 整篇內容以工程師視角撰寫,適合保存作為長期參考手冊。
為什麼 SNMP 不足夠:企業 3‑Tier 網絡的真正監控需求
企業網絡監控一直以來都依賴 SNMP,但在現代 3‑Tier 架構(Core / Distribution / Access)中,SNMP 已經無法回答真正重要的問題。
這篇文章分成兩部分:
- 為什麼 SNMP 不足夠(概念篇)
- 如何部署 Flow-based Telemetry(實作篇:ntopng + InfluxDB + Grafana)
1. 為什麼 SNMP 不足夠(概念篇)
在典型企業網絡中,SNMP 只能看到「設備層級」的健康狀態:
- CPU / Memory
- Interface up/down
- Interface counters(但無法 per‑IP、per‑protocol)
- 基本流量量值(但不知道 誰 在做 什麼)
問題是:
SNMP 完全無法回答真正重要的問題:
- 哪一台終端造成 broadcast storm?
- 哪一個 IP 在大量做 DNS Query?
- 哪一個 port 在跑大量 SMB?
- 哪一個 protocol 在佔用 WAN?
- 哪一個 VLAN 的流量異常?
這些都需要 Flow-based telemetry 才能做到。
SNMP vs ntopng + InfluxDB + Grafana 能力比較
| 需求 | SNMP | ntopng | InfluxDB | Grafana |
|---|---|---|---|---|
| per‑IP | ❌ | ✅ | 存儲 | 可視化 |
| per‑port | ❌ | ✅ | 存儲 | 可視化 |
| per‑protocol | ❌ | ✅ | 存儲 | 可視化 |
| 長期歷史 | ❌ | 部分 | ✅ | 可視化 |
| 自訂 Dashboard | ❌ | ❌ | ❌ | ✅ |
Flow 監控的核心不是 ntopng,而是 Flow Source
最常被忽略的問題:
如果你的防火牆同時是:
- NAT Gateway
- DHCP Server
- Routing Gateway
- VLAN Gateway(SVI)
- Policy Enforcement Point
那麼它就是最準確的 Flow Source。
推薦 Flow 格式
- NetFlow v9
- IPFIX(最佳)
Flow 能看到:
- 誰在傳輸什麼(IP、Port、Protocol、Bytes、Packets)
Flow 看不到:
- 為什麼被 block
- 哪條 policy hit
- 哪個 rule 造成大量 session
因此建議補充:
- Syslog → Loki / Elasticsearch
- Firewall logs → SIEM(如果你有)
2. Flow-based Telemetry 實作篇
Ubuntu 24.04:ntopng + InfluxDB + Grafana 完整部署教學
本方案在 同一台 VM 上部署:
- ntopng(接收 Cisco NetFlow)
- InfluxDB v2(儲存 timeseries)
- Grafana(可視化 Dashboard)
整個流程約 1–2 小時。
前置條件
- vSphere 已建立 Ubuntu 24.04 Server(minimal)
- VM 規格:4–6 vCPU / 8–16GB RAM / 100–200GB SSD
- VM 有靜態 IP(例:
192.168.1.100) - Cisco 交換機能匯出 NetFlow 到
UDP 2055 - SSH + sudo 權限
步驟 1:基本系統設定
sudo apt update && sudo apt upgrade -y
sudo apt install wget curl gnupg software-properties-common -y
sudo reboot
步驟 2:安裝 ntopng(Community Edition)
sudo apt-get install software-properties-common wget whiptail -y
sudo add-apt-repository universe -y
wget https://packages.ntop.org/apt/24.04/all/apt-ntop.deb
sudo apt install ./apt-ntop.deb
sudo apt update
sudo apt install ntopng -y
啟動 ntopng
sudo systemctl start ntopng
sudo systemctl enable ntopng
設定接收 NetFlow
sudo nano /etc/ntopng/ntopng.conf
加入:
-F="netflow;0.0.0.0:2055"
重啟:
sudo systemctl restart ntopng
開放端口
sudo ufw allow 3000/tcp
sudo ufw allow 2055/udp
sudo ufw reload
登入 ntopng:
http://VM_IP:3000(預設帳密:admin/admin)
步驟 3:安裝 InfluxDB v2
wget -q https://repos.influxdata.com/influxdb2.key
echo "deb [signed-by=/etc/apt/trusted.gpg.d/influxdb2.gpg] https://repos.influxdata.com/debian stable main" | sudo tee /etc/apt/sources.list.d/influxdb.list
sudo apt update
sudo apt install influxdb2 -y
sudo systemctl start influxdb
sudo systemctl enable influxdb
初始設定:
瀏覽器開啟 http://VM_IP:8086 → 建立:
- Organization(例:
main) - Bucket(例:
ntopng) - 初始使用者與密碼
步驟 4:ntopng → InfluxDB 匯出設定
4.1 產生 All-Access Token
InfluxDB Web → Load Data → API Tokens → Generate Token
複製完整 Token。
4.2 CLI 登入
export INFLUX_TOKEN=eyJr...完整Token
export INFLUX_HOST=http://localhost:8086
export INFLUX_ORG=main
驗證:
influx org list
influx bucket list
4.3 建立 v1 相容帳號給 ntopng
influx v1 auth create \
--username ntopng \
--password 你的強密碼 \
--org main \
--write-bucket ntopng \
--read-bucket ntopng
4.4 ntopng Timeseries 設定
ntopng Web → Preferences → Timeseries
- Driver:InfluxDB 1.x/2.x
- URL:
http://127.0.0.1:8086 - Database:
ntopng - Username:
ntopng - Password:剛剛建立的密碼
重啟:
sudo systemctl restart ntopng
127.0.0.1,不要使用 VM 的內網 IP。
步驟 5:安裝 Grafana
sudo apt-get install -y apt-transport-https software-properties-common wget
sudo mkdir -p /etc/apt/keyrings/
wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg > /dev/null
echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
sudo apt update
sudo apt install grafana -y
啟動 Grafana
sudo systemctl start grafana-server
sudo systemctl enable grafana-server
修改端口(可選)
sudo nano /etc/grafana/grafana.ini
找到:
[server]
http_port = 8080
重啟:
sudo systemctl restart grafana-server
開放端口:
sudo ufw allow 8080/tcp
登入:
http://VM_IP:8080(預設帳密:admin/admin)
步驟 6:Grafana 連 InfluxDB + 匯入 Dashboard
設定 Data Source
Grafana → Connections → Data sources → Add → InfluxDB
- URL:
http://localhost:8086 - Database:
ntopng - Token 或 username/password
按下 Save & Test → 成功
匯入 Dashboard
- 前往:
https://grafana.com/grafana/dashboards/ - 搜尋:ntopng
- 推薦:Dashboard ID 14357(Dynamic Flows)
- Import → 選你的 InfluxDB datasource
步驟 7:Cisco C9300(IOS‑XE 17.06.05)NetFlow / FNF 正確配置
1:建立 Flow Record / Exporter / Monitor
以下為「通用版」設定,適用於 Gigabit / TenGigabit Access 端口。
1.1 建立 Ingress Flow Record
flow record NETFLOW-INGRESS
match ipv4 source address
match ipv4 destination address
match transport source-port
match transport destination-port
match ipv4 protocol
collect counter bytes long
collect counter packets long
collect timestamp absolute first # 若不支援可刪除
collect timestamp absolute last # 若不支援可刪除
! 不加 collect interface,避免 ASIC 限制
1.2 建立 Egress Flow Record
flow record NETFLOW-EGRESS
match ipv4 source address
match ipv4 destination address
match transport source-port
match transport destination-port
match ipv4 protocol
collect counter bytes long
collect counter packets long
collect timestamp absolute first
collect timestamp absolute last
! 不加 collect interface,避免 ASIC 限制
1.3 建立 Flow Exporter(匯出到 ntopng)
flow exporter NETFLOW-EXPORTER
destination 192.168.1.100 ! ntopng VM IP
source Vlan1
transport udp 2055
export-protocol netflow-v9
1.4 建立 Flow Monitor(Ingress / Egress)
flow monitor NETFLOW-INGRESS
record NETFLOW-INGRESS
exporter NETFLOW-EXPORTER
cache timeout active 60
cache timeout inactive 15
flow monitor NETFLOW-EGRESS
record NETFLOW-EGRESS
exporter NETFLOW-EXPORTER
cache timeout active 60
cache timeout inactive 15
2:套用到 Access 端口
2.1 GigabitEthernet Access Ports
interface range GigabitEthernet1/0/1 - 48, GigabitEthernet2/0/1 - 48, GigabitEthernet3/0/1 - 48
ip flow monitor NETFLOW-INGRESS input
ip flow monitor NETFLOW-EGRESS output
exit
2.2 TenGigabitEthernet Uplink / Server Ports
interface range TenGigabitEthernet1/1/1 - 8
ip flow monitor NETFLOW-INGRESS input
ip flow monitor NETFLOW-EGRESS output
exit
interface range TenGigabitEthernet2/1/1 - 8
ip flow monitor NETFLOW-INGRESS input
ip flow monitor NETFLOW-EGRESS output
exit
interface range TenGigabitEthernet3/1/1 - 8
ip flow monitor NETFLOW-INGRESS input
ip flow monitor NETFLOW-EGRESS output
exit
end
3:完成後測試(非常重要)
3.1 先產生流量
(ping -s 1500、傳檔、iPerf、NAS 讀寫都可以)
3.2 等 30–60 秒後執行:
show flow exporter statistics
show flow monitor NETFLOW-INGRESS cache
show flow monitor NETFLOW-EGRESS cache
你應該看到:
- Records added 開始增加
- Packets sent > 0
- Cache 裡有 IPv4 flows
3.3 ntopng 介面
等 2–3 分鐘後:
- Flows 開始跳動
- Top Talkers 出現
- 應用分類(DNS/SMB/HTTPS)開始填滿
結語:SNMP 是健康檢查,Flow 才是行為監控
SNMP 告訴你「設備是否正常」。
Flow 告訴你「網絡上到底發生了什麼」。
這套 ntopng + InfluxDB + Grafana 的組合:
- per‑IP / per‑port / per‑protocol
- 長期歷史
- 自訂 Dashboard
- 高度可視化
- 適合企業 3‑Tier 架構
非常適合作為企業網絡的行為監控基礎。