最近Linux redhat 6.5 APP 業務系統,向外大量發送流量,不斷建立tcp連接,目標地址是美國的一個IP,估計被當成肉雞了,比較悲慘,直接飛向IDC機房,防火牆顯示這個APP服務器tcp連接很多每秒10W個,
從服務器上使用命令sar -n DEV 2 10 ,確實出現大量發包的問題,(下邊是正常的,異常的情況eth0txpck/s 10000左右了)

先進行限速或者拔掉網線:
開始之前,先要清除 eth0所有隊列規則
tc qdisc del dev eth0 root 2> /dev/null > /dev/null
1) 定義最頂層(根)隊列規則,並指定 default 類別編號
tc qdisc add dev eth0 root handle 1: htb default 20
tc class add dev eth0 parent 1: classid 1:20 htb rate 2000kbit
(1KB/s = 8KBit/s)
TC命令格式:
tc qdisc [ add | change | replace | link ] dev DEV [ parent qdisc-id | root ] [ handle qdisc-id ] qdisc [ qdisc specific parameters ]
tc class [ add | change | replace ] dev DEV parent qdisc-id [ classid class-id ] qdisc [ qdisc specific parameters ]
tc filter [ add | change | replace ] dev DEV [ parent qdisc-id | root ] protocol protocol prio priority filtertype [ filtertype specific parameters ] flowid flow-id
顯示
tc [-s | -d ] qdisc show [ dev DEV ]
tc [-s | -d ] class show dev DEV tc filter show dev DEV
查看TC的狀態
tc -s -d qdisc show dev eth0
tc -s -d class show dev eth0
刪除tc規則
tc qdisc del dev eth0 root
查看狀態:
top
CPU和MEM都正常,看不出異常的進程。
yum install -y tcpdump
tcpdump -nn
找到大量的IP地址
本機(192.168.35.145)和主機114.114.110.110之間的數據
tcpdump -n -i eth0 host 192.168.35.145 and 114.114.110.110
還有截取全部進入服務器的數據可以使用以下的格式
tcpdump -n -i eth0 dst 192.168.35.145
或者服務器有多個IP 可以使用參數
tcpdump -n -i eth0 dst 192.168.35.145 or 192.168.35.155
我們抓取全部進入服務器的TCP數據包使用以下的格式,大家可以參考下
tcpdump -n -i eth0 dst 192.168.35.145 or 192.168.35.155 and tcp
從本機出去的數據包
tcpdump -n -i eth0 src 192.168.35.145 or 192.168.35.155
tcpdump -n -i eth0 src 192.168.35.145 or 192.168.35.155 and port ! 22 and tcp
或者可以條件可以是or 和 and 配合使用即可篩選出更好的結果。
可以將異常IP加入到/etc/hosts.deny中,或者防火牆設置下
之后安裝個NetHogs
Install Howto:
Download the latest epel-release rpm from (一個是32位、一個是64位連接)
http://dl.fedoraproject.org/pub/epel/6/i386/
http://dl.fedoraproject.org/pub/epel/6/x86_64/
Install epel-release rpm:
# rpm -Uvh epel-release*rpm(記得yum clean all和yum makecache下)
Install nethogs rpm package:
# yum install nethogs
執行nethogs
nethogs
或者
nethogs eth0
如果網卡綁定過nethogs bond0
-------------------------
rpm -Uvh epel-release-6-8.noarch64.rpm
yum clean all
yum makecache
yum install nethogs
nethogs
--------------------------
下圖顯示各進程當前網絡使用情況:

按“m”鍵可以切換到統計視圖,顯示各進程總的網絡使用情況

按“Ctrl+C”或“q”退出監控
使用幫助:
[root@localhost ~]# nethogs --help
nethogs: invalid option -- '-'
usage: nethogs [-V] [-b] [-d seconds] [-t] [-p] [device [device [device ...]]]
-V : 顯示版本信息,注意是大寫字母V.
-d : 延遲更新刷新速率,以秒為單位。默認值為 1.
-t : 跟蹤模式.
-b : bug 狩獵模式 — — 意味着跟蹤模式.
-p : 混合模式(不推薦).
設備 : 要監視的設備名稱. 默認為 eth0
當 nethogs 運行時, 按:
q: 退出
m: 總數和當前使用情況模式之間切換
找到大量發包的進程,之后kill掉,在排查下這個進程是什么程序,文件路徑在哪里,刪除掉異常的文件。
目前問題解決了,觀察一段時間,看看問題是否還會發生,防火牆將公網IP進行了訪問限制,只允許辦公地點訪問,增加安全。

先進行限速或者拔掉網線:
開始之前,先要清除 eth0所有隊列規則
tc qdisc del dev eth0 root 2> /dev/null > /dev/null
1) 定義最頂層(根)隊列規則,並指定 default 類別編號
tc qdisc add dev eth0 root handle 1: htb default 20
tc class add dev eth0 parent 1: classid 1:20 htb rate 2000kbit
(1KB/s = 8KBit/s)
TC命令格式:
tc qdisc [ add | change | replace | link ] dev DEV [ parent qdisc-id | root ] [ handle qdisc-id ] qdisc [ qdisc specific parameters ]
tc class [ add | change | replace ] dev DEV parent qdisc-id [ classid class-id ] qdisc [ qdisc specific parameters ]
tc filter [ add | change | replace ] dev DEV [ parent qdisc-id | root ] protocol protocol prio priority filtertype [ filtertype specific parameters ] flowid flow-id
顯示
tc [-s | -d ] qdisc show [ dev DEV ]
tc [-s | -d ] class show dev DEV tc filter show dev DEV
查看TC的狀態
tc -s -d qdisc show dev eth0
tc -s -d class show dev eth0
刪除tc規則
tc qdisc del dev eth0 root
查看狀態:
top
CPU和MEM都正常,看不出異常的進程。
yum install -y tcpdump
tcpdump -nn
找到大量的IP地址
本機(192.168.35.145)和主機114.114.110.110之間的數據
tcpdump -n -i eth0 host 192.168.35.145 and 114.114.110.110
還有截取全部進入服務器的數據可以使用以下的格式
tcpdump -n -i eth0 dst 192.168.35.145
或者服務器有多個IP 可以使用參數
tcpdump -n -i eth0 dst 192.168.35.145 or 192.168.35.155
我們抓取全部進入服務器的TCP數據包使用以下的格式,大家可以參考下
tcpdump -n -i eth0 dst 192.168.35.145 or 192.168.35.155 and tcp
從本機出去的數據包
tcpdump -n -i eth0 src 192.168.35.145 or 192.168.35.155
tcpdump -n -i eth0 src 192.168.35.145 or 192.168.35.155 and port ! 22 and tcp
或者可以條件可以是or 和 and 配合使用即可篩選出更好的結果。
可以將異常IP加入到/etc/hosts.deny中,或者防火牆設置下
之后安裝個NetHogs
Install Howto:
Download the latest epel-release rpm from (一個是32位、一個是64位連接)
http://dl.fedoraproject.org/pub/epel/6/i386/
http://dl.fedoraproject.org/pub/epel/6/x86_64/
Install epel-release rpm:
# rpm -Uvh epel-release*rpm(記得yum clean all和yum makecache下)
Install nethogs rpm package:
# yum install nethogs
執行nethogs
nethogs
或者
nethogs eth0
如果網卡綁定過nethogs bond0
-------------------------
rpm -Uvh epel-release-6-8.noarch64.rpm
yum clean all
yum makecache
yum install nethogs
nethogs
--------------------------
下圖顯示各進程當前網絡使用情況:

按“m”鍵可以切換到統計視圖,顯示各進程總的網絡使用情況

按“Ctrl+C”或“q”退出監控
使用幫助:
[root@localhost ~]# nethogs --help
nethogs: invalid option -- '-'
usage: nethogs [-V] [-b] [-d seconds] [-t] [-p] [device [device [device ...]]]
-V : 顯示版本信息,注意是大寫字母V.
-d : 延遲更新刷新速率,以秒為單位。默認值為 1.
-t : 跟蹤模式.
-b : bug 狩獵模式 — — 意味着跟蹤模式.
-p : 混合模式(不推薦).
設備 : 要監視的設備名稱. 默認為 eth0
當 nethogs 運行時, 按:
q: 退出
m: 總數和當前使用情況模式之間切換
找到大量發包的進程,之后kill掉,在排查下這個進程是什么程序,文件路徑在哪里,刪除掉異常的文件。
目前問題解決了,觀察一段時間,看看問題是否還會發生,防火牆將公網IP進行了訪問限制,只允許辦公地點訪問,增加安全。