歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux下抓包工具tcpdump使用

Linux下抓包工具tcpdump使用

日期:2017/2/28 14:56:05   编辑:Linux教程

為了弄明白keepalived+lvs是如何交互的,必須學會分析和使用抓包工具進行分析,下面就是對抓包工具的的使用簡單介紹如下,有些部分參考的網上的,如有不對的地方歡迎指正,謝謝!

1.第一種是關於類型的關鍵字主要包括host,net,port

例如: host host 10.10.10.12,指明host 10.10.10.12是一台主機,net 202.0.0.0 指明 202.0.0.0是一個網絡地址,port 80 指明端口號是80。如果沒有指定類型,缺省的類型是host.

[root@platform_c ~]# tcpdump host 10.10.10.12 -n
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
14:47:54.338648 IP 10.10.10.12 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 90, authtype simple, intvl 1s, length 20
14:47:55.339591 IP 10.10.10.12 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 90, authtype simple, intvl 1s, length 20
14:47:55.460784 IP 10.10.10.17.5540 > 10.10.10.12.scp-config: P 990305450:990305578(128) ack 3936126663 win 10281 <nop,nop,timestamp 128715924 4061149870>
14:47:55.461037 IP 10.10.10.12.scp-config > 10.10.10.17.5540: P 1:134(133) ack 128 win 10285 <nop,nop,timestamp 4061151871 128715924>
14:47:55.461090 IP 10.10.10.17.5540 > 10.10.10.12.scp-config: . ack 134 win 10281 <nop,nop,timestamp 128715924 4061151871>
14:47:56.340551 IP 10.10.10.12 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 90, authtype simple, intvl 1s, length 20
14:47:56.682367 arp who-has 10.10.10.12 tell 10.10.10.89
14:47:57.341512 IP 10.10.10.12 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 90, authtype simple, intvl 1s, length 20
14:47:57.461844 IP 10.10.10.17.5540 > 10.10.10.12.scp-config: P 128:256(128) ack 134 win 10281 <nop,nop,timestamp 128717925 40611518

2.第二種是確定傳輸方向的關鍵字主要包括src , dst ,dst or src, dst and src

這些關鍵字指明了傳輸的方向,例如:src 10.10.10.12,指明ip包中源地址是10.10.10.12, dst net 202.0.0.0 指明目的網絡地址是202.0.0.0。如果沒有指明方向關鍵字,則缺省是src or dst關鍵字。

[root@platform_c ~]# tcpdump src 10.10.10.12 -n
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
14:50:48.504155 IP 10.10.10.12 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 90, authtype simple, intvl 1s, length 20
14:50:49.132905 IP 10.10.10.12.21002 > 10.10.10.17.20742: P 1000890141:1000890152(11) ack 1991025729 win 2998
14:50:49.134210 IP 10.10.10.12.21002 > 10.10.10.17.20742: P 11:862(851) ack 209 win 3108
14:50:49.135543 IP 10.10.10.12.21002 > 10.10.10.17.20742: P 862:873(11) ack 230 win 3108
14:50:49.504790 IP 10.10.10.12 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 90, authtype simple, intvl 1s, length 20
14:50:49.548064 IP 10.10.10.12.scp-config > 10.10.10.17.5540: P 3936138234:3936138367(133) ack 990316714 win 10285 <nop,nop,timestamp 4061325974 128890011>
14:50:50.505743 IP 10.10.10.12 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 90, authtype simple, intvl 1s, length 20


3.第三種是協議的關鍵字,主要包括fddi,ip,arp,rarp,tcp,udp等類型。

Fddi指明是在FDDI(分布式光纖數據接口網絡)上的特定的網絡協議,實際上它是"ether"的別名,fddi和ether具有類似的源地址和目的地址,所以可以將fddi協議包當作ether的包進行處理和分析。其他的幾個關鍵字就是指明了監聽的包的協議內容。如果沒有指定任何協議,則tcpdump將會監聽所有協議的信息包。

[root@platform_c ~]# tcpdump tcp port 80 -n
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
14:48:51.852424 IP 10.10.10.12.20278 > 10.10.10.17.http: S 1416876662:1416876662(0) win 14600 <mss 1460,nop,nop,sackOK,nop,wscale 4>
14:48:51.852447 IP 10.10.10.17.http > 10.10.10.12.20278: S 1206855618:1206855618(0) ack 1416876663 win 5840 <mss 1460,nop,nop,sackOK,nop,wscale 4>
14:48:51.852568 IP 10.10.10.12.20278 > 10.10.10.17.http: . ack 1 win 913
14:48:51.852590 IP 10.10.10.12.20278 > 10.10.10.17.http: R 1:1(0) ack 1 win 913

除了這三種類型的關鍵字之外,其他重要的關鍵字如下:gateway, broadcast,less,greater,還有三種邏輯運算,取非運算是'not ' ,'! ',與運算是'and','&&';或運算 是'or','││';這些關鍵字可以組合起來構成強大的組合條件來滿足人們的需要,下面舉幾個例子來說明。

Copyright © Linux教程網 All Rights Reserved