|
为了看清楚 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 字节。 |
|