CN_@IP协议IP地址@IP首部@IPv4@地址分类@私有地址@NAT@单播地址@组播地址@广播地址

IP协议

IP数据报(Packet structure)

  • IP协议当前有两个版本在运行

  • 目前来看IP数据报默认指的是IPv4数据报,将来有IPv6取代

IPv4分组的格式

  • IPv4 - Wikipedia

  • 一个IP分组由首部和数据部分组成。

    • 首部固定部分:首部前一部分的长度固定,共20B,
      • 是所有IP分组必须具有的。
    • 首部固定部分的后面是一些可选字段,其长度可变,用来提供错误检测安全等机制
  • IP数据报文头部的结构是体现IP分组的核心

  • 其中,固定部分又是核心中的核心(共占有20B)(80bit)

  • 在这里插入图片描述

Header

  • The IPv4 packet header consists of 14 fields, of which 13 are required.

    • The 14th field is optional and aptly named: options.
    • The fields in the header are packed with the most significant byte first (big endian), and for the diagram and discussion, the most significant bits are considered to come first (MSB 0 bit numbering).
    • The most significant bit is numbered 0, so the version field is actually found in the four most significant bits of the first byte, for example.
  • 在这里插入图片描述

  • Version

    • The first header field in an IP packet is the four-bit version field. For IPv4, this is always equal to 4.
  • Internet Header Length (IHL)

    • The IPv4 header is variable in size due to the optional 14th field (options). The IHL field contains the size of the IPv4 header; it has 4 bits that specify the number of 32-bit words in the header. The minimum value for this field is 5,[35] which indicates a length of 5 × 32 bits = 160 bits = 20 bytes. As a 4-bit field, the maximum value is 15; this means that the maximum size of the IPv4 header is 15 × 32 bits = 480 bits = 60 bytes.
  • Differentiated Services Code Point (DSCP)

  • Explicit Congestion Notification (ECN)

    • This field is defined in RFC 3168 and allows end-to-end notification of network congestion without dropping packets. ECN is an optional feature available when both endpoints support it and effective when also supported by the underlying network.
  • Total Length

    • This 16-bit field defines the entire packet size in bytes, including header and data. The minimum size is 20 bytes (header without data) and the maximum is 65,535 bytes. All hosts are required to be able to reassemble datagrams of size up to 576 bytes, but most modern hosts handle much larger packets. Links may impose further restrictions on the packet size, in which case datagrams must be fragmented. Fragmentation in IPv4 is performed in either the sending host or in routers. Reassembly is performed at the receiving host.
  • Identification

    • This field is an identification field and is primarily used for uniquely identifying the group of fragments of a single IP datagram. Some experimental work has suggested using the ID field for other purposes, such as for adding packet-tracing information to help trace datagrams with spoofed source addresses,[36] but RFC 6864 now prohibits any such use.
  • Flags

    • A three-bit field follows and is used to control or identify fragments. They are (in order, from most significant to least significant):

    • bit 0: Reserved; must be zero.[b]

    • bit 1: Don’t Fragment (DF)

    • bit 2: More Fragments (MF)

    • If the DF flag is set, and fragmentation is required to route the packet, then the packet is dropped. This can be used when sending packets to a host that does not have resources to perform reassembly of fragments. It can also be used for path MTU discovery, either automatically by the host IP software, or manually using diagnostic tools such as ping or traceroute.

    • For unfragmented packets, the MF flag is cleared. For fragmented packets, all fragments except the last have the MF flag set. The last fragment has a non-zero Fragment Offset field, differentiating it from an unfragmented packet.

  • Fragment offset

    • This field specifies the offset of a particular fragment relative to the beginning of the original unfragmented IP datagram. The fragmentation offset value for the first fragment is always 0. The field is 13 bits wide, so that the offset can be from 0 to 8191 (from (20 –1) to (213 – 1)). Fragments are specified in units of 8 bytes, which is why fragment length must be a multiple of 8.[37] Therefore, the 13-bit field allows a maximum offset of (213 – 1) × 8 = 65,528 bytes, with the header length included (65,528 + 20 = 65,548 bytes), supporting fragmentation of packets exceeding the maximum IP length of 65,535 bytes.
  • Time to live (TTL)

    • An eight-bit time to live field limits a datagram’s lifetime to prevent network failure in the event of a routing loop. It is specified in seconds, but time intervals less than 1 second are rounded up to 1. In practice, the field is used as a hop count—when the datagram arrives at a router, the router decrements the TTL field by one. When the TTL field hits zero, the router discards the packet and typically sends an ICMP time exceeded message to the sender.

    • The program traceroute sends messages with adjusted TTL values and uses these ICMP time exceeded messages to identify the routers traversed by packets from the source to the destination.

  • Protocol

    • This field defines the protocol used in the data portion of the IP datagram. IANA maintains a list of IP protocol numbers as directed by RFC 790.
  • Header checksum

    • The 16-bit IPv4 header checksum field is used for error-checking of the header. When a packet arrives at a router, the router calculates the checksum of the header and compares it to the checksum field. If the values do not match, the router discards the packet. Errors in the data field must be handled by the encapsulated protocol. Both UDP and TCP have separate checksums that apply to their data.

    • When a packet arrives at a router, the router decreases the TTL field in the header. Consequently, the router must calculate a new header checksum.

    • The checksum field is the 16 bit one’s complement of the one’s complement sum of all 16 bit words in the header. For purposes of computing the checksum, the value of the checksum field is zero.

  • Source address

  • Destination address

    • This 32-bit field is the IPv4 address of the receiver of the packet. As with the source address, this may be changed in transit by a network address translation device.
  • Options

重要字段

  • IP首部的部分重要字段含义如下:

  • 1)版本。

    • 指P协议的版本,目前广泛使用的版本号为4.
  • 2)首部长度。

    • 占4位,可以表示的最大十进制数是15。
      • 以32位(4B)为基本计量单位,首部最大值为60B(15×4B)。
    • 最常用的首部长度是20B(固定部分)
      • 此时不使用任何选项(即可选字段)。
  • 3)总长度。

    • 占16位。
    • 指首部和数据之和的长度,单位为字节,因此数据报的最大长度为 2 16 2^{16} 216-1=65535B。
    • 以太网帧的最大传送单元(MTU)为1500B,
      • 因此当一个IP数据报封装成帧时,数据报的总长度(首部加数据)一定不能超过下面的数据链路层的MTU值
  • 4)标识。

    • 占16位。
    • 它是一个计数器,每产生一个数据报就加1,并赋值给标识字段。
    • 但它并不是“序号”(因为P是无连接服务)。
    • 当一个数据报的长度超过网络的MTU时,必须分片,此时每个数据报片都复制一次标识号,以便能正确重装成原来的数据报
  • 5)标志。

    • 占3位。
    • 标志字段的最低位为MF,
      • MF=1表示后面还有分片,
      • MF=0表示最后一个分片。
    • 标志字段中间的一位是DF,
      • 只有当DF=0时才允许分片。
  • 6)片偏移。

    • 占13位。
    • 它指出较长的分组在分片后,某片在原分组中的相对位置
    • 片偏移以8个字节为偏移单位。除最后一个分片外,每个分片的长度一定是8B的整数倍。
  • 7)生存时间(TTL)。

    • 占8位。
    • 数据报在网络中可通过的路由器数的最大值,标识分组在网络中的寿命,以确保分组不会永远在网络中循环。
    • 路由器在转发分组前,先把TTL减1.
    • 若TTL被减为0,则该分组必须丢弃。
  • 8)协议。

    • 占8位。
    • 指出此分组携带的数据使用何种协议,即分组的数据部分应上交给哪个协议进行处理,如TCP;UDP等。
      • 值为6表示TCP,
      • 值为I7表示UDP.
  • 9)首部校验和。

    • 占16位。
    • 首部校验和只校验分组的首部,而不校验数据部分。
  • 10)源地址字段。

    • 占4B,标识发送方的P地址。
  • 11)目的地址字段。

    • 占4B,标识接收方的P地址。

Note:

  • 在IP数据报首部中有三个关于长度的标记
    • 首部长度;总长度;片偏移,基本单位分别为4B;1B;8B(需要记住)。
    • 熟悉IP数据报首部的各个字段的意义和功能,但不需要记忆IP数据报的首部

IP数据报分片

  • 一个链路层数据报能承载的最大数据量称为最大传送单元(MTU)。
  • 因为IP数据报被封装在链路层数据报中,因此链路层的MTU严格地限制着IP数据报的长度,而且在IP数据报的源与目的地路径上的各段链路可能使用不同的链路层协议,有不同的MTU。
  • 例如,以太网的MTU为1500B,而许多广域网的MTU不超过576B。
    • 当IP数据报的总长度大于链路MTU时,就需要将IP数据报中的数据分装在多个较小的IP数据报中
    • 这些较小的数据报称为

IP数据报分片案例🎈

  • 原始数据报首部被复制为各数据报片的首部,但必须修改有关字段的值。

  • 例如:

    • 设:
      • 一数据报的总长度为 3820 字节,其数据部分的长度为 3800 字节(使用固定首部)
      • 需要分片为长度不超过 1420 字节的数据报片。
    • 因固定首部长度为 20 字节,因此每个数据报片的数据部分长度不能超
      过 1400 字节。
    • 于是分为 3 个数据报片,其数据部分的长度分别为 1400、1400 和1000 字节。
      在这里插入图片描述
  • IP数据报首部中与分片有关的字段中的数值

总长度标识数据部分长度分组/分片内字节范围MFDF片偏移🎈
原始数据报38201234538000$\sim$3799000
数据报片114201234514000$\sim$1399100(0/8=0)
数据报片214201234514001400$\sim$279910175(1400/8=175)
数据报片310201234510002800$\sim$379900350(280/8=350)

MTU的大小不总是可以被充分利用

  • 若路由器向MTU=800B的链路转发一个总长度为1580B的IP数据报(首部长度为20B)时,进行了分片,且每个分片尽可能大,则第2个分片的总长度字段和MF标志位的值分别是()
    • A.796,0
      B.796,1
      C.800,0
      D.800,1
  • 分析:
    • 链路层MTU=800B
    • IP分组首部长20B
    • 理论字节数上限为800-20=780B
      • 但是,片偏移以8个字节为偏移单位,因此除最后一个分片,其他每个分片的数据部分长度都是8B的整数倍
      • 这句话很重要
      • 意味着,MTU的总容量不总是可以被充分利用(实际上限比MTU更小)
      • 780%8=4(商为97;我们只关心余数是否为0,如果不是,那么MTU容量不能够别充分利用)
    • 所以,最大IP分片的数据部分长度为776(=800-4)B
    • 总长度1580B的IP数据报中,数据部分占1560B, ( ⌈ 1560 B / 776 B ⌉ ) = 3 (\lceil{1560B/776B}\rceil)=3 (1560B/776B)=3,需要分成3片
    • 故第2个分片的总长度字段为796,MF为1(表示还有后续的分片)。

网络中继系统(设备)

  • 将网络互相连接起来要使用一些中间设备。

    • 中间设备又称为中间系统中继 (relay)系统
  • 有以下五种不同的中间设备:

    • 物理层中继系统:转发器 (repeater)

      • 转发器

        • 中继器

          • 数字信号
        • 放大器

          • 模拟信号
      • 数据链路层中继系统:交换机(switcher)/网桥/桥接器 (bridge)

        • 网桥和路由器的混合物:桥路器 (brouter)。
    • 网络层中继系统:路由器 (router)。

    • 网络层以上的中继系统:网关 (gateway)。

IP地址🎈

  • IP 地址就是给每个连接在互联网上的主机(或路由器)分配一个在全世界范围是唯一的 32 位的标识符。
  • 从 IP 地址的结构来看,IP 地址并不仅仅指明一台主机,而是还指明了主机所连接到的网络
  • IP 地址现在由互联网名字和数字分配机构ICANN (Internet Corporation for Assigned Names and Numbers)进行分配。

IP 地址的编址方法

  • 分类的 IP 地址。

    • 这是最基本的编址方法,在1981年就通过了相应的标准协议。
  • 子网的划分。

    • 这是对最基本的编址方法的改进,其标准[RFC 950]在1985年通过。
  • 构成超网。

    • 这是比较新的无分类编址方法。1993年提出后很快就得到推广应用。

IPv4地址的点分十进制表示法🎈

  • 8位一组@点分十进制IP地址表示法
  • 机器中存放的 IP 地址是 32 位二进制代码
    • 例如:10000000000010110000001100011111
  • 每 8 位为一组 ,也就是,每个8位字节(Octet)一个分组
    • 10000000 00001011 00000011 00011111
  • 将每 8 位的二进制数转换为十进制数
    • 128 11 3 31
  • 采用点分十进制记法则进一步提高可读性
    • 128.11.3.31

非法地址(错误地址)

  • 比如点分十进制出现了256或者更大的地址
    • 211.256.1.1
  • 最大只有255🎈

早期分类的IP🎈

  • 各类 IP 地址的网络号字段和主机号字段

    • 这种两级的 IP 地址可以记为:
      • IP 地址 ::= { <网络号>, <主机号>}

      • 符号“::=”表示“定义为”

  • 地址类别网络号位数前缀前缀位数后缀(理论)后缀位数范围主机号主机号位数范围
    A801 0 ∼ 2 7 − 1 0\sim{2^7}-1 02717 0 ∼ 2 24 − 1 0\sim{2^{24}}-1 0224124
    B16102 0 ∼ 2 14 − 1 0\sim{2^{14}}-1 0214114 0 ∼ 2 16 − 1 0\sim{2^{16}}-1 0216116
    C241103 0 ∼ 2 21 − 1 0\sim{2^{21}}-1 0221121 0 ∼ 2 8 − 1 0\sim{2^{8}}-1 02818
    D1110
    E1111
    • 最小n位数r进制数为 r n − 1 r^{n-1} rn1
      • 或者说, r n r^{n} rn是最小n+1位数r进制数
    • 最大n位数r进制数为 r n − 1 r^n-1 rn1
      • 最大n位2进制数: 2 n − 1 2^n-1 2n1
      • 例如,最大2位二进制数 11 11 11,可以符合 2 2 − 1 = 3 = 1 1 2 2^2-1=3=11_2 221=3=112
    • D类地址作为多播地址(组播地址)
    • E类地址保留今后使用
  • 网络号(net-id)

    • 前缀(prefix)
    • 后缀(postfix)
  • 主机号(host-id)

常用的三种类别的 IP 地址🎈

  • IPv4 - Address Classes (tutorialspoint.com)

  • IP 地址的指派范围

    网络类别最大可指派第一个可指派的网络号最后一个可指派的 网络号每个网络中最大主机数
    A 126 = ( 2 7 − 2 ) 126=(2^7-2) 126=(272)112616777214
    B 16383 = ( 2 14 ) 16383=(2^{14}) 16383=(214)128.0191.25565534
    C 2097151 = ( 2 21 ) 2097151=(2^{21} ) 2097151=(221)192.0.0223.255.255254
  • 从第一个可指派的网络号和最后一个可指派的网络号看各类别(A/B/C)网络最大可指派网络数

    • 最大可指派数主要取决于net-id的位数(ABC类的net-id位数分别为8bit,16bit,24bit);
    • 注意到ABC类地址的前缀都是固定的(所有同类别网路号都相同)(分别是0/10/110(各占走1bit,2bit,3bit));
  • A类地址可用的网络数为 2 7 − 2 2^{7}-2 272,减2的原因是:

    • 第一,网络号字段全为0的IP地址是保留地址,意思是“本网络”,
    • 第二,网络号字段全为1的A类网络(net-id=127)的网络是环回自检网络。
网络号后缀全为0的地址指派问题/B,C类可指派网络数
多IP主机问题
  • 一台主机有2个IP地址
    • 假设一个地址是X1=192.168.11.25;
    • 另一个IP地址X2可能是?
    • 分析:
      • 一台主机占有2个或更多的IP,说明这台主机属于两个或者两个以上的逻辑网络
      • IP地址X1属于C类网络,且网络号为N(X1)192.168.11
      • 另一个网络IP地址X2的网络号应该和N(X1)不同(否则其中一个就没有意义)
      • 比如192.168.13

传输方式🎆

单播
广播
  • 广播的目的地址为网络中的全体目标
多播(组播)
  • Multicast - Wikipedia

  • 多播的目的地址是一组目标,加入该组的成员均是数据包的目的地。

  • 多播(英语:multicast,又称群播组播),是计算机网络中的一种群组通信,它把信息同时传递给一组目的计算机。

  • 多播可以是一对多或多对多布置。

  • 不应将其与物理层的点到多点通信混淆。

  • 群组通信可由应用层多播实现,也可由网络级多播协助实现,后者能让一个源地址用一次传输将数据发给群组。

  • 数据到达包含该组成员的网络区域时,由路由器交换机基站子系统等网络组件自动完成复制分发。

  • 网络级多播可能通过数据链路层的一对多地址交换实现,如以太网多播地址、异步传输模式(ATM)、P2MP及Infiniband多播,也可能通过网络层由IP多播实现。

  • 在IP多播中,多播发生在IP路由层面,路由器创建一个最佳路径将数据发往多播目的地址。

  • 多播通常应用于IP网络上的流媒体传输,如IPTV多点视频会议(Multipoint videoconferencing) 等。

单播地址&广播地址&组播地址
  • A,B,C类地址中绝大多数是单播地址(一对一通信 )
    • 主机号全为1的这部分属于广播地址
      • 这里的广播是指某个网络内广播地址(路由不转发的广播)
    • 组播地址分布在D类地址(前4个bit为1110)
      • 1110 0000$\sim$1111 1111
        • 14 × 16 = 224 14\times{16}=224 14×16=224
        • 2 8 − 1 = 255 2^8-1=255 281=255
      • 即首字节为244$\sim$255

一般不使用的IP地址🎈

网络号主机号源地址使用目的地址使用代表的意思
00可以不可在本网络上的本主机(见DHCP协议)
0host-id可以不可在本网络上的某台主机 host-id
全1全1不可可以只在本网络上进行广播(各路由器均不 转发)
net-id全1不可可以对net-id上的所有主机进行广播
127非全0或全1的 任何数可以可以用于本地软件环回测试
  • 在各类P地址中,有些P地址具有特殊用途,不用做主机的P地址:
主机号全为0
IP地址中的网络IP代表
  • 网络号不全为0,主机号全为0:表示本网络本身
    • 如202.98.174.0.这类IP可以作为某个具体网络的标志性代表IP地址
本主机地址
  • 32位全为0
    • 网络号和主机号全为0
    • 即0.0.0.0表示本网络上的本主机
主机号全为1
本网络广播地址
  • 表示本网络的广播地址,又称直接广播地址
    • 如202.98.174.255.
受限广播地址
  • 32位全为1
    • 即255.255.255.255表示整个TCP/IP网络的广播地址,又称受限广播地址
    • 实际使用时,由于路由器对广播域的隔离,255.255.255.255等效为本网络的广播地址
回环地址
  • l27.x.x.x
    • 保留为环回自检(Loopback Test).地址,此地址表示任意主机本身
    • 目的地址为环回地址的IP数据报永远不会出现在任何网络上。
小结🎈
  • 全0和全1地址在DHCP协议中将经常提及和使用🎈

  • 🎈除了A类的网络号可以是全0

    • A,B,C,D类地址都至少含有一个0,
      • {0,10,110}
    • 其他类地址(B,C,D)的网络号都是1开头的(不会是全1)
      • 它们的开头是{10,110}中的一种,所以既有1,又有0
  • A,B,C三类地址的网络号长度分别为1B,2B,3B

    • 三类地址的首字节取值范围分别是:
      • 0 ∼ 255 0\sim{255} 0255
      • 128 ∼ 191 128\sim{191} 128191
        • 100 0;0000 ∼ \sim 1011;1111
        • ( 2 7 + ( 2 6 − 1 ) ) = 128 + 63 = 191 (2^7+(2^6-1))=128+63=191 (27+(261))=128+63=191
      • 192 ∼ 223 192\sim{223} 192223
        • 110 0;0000$\sim$110 0;1111
        • 2 7 + 2 6 + 0 × 2 5 + ( ∑ i = 0 i = 4 ) 0 = 128 + 64 = 192 2^7+2^6+0\times{2^5}+(\sum\limits_{i=0}^{i=4})0=128+64=192 27+26+0×25+(i=0i=4)0=128+64=192
        • 2 7 + 2 6 + 0 × 2 5 + ∑ i = 0 i = 4 2 i = 192 + 16 + 8 + 4 + 2 + 1 = 223 2^7+2^6+0\times{2^5}+\sum\limits_{i=0}^{i=4}2^i=192+16+8+4+2+1=223 27+26+0×25+i=0i=42i=192+16+8+4+2+1=223
    • 对于B,C类网络号的第二个字节取值范围都是都可以 0 ∼ 255 0\sim{255} 0255
    • 对于C类网络号的第三个字节也是 0 ∼ 255 0\sim{255} 0255

IP 地址的一些重要特点

  • 实际上 IP 地址是标志一个主机(或路由器)和一条链路接口
    • 当一个主机同时连接到两个网络上时,该主机就必须同时具有两个相应的 IP 地址,其网络号 net-id 必须是不同的。
      • 这种主机称为多归属主机 (multihomed host)。
      • 由于一个路由器至少应当连接到两个网络(这样它才能将 IP 数据报从一个网络转发到另一个网络),因此一个路由器至少应当
        有两个不同的 IP 地址。
    • 用转发器或网桥连接起来的若干个局域网仍为一个网络,因此这些局域网都具有同样的网络号 net-id。
    • 所有分配到网络号 net-id 的网络,无论是范围很小的局域网,还是可能覆盖很大地理范围的广域网,都是平等的。

IP 地址与硬件地址

  • IP 地址与硬件地址是不同的地址。
  1. 硬件地址(或物理地址)是数据链路层和物理层使用的地址。
  2. IP 地址是网络层和以上各层使用的地址,是一种逻辑地址(称IP 地址是逻辑地址是因为 IP 地址是用软件实现的)

私有IP地址网段🎈

  • 私有IP地址也称可重用地址

  • A类: 1 ( = 2 0 =2^0 =20)个A类网段,即10.0.0.0~10.255.255.255

    • 网络号8位;固定0开头

    • 0000 1010 ;0000 0000;0000 0000;0000 0000

    • 0000 1010 ;1111;1111;1111;1111;1111 1111

  • B类: 16( = 2 4 =2^4 =24)个B类网段,即172.16.0.0~172.31.255.255

    • 网络号16位;固定10开头
    • 1010 1100;0001 0000;0000 0000;0000 0000
    • 1010 1100;0001 1111;1111 1111;1111 1111
  • C类: 256(= 2 8 2^8 28)个C类网段,即192.168.0.0~192.168.255.255

    • 网络号24位;固定110开头
    • 1100 0000;1010 1000;0000 0000;0000 0000
    • 1100 0000;1010 1000;1111 1111;1111 1111
  • Of the approximately four billion addresses defined in IPv4, about 18 million addresses in three ranges are reserved for use in private networks.

  • Packets addresses in these ranges are not routable in the public Internet; they are ignored by all public routers.

  • Therefore, private hosts cannot directly communicate with public networks, but require network address translation at a routing gateway for this purpose.(NAT)

  • NameCIDR blockAddress rangeNumber of addressesClassful description
    24-bit block10.0.0.0/810.0.0.0 – 10.255.255.25516777216Single Class A.
    20-bit block172.16.0.0/12172.16.0.0 – 172.31.255.2551048576Contiguous range of 16 Class B blocks.
    16-bit block192.168.0.0/16192.168.0.0 – 192.168.255.25565536Contiguous range of 256 Class C blocks.
  • Since two private networks, (e.g., two branch offices), cannot directly interoperate via the public Internet, the two networks must be bridged across the Internet via a virtual private network (VPN) or an IP tunnel, which encapsulates packets, including their headers containing the private addresses, in a protocol layer during transmission across the public network.

  • Additionally, encapsulated packets may be encrypted for transmission across public networks to secure the data.

Link-local addressing

  • 链路本地地址(英语:Link-local address)是计算机网络中一类特殊的地址,它仅供于在网段,或广播域中的主机相互通信使用。

  • 这类主机通常不需要外部互联网服务,仅有主机间相互通讯的需求。

    • IPv4链路本地地址定义在169.254.0.0/16地址块。
    • IPv6定义在fe80::/10地址块
  • RFC 3927 defines the special address block 169.254.0.0/16 for link-local addressing. These addresses are only valid on the link (such as a local network segment or point-to-point connection) directly connected to a host that uses them. These addresses are not routable. Like private addresses, these addresses cannot be the source or destination of packets traversing the internet. These addresses are primarily used for address autoconfiguration (Zeroconf) when a host cannot obtain an IP address from a DHCP server or other internal configuration methods.

  • When the address block was reserved, no standards existed for address autoconfiguration. Microsoft created an implementation called Automatic Private IP Addressing (APIPA), which was deployed on millions of machines and became a de facto standard. Many years later, in May 2005, the IETF defined a formal standard in RFC 3927, entitled Dynamic Configuration of IPv4 Link-Local Addresses.

Loopback

  • Main article: Localhost

  • The class A network 127.0.0.0 (classless network 127.0.0.0/8) is reserved for loopback.

  • IP packets whose source addresses belong to this network should never appear outside a host.

  • Packets received on a non-loopback interface with a loopback source or destination address must be dropped.

私有网络与网络地址转换NAT🎈

  • 网络地址转换(NAT)是指通过将专用网络地址(如Intranet)转换为公用地址(如Internet),从而对外隐藏内部管理的P地址。

  • 它使得整个专用网只需要一个全球P地址就可以与因特网连通,由于专用网本地P地址是可重用的,所以NAT大大节省了P地址的消耗。

  • 同时,它隐藏了内部网络结构,从而降低了内部网络受到攻击的风险。

  • 此外,为了网络安全,划出了部分P地址为私有IP地址。

  • 私有IP地址只用于LAN,不用于WAN连接

    • (因此私有IP地址不能直接用于Internet,必须通过网关利用NAT把私有IP地址转换为Internet中合法的全球P地址后才能用于Internet),并且允许私有IP地址被LAN重复使用。

NAT转发表示格式

  • WAN端
    • 全球IP:端口
  • LAN端
    • 私有IP:端口
小结
  • NAT可看到端口,工作在传输层🎈

wireshark 分析IP 数据报首部

在这里插入图片描述

  • Identivication标识占了16位(从上面的抓包的取值0x739c(六进制数,而且是4位16进制数,每个十六进制数相当于4位二进制数,所以标识字段占2Byte:16bit
  • Flags标志
    • 标志字段占三位
    • 现在,仅有后面两位有用处,第一位暂时保留不用
    • DF=1时,表示数据报不可分片(否则可)
    • MF=1时,表示该IP分组是某个IP数据报的某个分片,且不是最后一个分片(否则就是最后一个分片)
    • 在这里插入图片描述
  • 偏移位占13位
  • 头部的第2行(4~7)字节中,第4字节的值是0100 0000,其十六进制表示为0x40

special address(IP)

  • Address blockAddress rangeNumber of addressesScopeDescription
    0.0.0.0/80.0.0.0–0.255.255.25516777216SoftwareCurrent network[7]
    10.0.0.0/810.0.0.0–10.255.255.25516777216Private networkUsed for local communications within a private network.[8]
    100.64.0.0/10100.64.0.0–100.127.255.2554194304Private networkShared address space[9] for communications between a service provider and its subscribers when using a carrier-grade NAT.
    127.0.0.0/8127.0.0.0–127.255.255.25516777216HostUsed for loopback addresses to the local host.[7]
    169.254.0.0/16169.254.0.0–169.254.255.25565536SubnetUsed for link-local addresses[10] between two hosts on a single link when no IP address is otherwise specified, such as would have normally been retrieved from a DHCP server.
    172.16.0.0/12172.16.0.0–172.31.255.2551048576Private networkUsed for local communications within a private network.[8]
    192.0.0.0/24192.0.0.0–192.0.0.255256Private networkIETF Protocol Assignments.[7]
    192.0.2.0/24192.0.2.0–192.0.2.255256DocumentationAssigned as TEST-NET-1, documentation and examples.[11]
    192.88.99.0/24192.88.99.0–192.88.99.255256InternetReserved.[12] Formerly used for IPv6 to IPv4 relay[13] (included IPv6 address block 2002::/16).
    192.168.0.0/16192.168.0.0–192.168.255.25565536Private networkUsed for local communications within a private network.[8]
    198.18.0.0/15198.18.0.0–198.19.255.255131072Private networkUsed for benchmark testing of inter-network communications between two separate subnets.[14]
    198.51.100.0/24198.51.100.0–198.51.100.255256DocumentationAssigned as TEST-NET-2, documentation and examples.[11]
    203.0.113.0/24203.0.113.0–203.0.113.255256DocumentationAssigned as TEST-NET-3, documentation and examples.[11]
    224.0.0.0/4224.0.0.0–239.255.255.255268435456InternetIn use for IP multicast.[15] (Former Class D network.)
    233.252.0.0/24233.252.0.0-233.252.0.255256DocumentationAssigned as MCAST-TEST-NET, documentation and examples.[15][16]
    240.0.0.0/4240.0.0.0–255.255.255.254268435455InternetReserved for future use.[17] (Former Class E network.)
    255.255.255.255/32255.255.255.2551SubnetReserved for the “limited broadcast” destination address.[7]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值