IP Header Version 版本) 标识了数据包的IP 版本号。长度4bit ,0100 表示IPv4,0110 表示IPv6 。Header Length:(报头长度)表示32位字长的IP报头长度。单位为32bit(4字节),长度4bit。报头长度的值=IP头部长度(bit)/(8*4)。由于可选项字段的长度会变化,所以最小是20字节(可选项长度为0),最长可表示的报头长度为“1111”,即60(15*4=60)字节。 Type of Service 服务类型,ToS) 用来指定特殊的数据包处理方式。长度8bit 。旧时,这个字段由两部分组成:Precedence和ToS(优先级和ToS)。 被定义为PPPDTRC0,PPP为优先级,取值越大越重要 000 路由选择 (Routine) 001 优先级(Priority) 010 立即的发送(Immediate) 011 火速 (Flash) 100 火速覆盖 (FlashOverride) 101 紧急 (CRI/TIC/ECP) 110 网间控制(Internetwork Control) 111 网络控制 (NetworkControl) D 时延: 0:普通 1:延迟尽量小 T 吞吐量: 0:普通 1:流量尽量大 R 可靠性: 0:普通 1:可靠性尽量大 M 传输成本: 0:普通 1:成本尽量小 0 最后一位被保留,恒定为0 被重新定义后,这个字段由两部分组成:DSCP(区分服务代码点)和(显示拥塞通知)ECN。 开始的6bit位构成了DSCP(DiffServCode Point)。 ECN(Explicit Congestion Notification,显示拥塞通知),2bit,某些路由器用来支持显式拥塞通知的,当它支持这个特性时,可以用拥塞信号(ECN=11)。 Total Length IP 包总长) ,长度16bit 。以字节为单位计算的IP 包的长度 ( 包括头部和数据) 。包括IP 报头,IP 数据包有效荷载=TotalLength-Header Length 。最大用十进制表示为65535 字节。 Identifier 标识符) 长度16bit 。该字段和Flags 和FragmentOffest 字段联合使用,对较大的上层数据包进行分段(fragment )操作。路由器将一个包拆分后,所有拆分开的小包被标记相同的值,以便目的端设备能够区分哪个包属于被拆分开的包的一部分。被分段的数据包不会在数据链路的另一端被重组,而是一直保持分段状态,直到到达最终目的地时才会被重组。 Flag 标记) 长度3bit 。该字段第一位不使用,为0 。第二位是DF 位(DoNotFragment ),DF 位设为1 时表明路由器不能对该上层数据包分段。如果一个上层数据包无法在不分段的情况下进行转发,则路由器会丢弃该上层数据包并返回一个错误信息。第三位是MF 位(More Fragment) ,当路由器对一个上层数据包分段,则路由器会在最后一个分段的IP 包的包头中将MF 位设为0, 其余IP 包的包头中将MF 设为1 。以便接收者直到收到MF 位为0 为止。 Bit 0: reserved, must be zero Bit 1: (DF) 0= May Fragment, 1 = Don't Fragment. Bit 2: (MF) 0 = Last Fragment, 1 = MoreFragments. Fragment Offset 分段偏移) 长度13bit 。该字段对包含分段的上层数据包的IP 包赋予序号。由于IP 包在网络上传送的时候不一定能按顺序到达,这个字段保证了目标路由器在接受到IP 包之后能够还原分段的上层数据包。到某个包含分段的上层数据包的IP包在传送时丢失,则整个一系列包含分段的上层数据包的IP包都会被要求重传。 所以,可能会造成时延不成比例,也可能会由于重传整个数据包加重网络拥塞。 TTL(Time To Live) 生存时间) 长度8bit 。当IP 包进行传送时,先会对该字段赋予某个特定的值。实际上TTL 用来表示跳数。常见的值为15 和32 ,但是建议的缺省值是64 。 trace命令使用的就是TTL字段。是先把TTL置1,第一台路由器收到数据包时,TTL变为0,这时会回送一个错误信息。源收到错误信息,将TTL值增1,再向下发送。以此类推,直到发现目的地。这样,沿途的所有路由器就会被标识出来。 Protocol 协议) 长度8bit 。标识了上层协议。 协议号 | | | | | | | | | | | | | | | | | IGRP(Cisco Internet 网关路由选择协议) | | |
Header Checksum 头部校验和) 长度16bit 。是一个16 位二进制补码和,由数据包发送者计算。用来做IP 头部的正确性检测,但不包含数据部分。因为每个路由器要改变TTL 的值, 所以路由器会为每个通过的数据包重新计算这个值。 Source Address 源地址) 发送者IP 地址。 Destination Address 目的地址) 数据包目的IP 地址。 Options 可选项) 这是一个可变长的字段。该字段属于可选项,主要用于测试,由起源设备根据需要改写。可选项目包含以下内容: 松散源路由(Loosesource routing):给出一连串路由器接口的IP地址。IP包必须沿着这些IP地址传送,但是允许在相继的两个IP地址之间跳过多个路由器。 严格源路由(Strictsource routing):给出一连串路由器接口的IP地址。IP包必须沿着这些IP地址传送,如果下一跳不在IP地址表中则表示发生错误。 路由记录(Recordroute):当IP包离开每个路由器的时候记录路由器的出站接口的IP地址。 时间戳(Timestamps):当IP包离开每个路由器的时候记录时间。 可用扩展ping实现。 Padding 填充项) 因为IP 包头长度(HeaderLength )部分的单位为32bit ,所以IP 包头的长度必须为32bit 的整数倍。因此,在可选项后面,IP 协议会填充若干个0 ,以达到32bit 的整数倍。 实验: R1扩展ping: 1)测试数据包的分段 R1#ping Protocol [ip]: Target IP address: 202.101.23.3 Repeat count [5]: 100 Datagram size [100]: 3000 Timeout in seconds [2]: Extended commands [n]: y Source address or interface: 202.101.12.1 Type of service [0]: Set DF bit in IP header? [no]: Validate reply data? [no]: Data pattern [0xABCD]: Loose, Strict, Record, Timestamp,Verbose[none]: Sweep range of sizes [n]: Type escape sequence to abort. Sending 100, 3000-byte ICMP Echos to202.101.23.3, timeout is 2 seconds: Packet sent with a source address of202.101.12.1 !!...!!!...!.!....!..!..!!...!!!!!.!!.!.!..!!..!!.!!..!.!.!.....!....! !...!!....!!!.!.!!!.!.!!..!.!. Success rate is 46 percent (46/100),round-trip min/avg/max = 28/176/344 ms 抓包: IP数据包被分为3个: 第一个抓包信息: 第二个抓包信息: 第三个抓包信息: 可观察到,IP数据包被分为3个分段。分段偏移标识了它们的顺序。ICMP的TTL被设置为了255,经过R1变为了254。只有最后的flag位的MF为0,表示结束。而他们的标识符都为134。 2)将DF位置1,不允许分段。 R1#ping Protocol [ip]: Target IP address: 202.101.23.3 Repeat count [5]: 10 Datagram size [100]: Timeout in seconds [2]: Extended commands [n]: y Source address or interface: 202.101.12.1 Type of service [0]: SetDF bit in IP header? [no]: y Validate reply data? [no]: Data pattern [0xABCD]: Loose, Strict, Record, Timestamp,Verbose[none]: Sweep range of sizes [n]: Type escape sequence to abort. Sending 10, 100-byte ICMP Echos to202.101.23.3, timeout is 2 seconds: Packet sent with a source address of202.101.12.1 Packet sent with the DF bit set .!!!!!!!!! Success rate is 90 percent (9/10),round-trip min/avg/max = 28/62/152 ms 如果数据包不需要分段,则可以ping通,抓包为: 所以,如果说DF位被置1,则flag位只能为0x02 数据包大小大于1480,则会被分段,则不会产生IGMP包。 3)为其设置松散路由 R1#ping Protocol [ip]: Target IP address: 202.101.23.3 Repeat count [5]: 2 Datagram size [100]: Timeout in seconds [2]: Extended commands [n]: y Source address or interface: 202.101.12.1 Type of service [0]: Set DF bit in IP header? [no]: Validate reply data? [no]: Data pattern [0xABCD]: Loose, Strict, Record, Timestamp,Verbose[none]: l Source route: 202.101.23.2 Loose, Strict, Record, Timestamp, Verbose[LV]: Sweep range of sizes [n]: Type escape sequence to abort. Sending 2, 100-byte ICMP Echos to202.101.23.3, timeout is 2 seconds: Packet sent with a source address of202.101.12.1 Packet has IP options: Totaloption bytes= 7, padded length=8 Loose source route: <*> (202.101.23.2) Reply to request 0 (244 ms). Received packet has options Total option bytes= 8, padded length=8 Loose source route: (202.101.12.2) <*> Endof list Reply to request 1 (176 ms). Received packet has options Total option bytes= 8, padded length=8 Loose source route: (202.101.12.2) <*> Endof list Success rate is 100 percent (2/2),round-trip min/avg/max = 176/210/244 ms Verbose模式:它要ping命令除了打印ECHO-RESPONSE数据包之外,还打印其它所有返回的ICMP数据包。 0x83:Type=131 0x07:LSR长度07 0x04:pointer为04 0xca 65 17 03:地址为202.101.23.2 0x00:End of Option List,为00。 Option:
Option | | | LSR -- Loose Source Route | | | | | | SSR -- Strict Source Route |
4)为其设置为严格源路由 1.提供正确的严格源路由 R1#ping Protocol [ip]: Target IP address: 202.101.23.3 Repeat count [5]: 2 Datagram size [100]: Timeout in seconds [2]: Extended commands [n]: y Source address or interface: 202.101.12.1 Type of service [0]: Set DF bit in IP header? [no]: Validate reply data? [no]: Data pattern [0xABCD]: Loose,Strict, Record, Timestamp, Verbose[none]: S Sourceroute: 202.101.12.2 202.101.23.2 Loose, Strict, Record, Timestamp,Verbose[SV]: Sweep range of sizes [n]: Type escape sequence to abort. Sending 2, 100-byte ICMP Echos to202.101.23.3, timeout is 2 seconds: Packet sent with a source address of202.101.12.1 Packet has IP options: Total option bytes= 11, padded length=12 Strict source route: <*> (202.101.12.2) (202.101.23.2) Reply to request 0 (276 ms). Received packet has options Total option bytes= 12, padded length=12 Strict source route: (202.101.23.3) (202.101.12.2) <*> Endof list Reply to request 1 (44 ms). Received packet has options Total option bytes= 12, padded length=12 Strictsource route: (202.101.23.3) (202.101.12.2) <*> Endof list Success rate is 100 percent (2/2),round-trip min/avg/max = 44/160/276 ms 抓包: 0x89:137=SSR 0x0b:SSR大小11字节 0x04:pointer为4 0xca 65 17 02 ca 65 17 03表示严格源路由为202.101.23.2和202.101.23.3 自己直连网段的将不写入IP数据包,但会将目标地址写入。 0x00:End of List 2.提供错误的严格源路由 R1#ping Protocol [ip]: Target IP address: 202.101.23.3 Repeat count [5]: 2 Datagram size [100]: Timeout in seconds [2]: Extended commands [n]: y Source address or interface: 202.101.12.1 Type of service [0]: Set DF bit in IP header? [no]: Validate reply data? [no]: Data pattern [0xABCD]: Loose, Strict, Record, Timestamp,Verbose[none]: S Source route: 202.101.23.2 Loose, Strict, Record, Timestamp,Verbose[SV]: Sweep range of sizes [n]: Type escape sequence to abort. Sending 2, 100-byte ICMP Echos to202.101.23.3, timeout is 2 seconds: Packet sent with a source address of202.101.12.1 Packet has IP options: Total option bytes= 7, padded length=8 Strict source route: <*> (202.101.23.2) Request 0 timed out Request 1 timed out Success rate is 0 percent (0/2) 本地检查,不符合严格源路由,则不发送echo request包。 5)Record Route R1#ping Protocol [ip]: Target IP address: 202.101.23.3 Repeat count [5]: 2 Datagram size [100]: Timeout in seconds [2]: Extended commands [n]: y Source address or interface: Type of service [0]: Set DF bit in IP header? [no]: Validate reply data? [no]: Data pattern [0xABCD]: Loose, Strict, Record, Timestamp,Verbose[none]: R Number of hops [ 9 ]: 2 Loose, Strict, Record, Timestamp,Verbose[RV]: Sweep range of sizes [n]: Type escape sequence to abort. Sending 2, 100-byte ICMP Echos to202.101.23.3, timeout is 2 seconds: Packet has IP options: Total option bytes= 11, padded length=12 Record route: <*> (0.0.0.0) (0.0.0.0) Reply to request 0 (236 ms). Received packet has options Total option bytes= 12, padded length=12 Record route: (202.101.12.1) (202.101.23.2) <*> Endof list Reply to request 1 (140 ms). Received packet has options Total option bytes= 12, padded length=12 Record route: (202.101.12.1) (202.101.23.2) <*> Endof list Success rate is 100 percent (2/2),round-trip min/avg/max = 140/188/236 ms 抓包: Request: reply: 0x07:RR=7 0x0b:RR长度12字节 0x0c:pointer为12。 0xca 65 0c 01 ca 65 17 02:202.101.12.1202.101.23.2 0x00:end of option list Pointer. 8 bits. 4 to 255 The pointer into the route data indicatesthe byte which begins the next area to store a route address. The pointer isrelative to this option. 路由数据里的指针表明了哪一个字节开始下一个存储路由地址的区域。指针和这个选项有关。其它时候一般为4。
|