手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux下抓包工具tcpdump使用

[日期:2012-11-29] 来源:Linux社区  作者:gzh0222 [字体: ]

为了弄明白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','││';这些关键字可以组合起来构成强大的组合条件来满足人们的需要,下面举几个例子来说明。

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款