【Linux】一步一步学Linux——tcpdump命令(185)
00. 目錄
文章目錄
- 00. 目錄
- 01. 命令概述
- 02. 命令格式
- 03. 常用選項(xiàng)
- 04. 參考示例
- 05. 總結(jié)
- 06. 附錄
01. 命令概述
tcpdump命令是一款sniffer工具,它可以打印所有經(jīng)過(guò)網(wǎng)絡(luò)接口的數(shù)據(jù)包的頭信息,也可以使用-w選項(xiàng)將數(shù)據(jù)包保存到文件中,方便以后分析。
02. 命令格式
格式:tcpdump [選項(xiàng)] [參數(shù)]03. 常用選項(xiàng)
-a:嘗試將網(wǎng)絡(luò)和廣播地址轉(zhuǎn)換成名稱 -c<數(shù)據(jù)包數(shù)目>:收到指定的數(shù)據(jù)包數(shù)目后,就停止進(jìn)行傾倒操作 -d:把編譯過(guò)的數(shù)據(jù)包編碼轉(zhuǎn)換成可閱讀的格式,并傾倒到標(biāo)準(zhǔn)輸出 -dd:把編譯過(guò)的數(shù)據(jù)包編碼轉(zhuǎn)換成C語(yǔ)言的格式,并傾倒到標(biāo)準(zhǔn)輸出 -ddd:把編譯過(guò)的數(shù)據(jù)包編碼轉(zhuǎn)換成十進(jìn)制數(shù)字的格式,并傾倒到標(biāo)準(zhǔn)輸出 -e:在每列傾倒資料上顯示連接層級(jí)的文件頭 -f:用數(shù)字顯示網(wǎng)際網(wǎng)絡(luò)地址 -F<表達(dá)文件>:指定內(nèi)含表達(dá)方式的文件 -i<網(wǎng)絡(luò)界面>:使用指定的網(wǎng)絡(luò)截面送出數(shù)據(jù)包 -l:使用標(biāo)準(zhǔn)輸出列的緩沖區(qū) -n:不把主機(jī)的網(wǎng)絡(luò)地址轉(zhuǎn)換成名字 -N:不列出域名 -O:不將數(shù)據(jù)包編碼最佳化 -p:不讓網(wǎng)絡(luò)界面進(jìn)入混雜模式 -q :快速輸出,僅列出少數(shù)的傳輸協(xié)議信息 -r<數(shù)據(jù)包文件>:從指定的文件讀取數(shù)據(jù)包數(shù)據(jù) -s<數(shù)據(jù)包大小>:設(shè)置每個(gè)數(shù)據(jù)包的大小 -S:用絕對(duì)而非相對(duì)數(shù)值列出TCP關(guān)聯(lián)數(shù) -t:在每列傾倒資料上不顯示時(shí)間戳記 -tt: 在每列傾倒資料上顯示未經(jīng)格式化的時(shí)間戳記 -T<數(shù)據(jù)包類型>:強(qiáng)制將表達(dá)方式所指定的數(shù)據(jù)包轉(zhuǎn)譯成設(shè)置的數(shù)據(jù)包類型 -v:詳細(xì)顯示指令執(zhí)行過(guò)程 -vv:更詳細(xì)顯示指令執(zhí)行過(guò)程 -x:用十六進(jìn)制字碼列出數(shù)據(jù)包資料 -w<數(shù)據(jù)包文件>:把數(shù)據(jù)包數(shù)據(jù)寫(xiě)入指定的文件04. 參考示例
4.1 監(jiān)視網(wǎng)卡上所有流過(guò)的數(shù)據(jù)包
[root@localhost ~]# tcpdump tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on virbr0, link-type EN10MB (Ethernet), capture size 262144 bytes普通情況下,直接啟動(dòng)tcpdump將監(jiān)視第一個(gè)網(wǎng)絡(luò)接口上所有流過(guò)的數(shù)據(jù)包。
4.2 指定網(wǎng)庫(kù)的數(shù)據(jù)包
[root@localhost ~]# tcpdump -i ens33 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes如果不指定網(wǎng)卡,默認(rèn)tcpdump只會(huì)監(jiān)視第一個(gè)網(wǎng)絡(luò)接口
4.3 監(jiān)視指定主機(jī)的數(shù)據(jù)包
[root@localhost ~]# tcpdump host localhost tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on virbr0, link-type EN10MB (Ethernet), capture size 262144 bytes打印所有進(jìn)入或離開(kāi)localhost的數(shù)據(jù)包
4.4 監(jiān)視本地IP的所有數(shù)據(jù)包
[root@localhost ~]# tcpdump host 192.168.12.94 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on virbr0, link-type EN10MB (Ethernet), capture size 262144 bytes截獲所有192.168.12.94 的主機(jī)收到的和發(fā)出的所有的數(shù)據(jù)包
4.5 打印localhost與 itcast 或者與 deng之間通信的數(shù)據(jù)包
[root@localhost ~]# tcpdump host localhost and \(itcast or deng\)4.6 截獲主機(jī)192.168.12.94和主機(jī)192.168.12.95 或192.168.12.96的通信
[root@localhost ~]# tcpdump host 192.168.12.94 and \(192.168.12.95 or 192.168.12.96\) tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on virbr0, link-type EN10MB (Ethernet), capture size 262144 bytes4.7 打印localhost與任何其他主機(jī)之間通信的IP 數(shù)據(jù)包, 但不包括與itcast之間的數(shù)據(jù)包
[root@localhost ~]# tcpdump ip host localhost and not itcast4.8 獲取主機(jī)192.168.12.94除了和主機(jī)192.168.12.2之外所有主機(jī)通信的ip包
[root@localhost ~]# tcpdump ip host 192.168.12.94 and ! 192.168.12.2 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on virbr0, link-type EN10MB (Ethernet), capture size 262144 bytes4.9 截獲主機(jī)localhost發(fā)送的所有數(shù)據(jù)
[root@localhost ~]# tcpdump -i ens33 src host localhost tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes4.10 監(jiān)視所有送到主機(jī)localhost的數(shù)據(jù)包
[root@localhost ~]# tcpdump -i ens33 dst host localhost tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes4.11 監(jiān)視指定主機(jī)和端口的數(shù)據(jù)包
[root@localhost ~]# tcpdump tcp port 22 and host 192.168.12.94 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on virbr0, link-type EN10MB (Ethernet), capture size 262144 bytes4.12 監(jiān)視主機(jī)udp協(xié)議和端口號(hào)為10086
[root@localhost ~]# tcpdump udp port 10086 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on virbr0, link-type EN10MB (Ethernet), capture size 262144 bytes4.13 監(jiān)視指定網(wǎng)絡(luò)的數(shù)據(jù)包
[root@localhost ~]# tcpdump net ucb-ether打印本地主機(jī)與Berkeley網(wǎng)絡(luò)上的主機(jī)之間的所有通信數(shù)據(jù)包。
ucb-ether此處可理解為“Berkeley網(wǎng)絡(luò)”的網(wǎng)絡(luò)地址,此表達(dá)式最原始的含義可表達(dá)為:打印網(wǎng)絡(luò)地址為ucb-ether的所有數(shù)據(jù)包
4.14 打印所有通過(guò)網(wǎng)關(guān)snup的ftp數(shù)據(jù)包
[root@localhost ~]# tcpdump 'gateway snup and (port ftp or ftp-data)'注意:表達(dá)式被單引號(hào)括起來(lái)了,這可以防止shell對(duì)其中的括號(hào)進(jìn)行錯(cuò)誤解析
4.15 打印所有源地址或目標(biāo)地址是本地主機(jī)的IP數(shù)據(jù)包
[root@localhost ~]# tcpdump ip and not net localnet如果本地網(wǎng)絡(luò)通過(guò)網(wǎng)關(guān)連到了另一網(wǎng)絡(luò),則另一網(wǎng)絡(luò)并不能算作本地網(wǎng)絡(luò)。
(如果本地網(wǎng)絡(luò)通過(guò)網(wǎng)關(guān)連到了另一網(wǎng)絡(luò), 則另一網(wǎng)絡(luò)并不能算作本地網(wǎng)絡(luò).(nt: 此句翻譯曲折,需補(bǔ)充).localnet 實(shí)際使用時(shí)要真正替換成本地網(wǎng)絡(luò)的名字)
05. 總結(jié)
06. 附錄
參考:【Linux】一步一步學(xué)Linux系列教程匯總
參考:https://www.cnblogs.com/ggjucheng/archive/2012/01/14/2322659.html
總結(jié)
以上是生活随笔為你收集整理的【Linux】一步一步学Linux——tcpdump命令(185)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【Linux】一步一步学Linux——a
- 下一篇: 【Linux】一步一步学Linux——i