關於 PHP, Linux, Open Source 及個人生活記載的網誌。
RSS icon
  • netstat 檢查不尋常連線

    Posted on February 9th, 2010 Sam Tang No comments

    netstat 是一個十分好用的網絡管理工具,而其中一個用途是查看不尋常連線,例如當一個 IP 發送大量連線到伺服器,那麼伺服器很大機會是否遭受 DoS 或 DDoS 攻擊。

    以下是一些實用的 netstat 語法,可以檢查主機的連線數量:

    netstat -na
    顯示主機上所有已建立的連線。

    netstat -an | grep :80 | sort
    顯示所有 port 80 的連線,並把結果排序。

    netstat -n -p|grep SYN_REC | wc -l
    列出主機上有多少個 SYNC_REC,一般上這個數字應該相當低。

    netstat -n -p | grep SYN_REC | sort -u
    同樣是列出 SYNC_REC,但不只列出數字,而是將每個 SYNC_REC 的連線列出。

    netstat -n -p | grep SYN_REC | awk ‘{print $5}’ | awk -F: ‘{print $1}’
    列出發送 SYNC_REC 的所有 ip 地址。

    netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n
    計算每一個 ip 在主機上建立的連線數量。

    netstat -anp |grep ‘tcp\|udp’ | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n
    列出從 TCP 或 UDP 連線到主機的 ip 的數量。

    netstat -ntu | grep ESTAB | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -nr
    列出每個 ip 建立的 ESTABLISHED 連線數量。

    netstat -plan|grep :80|awk {‘print $5′}|cut -d: -f 1|sort|uniq -c|sort -nk 1
    列出每個 ip 建立的 port 80 連線數量。


    Leave a reply

    *
    To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
    Click to hear an audio file of the anti-spam word