曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 7277|回复: 0
打印 上一主题 下一主题

用 tcpdump 看 ARP 请求

[复制链接]

4918

主题

5880

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34395
跳转到指定楼层
楼主
发表于 2009-12-15 00:24:47 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
为了看清楚 ARP 的运作过程,我们执行 telnet 命令与无效的服务器连接。实验环境是这样的:
两台分别装有 Ubuntu 9.10 和 CentOS 5.2 linux 的机子通过路由器连接。CentOS 一端做 telnet 服务器。这里需要注意的是,telnet 服务器需要编辑 /etc/xinetd.d/ekrb5-telnet 文件,使其中的 disable=yes ,这样才能使客户端连接到服务器上。

客户机的 IP 是:192.168.2.100 ,MAC 地址是: 00:1b:11:b5:a9:fe
服务器的 IP 是:192.168.2.101 ,MAC 地址是: 00:c0:9f:8d:06:77

首先,在服务器上执行 tcpdump 命令:
tcpdump -e host 192.168.2.101

现在在客户机上连接服务器:
beyes@beyes-groad:~$ telnet 192.168.2.101
Trying 192.168.2.101...
Connected to 192.168.2.101.
Escape character is '^]'.
^]

telnet> quit
Connection closed.
这时候,可以看到服务器端 tcpdump 截获了相应的通讯数据包并打印出来:
[root@localhost beyes]# /usr/sbin/tcpdump -e host 192.168.2.101
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes

22:32:14.868651 00:1b:11:b5:a9:fe (oui Unknown) > Broadcast, ethertype ARP (0x0806), length 60: arp who-has 192.168.2.101 tell 192.168.2.100

22:32:35.210733 00:c0:9f:8d:06:77 (oui Unknown) > 00:1b:11:b5:a9:fe (oui Unknown), ethertype ARP (0x0806), length 42: arp reply 192.168.2.101 is-at 00:c0:9f:8d:06:77 (oui Unknown)

22:32:14.869184 00:1b:11:b5:a9:fe (oui Unknown) > 00:c0:9f:8d:06:77 (oui Unknown), ethertype IPv4 (0x0800), length 74: 192.168.2.100.46240 > 192.168.2.101.telnet: S 1784537691:1784537691(0) win 5840 <mss 1460,sackOK,timestamp 2672563 0,nop,wscale 6>

22:32:14.869271 00:c0:9f:8d:06:77 (oui Unknown) > 00:1b:11:b5:a9:fe (oui Unknown), ethertype IPv4 (0x0800), length 74: 192.168.2.101.telnet > 192.168.2.100.46240: S 974142073:974142073(0) ack 1784537692 win 5792 <mss 1460,sackOK,timestamp 6316065 2672563,nop,wscale 4>

22:32:14.869839 00:1b:11:b5:a9:fe (oui Unknown) > 00:c0:9f:8d:06:77 (oui Unknown), ethertype IPv4 (0x0800), length 66: 192.168.2.100.46240 > 192.168.2.101.telnet: . ack 1 win 92 <nop,nop,timestamp 2672565 6316065>

22:32:14.869946 00:1b:11:b5:a9:fe (oui Unknown) > 00:c0:9f:8d:06:77 (oui Unknown), ethertype IPv4 (0x0800), length 93: 192.168.2.100.46240 > 192.168.2.101.telnet: P 1:28(27) ack 1 win 92 <nop,nop,timestamp 2672565 6316065>

22:32:14.869976 00:c0:9f:8d:06:77 (oui Unknown) > 00:1b:11:b5:a9:fe (oui Unknown), ethertype IPv4 (0x0800), length 66: 192.168.2.101.telnet > 192.168.2.100.46240: . ack 28 win 362 <nop,nop,timestamp 6316066 2672565>

22:32:14.876638 00:c0:9f:8d:06:77 (oui Unknown) > Broadcast, ethertype ARP (0x0806), length 42: arp who-has 192.168.2.1 tell 192.168.2.101

8 packets captured
23 packets received by filter
0 packets dropped by kernel
22:32:14.868651 00:1b:11:b5:a9:fe (oui Unknown) > Broadcast,ethertype ARP (0x0806), length 60: arp who-has 192.168.2.101 tell192.168.2.100
上面,Broadcast 是广播地址(ff:ff:ff:ff:ff:ff),电缆上的每个以太网接口都要接收这个数据帧并对它进行处理 -- 如果查看其中的访问信息,如果不是自己的,则丢弃。
ethertype ARP (0x0806)
表示帧的类型字段值是 0x0806,说明此帧是一个 ARP 请求或回答。
length 60
60 表示以太网帧的长度。由于 ARP 请求或回答的数据帧长都是 42 字节 (28 字节的 ARP 数据,14 字节的以太网帧头),因此,每一帧都必须假如填充字符以达到以太网的最小长度要求:60 字节。这 60 个字节包含 14 字节的以太网帧头,但不包括 4 个字节的以太网帧尾。以太网帧结构如下所示:
以太网首部(14字节)
IP首部(20字节)
TCP首部(20字节)
应用数据
以太网尾部(4字节)
大多数的设备驱动程序或接口卡会自动地用填充字符把以太网数据帧填充到最小长度。

22:32:35.210733 00:c0:9f:8d:06:77 (oui Unknown) > 00:1b:11:b5:a9:fe(oui Unknown), ethertype ARP (0x0806), length 42: arp reply192.168.2.101 is-at 00:c0:9f:8d:06:77 (oui Unknown)
这是服务器对客户机的应答。这里的 ARP 数据帧并没有填充到 60 个字节,而是保持 42 字节。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2025-5-5 05:39 , Processed in 0.076147 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表