linux下tcpdump命令的使用


一般情況下linux系統會自帶tcpdump工具,如果系統沒有安裝,直接用命令安裝就行了。

安裝命令:yum install -y tcpdump

查看安裝版本命令:tcpdump --help

查看網卡命令:

知道了網卡,就可以使用tcpdump工具針對服務器上的網卡監控、過濾網絡數據。

tcpdump常用命令:

#抓取所有經過 eth0,目的或源地址是 192.168.29.162 的網絡數據
命令:tcpdump -n -i eth0 host 192.168.29.162

# 源地址
命令:tcpdump -i eth1 src host 192.168.29.162
# 目的地址
命令:tcpdump -i eth1 dst host 192.168.29.162

#抓取當前服務器eth0網卡端口8080的網絡數據
命令:tcpdump -n -i eth0 port 8080

#抓取mysql執行的sql語句
命令:tcpdump -i eth1 -s 0 -l -w - dst port 3306 | strings

#抓取mysql通訊的網絡包(cap用wireshark打開)
命令tcpdump -n -nn -tttt -i eth0 -s 65535 'port 3306' -w 20160505mysql.cap

#抓取SMTP 數據
命令:tcpdump -i eth1 'tcp[tcpflags] & tcp-syn != 0 and tcp[tcpflags] & tcp-ack != 0'

#抓取HTTP GET數據,"GET "的十六進制是 47455420
命令:tcpdump -i eth1 'tcp[(tcp[12]>>2):4] = 0x47455420'

#抓取SSH返回,"SSH-"的十六進制是 0x5353482D
命令:tcpdump -i eth1 'tcp[(tcp[12]>>2):4] = 0x5353482D'

#實時抓取端口號8080的GET包,然后寫入GET.log
命令:tcpdump -i eth0 '((port 8080) and (tcp[(tcp[12]>>2):4]=0x47455420))' -nnAl -w /tmp/GET.log

#抓取指定SYN個數,-c 參數指定抓多少個包。
命令:time tcpdump -nn -i eth0 'tcp[tcpflags] = tcp-syn' -c 10

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM