監控每個 IP 的網路封包速率

監控每個 IP 的網路封包速率

我的問題是我收到一份報告稱我的 IP 被用於 DOS 攻擊。問題是我不知道哪台電腦被感染並且攻擊不再活躍。

是否有適用於我的路由器(運行 fedora)的簡單 Linux 工具,它可以計算每個本地 IP 的封包速率,如果超過我選擇的常數,它將啟動我的 shell 腳本?

注意我也對從本機產生的資料包感興趣(以防伺服器本身被駭客攻擊)。

答案1

所以我想出了一個使用 iptables 的解決方案:

# create new chain for every local ip we wanna monitor
iptables -N ip10     
# forward traffic from monitored IP to it's chain "ip10"
iptables -A FORWARD -i myLan -s 192.168.2.10 -o myWan -j ip10  
# trafic from other IP's we trusted we just accept
iptables -A FORWARD -i myLan -o myWan -j ACCEPT
# here we have even better thing than I asked for 
# we can ban the DOS attack before it gets out
# in following line we set maximum 100 packet per second
iptables -A ip10 -m limit --limit 100/s --limit-burst 300 -j ACCEPT
# here we can directly log if above limit is breached
# log will be in /var/log/message and it will contains IP src+dst, src mac and other info
# note limit 3 msg per minute is important to not have too big log file
iptables -A ip10 -m limit --limit 3/m --limit-burst 10 -j LOG --log-prefix 'mylog:' --log-level 4
# finally packets over limit will be discarded
iptables -A ip10 -j DROP

也可以透過呼叫以下命令來查看從一個 IP 發送的資料包及其大小:

iptables -L ip10 -vxn

如果您有興趣,您需要在某些腳本中執行此操作並將其重新計數為每秒資料包

請注意,要監視伺服器本身,您需要對鏈執行類似的方法

iptables -A OUTPUT

在 Fedora 18 上進行了測試。

答案2

這是一個典型的場景網路串流。它將為您提供細分為位址、協定和連接埠的流量歷史數據,您可以在精美的圖表中評估和查看這些數據。

相關內容