Common protocols at the network layer - IPV4, IPV6, ARP, ICMP, QoS

Table of contents

1. IPv4 protocol

The composition of an IPV4 address:

Classification of IPv4 addresses:

About multicast and multicast:

Common multicast address categories:

Special IPV4 address:

Private address and public address:

Private address range:

Subnetting:

Subnet mask:

Variable length subnet mask (VLSM):

CIDR:

Best matching principle in routers:

IPV4 datagram format:

2. ARP protocol

Changes in IP and MAC when hosts communicate in the WAN:

ARP protocol principle:

ARP protocol message types:

ARP related commands in Windows:

Proxy-ARP

RARP protocol

3. ICMP protocol (Internet Control Message Protocol)

ICMP protocol message types:

Things to note about ICMP messages:

Applications of ICMP:

4、QoS:

5. IPv6 protocol

An IPV6 address means:

Address types for IPv6:

Link local address:

IPV6 multicast (multicast) address:

IPV6 anycast address:

IPV6 message format:

Transition plan from IPv4 to IPv6


1. IPv4 protocol

        IP addresses are divided into two categories : IPV4 and IPV6; IP addresses are used to identify network devices. All devices on the network have IP addresses and are connected to the network through IP addresses.

        IP addresses are logical addresses and can be configured and modified manually.

        IPV4 uses 32-bit binary to represent IP addresses. Dotted decimal notation is usually used for representation: each 8-bit group is a group, a total of 4 groups, and each group is separated by ".".

        The rounding range of each group is 0~255 (decimal);

The composition of an IPV4 address:

Two parts: the network part         in the front and the host part in the back .

        For example: 192.168.0.11, assume that the network part is 192.168, and the following 0.11 is the host part.

        If the network parts of several hosts are the same, it means that they are in the same network segment (hosts in the same network segment are under the same LAN, and they use switches to communicate with each other without using routers; and hosts in different network segments A router is required to communicate with each other).

Classification of IPv4 addresses:

        Class A address: The first group is the network part, and the range of the first group is limited to 1~126 ;

        Class B address: The first and second groups are the network part, and the range of the first group is limited to 128~191 ;

        Class C address: The first, second, and third groups are the network part, and the range of the first group is limited to 192~223 ;

        Class D address: The first group is the network part, with a value of 224~239 , and the other three groups are multicast address IP;

        Class E address (reserved address): the first group of values ​​is 240~255 ;

Among them, class A, B, and C addresses are unicast addresses , and class D addresses are multicast addresses . Unicast represents "one-to-one" communication, while multicast represents "one-to-many" communication.

        When calculating the number of valid IP addresses (IPs that can be assigned to user hosts), subtract 2. One of them is that the host part is all 0, indicating the network address ; the other is that the host bit is all 1, indicating the broadcast address . For example, in the IPV4 address 192.168.1.100, the first 24 bits (192.168.1) are the network part, then the valid IP address is 192.168.1.1~192.168.1.254, minus the network address 192.168.1.0 and the broadcast address 192.168.1.255.

About multicast and multicast:

        Multicast is sending information to a specific group of receivers. Only hosts that have joined the same group can receive all data in this group. Broadcasting sends information to all hosts in the network, regardless of whether these hosts belong to the same group.

        Multicast has a fixed address segment (Class D address), while broadcast uses a specific broadcast address or the broadcast address of a specific network (such as 199.123.255.255)

        No matter how many members a multicast group contains, when the multicast service sends information, only one packet needs to be sent. (In multicast, "group" is a collection identified by an IP multicast address. Any user host (or other receiving device) that joins a multicast group becomes a member of the group and can identify and receive messages sent to the group. Multicast data of a multicast group. One multicast source can send data to multiple multicast groups at the same time, and multiple multicast sources can also send data to one multicast group at the same time. Multicast group members can join or leave dynamically In a multicast group, member hosts can be widely distributed anywhere in the network.)

        Multicast and broadcast can only be used for the destination address, not the source address.

    

Common multicast address categories:

224.0.0.0 - 224.0.0.255 For use by router protocols
224.0.1.0 - 224.0.1.255 Public multicast address, used on the Internet
224.0.2.0 - 238.255.255.255

Temporarily available multicast addresses across the entire network

239.0.0.0 - 239.255.255.255 Local management multicast address, valid only within a specific local scope

Special IPV4 address:

form Can it be used as a source address ? Can it be used as a destination address ? Remark
0.0.0.0 yes no Represents this host on this network
255.255.255.255 no yes Broadcast on this network
127.0.0.1 yes yes Used as a local software loopback address for testing
169.254.xy (the host number is not all 0s or all 1s) yes yes Private IP address assigned by the operating system in the event of a Windows host DHCP server failure (APIPA, Automatic Private IP Address)

Private address and public address:

        Public addresses are complexly assigned by the Internet Information Center, and the Internet can be accessed directly through the public address. The public address is unique in the entire network and cannot be reused.

        A private address is an unregistered address that is used exclusively within the organization and cannot directly access the Internet. Private addresses are uniquely used in the same intranet and can be reused in different intranets.

        To access the Internet from a private address, NAT (Network Address Translation Protocol) needs to be used to convert the private IP to a public IP. Hosts on the intranet use the NAT protocol and can access the Internet through a public gateway.

Private address range:

Address category address range Network number
A 10.0.0.0 - 10.255.255.255 10
B

172.16.0.0 - 172.31.255.255

172.16 ~ 172.31
C 192.168.0.0 - 192.168.255.255 192.168.0 ~ 192.168.255

Subnetting:

        Purpose - To solve the problem of address waste.

        Function - Divide a large network into multiple different small networks to solve the problems of low IP address space utilization and inflexible two-level IP addresses.

        Implementation process - Borrow several host bits of the IP address to act as subnet bits, thereby generating multiple different subnet networks.

        After subnetting, the IP address becomes a three-level structure: <network bit> <subnet bit> <host bit>

        Different subnet networks are obtained by taking different values ​​of the subnet number.

A company wants to divide the original 172.16.0.0/16 standard network into 12 subnets, of which the largest number of subnet nodes is about 4,000. Find the range of each subnet.

 

172.16.0.0/16, the last 16 means that the network number is 16 digits, then the host number is 32-16 = 16 digits, and the last two groups are host numbers, which can be used for subnet division.

 

12 subnets are required, and 4 binary bits can be used to represent 12, then bits 17-20 are used as subnet bits (you can choose any 12 numbers, 16 choose 12); the remaining 12 bits are used as host bits, 12 host bits The number of hosts that can be represented by bits is 2^12-2=4094, which meets the requirements of the question.

 

The scope of each subnet can be:

172.16.0000 0000.1/20 ~ 172.16.0000 0000.254/20;

172.16.0001 0000.1/20 ~ 172.16.0001 0000.254/20;

        ……

172.16.1011 0000.1/20 ~ 172.16.1011 0000.254/20;

172.16.1100 0000.1/20 ~ 172.16.1100 0000.254/20;

Subnet mask:

        Function: Used to specify the network bit and host bit of the IP address. It is specified that the network bit is 1 and the host bit is 0;

        Assume that an IP address has 19 network bits and 13 host bits, then the subnet mask is

        It can be seen from the representation of the IP address: 192.168.128.100/19:

        1) Subnet mask: 255.255.224.0, subnet mask length 19 bits

        2) Network part: 192.168.100 00000.100

        3) Host part: 192.168.100 00000.100

        4) This address is a Class C private IP address

Variable length subnet mask (VLSM):

        Continue to divide subnets on the basis of subnets. The calculation method is also similar.

CIDR:

        Classless interdomain routing. It is a method of classifying IP addresses for assigning IP addresses to users and routing IP packets efficiently on the Internet.

        CIDR uses slash notation, also known as CIDR notation, that is, add a slash "/" after the IP address, and then write the number of digits occupied by the network prefix (the number of 1's in the subnet mask), such as :192.168.32.10/20

        CIDR route aggregation : The same consecutive bits in the network address are aggregated, and different bits are classified as host bits after aggregation, thereby realizing the aggregation of multiple network segments into a new supernet network segment.

        If there are four network segments:

                192.168.129.0/24 —— 192.168.1000 0001.0/24

                192.168.130.0/24 —— 192.168.1000 0010.0/24

                192.168.132.0/24 —— 192.168.1000 0100.0/24

                192.168.133.0/24 —— 192.168.1000 0101.0/24

        It can be seen that the longest common prefix is ​​obtained in the third group: 1000 0, then the new network bits are 2 * 8 + 5 = 21 bits. 192.168.128.0/21 is the aggregated supernet ID.

        The advantage of route aggregation is that it can simplify the number of routing tables on the router; the characteristic of route aggregation is to aggregate multiple small networks into a large network.

Best matching principle in routers:

        When using route aggregation, the items in the routing table mainly consist of "network prefix" and "next hop" addresses.

        When searching the routing table to match the destination IP address in the packet, more than one match may be obtained. The route with the longest network prefix should be selected from the matching results (longest prefix matching).

        The longer the network prefix, the smaller its block address and therefore the more specific the route (i.e. the fewer hosts there are under the network).

IPV4 datagram format:

Field Placement size (bits) Remark value
Version 4 IP protocol version number IPv4 is 4 (0100)
header length 4 IP packet length The unit is 4 bytes. The minimum value is 5 (0101), that is, the minimum header length of the IP message is 20 bytes
total length 16 The total length of the IP packet The unit is bytes. The longest IP packet is 65535 bytes.
logo 16 Represent IP fragmentation Different fragments in the same message have the same identifier, which is used to reorganize the fragments.
logo 3

DF occupies one bit, indicating whether fragmentation is not allowed ;

MF occupies one bit, indicating whether there are more shards ;

There is also a reserved bit.

If fragmented, DF is 0, otherwise DF=1;

If the slice is the last slice and there are no more slices, then MF=0, otherwise MF=1;

slice offset 13 Point out the relative position of the data in the fragment in the message The unit is 8B, and can be sorted and reorganized according to the value of the slice offset field from small to large.
Time to Live (TTL) 8 Also called "hop count", it is used to prevent IP packets from being forwarded in the network without restrictions. Each time it passes through a router, the TTL value in the packet will be decremented by 1. When the TTL value is 0, the router will discard the packet.
protocol 8 Used to identify what protocol is used by the upper layer
header checksum 16 When forwarding in the network, verify the IP header
source address 32 Sender IP address
Destination address 32 Receiver’s IP address
Options variable length
filling variable length Used to ensure that the length of the IP message header is an integer multiple of 4B

Example: IP datagrams need to be fragmented when passing through a network with a smaller MTU. Assume that a message with a size of 1500 is divided into two smaller messages, and the size of one message is 800 bytes. What is the size of the other message at least by how many bytes? (Morning test questions for Internet workers in the second half of 2017)

 

For a 1500 message, the IP header occupies 20 bytes, so the data is only 1480 bytes;

It needs to be divided into two small messages to send. The data of the first message is 800-20=780 bytes, then the data of the second message is 1480-780= 700, plus the header 20 bytes, Then it is 720 bytes.

2. ARP protocol

        The ARP protocol is only used in LAN.

        When a host wants to communicate with another host, it must know the MAC address of the destination host, and this MAC address is obtained through the ARP protocol. ARP protocol is the Address Resolution Protocol, which is used to map IP addresses to MAC addresses.

        When host A wants to communicate with host B but does not know its MAC address, it will send an ARP request broadcast message to the LAN to ask for host B's MAC address. This ARP request broadcast message will contain the IP address of Host B. Since the MAC address of Host B is not yet known, the destination MAC address at this time is 0; when encapsulated into a frame, the destination MAC address will be set to the broadcast address (FF- FF-FF-FF-FF-FF) so that all hosts in the LAN can receive this message.

If the MAC address of hostA is aa-aa-aa-aa-aa-aa, the MAC address of hostB is bb-bb-bb-bb-bb-bb. The format of the frame sent by hostA to query the MAC address of hostB is as shown in the figure below. What is the target MAC address in this frame? What is the destination MAC address in the ARP message? (Morning questions for Internet workers in the first half of 2018)

The destination MAC address in the frame is: ff-ff-ff-ff-ff-ff;

The destination MAC address in the message is: 00-00-00-00-00-00

        When host B receives the ARP request broadcast message, it will check whether the IP address in the message matches its own IP address. If there is a match, host B will reply with an ARP response message to host A and provide its MAC address to host A. (ARP requests are sent by broadcast and ARP responses are sent by unicast.)

         The network layer and above use IP addresses; the data link layer and below use hardware addresses (MAC addresses).

Changes in IP and MAC when hosts communicate in the WAN:

        Assume that host H1 and host H2 are in different LANs. Host H1 wants to send a message to host H2, and the communication must go through router R1.

        When data leaves H1, the source IP is IP1, the destination IP is IP2, the source MAC address is HA1, and the destination MAC address is HA3. (Note that this is WAN communication and we do not know the MAC of the target host, so the target MAC is the MAC address of the transit router and let the router help handle it; if it is a LAN, the target MAC address must be the MAC address of the target host)

        From H1 to R1 and from R1 to H2: the source address and destination address in the IP datagram are both IP1 and IP2; the two IP addresses always remain unchanged.

        However, after moving from H1 to R1, the destination MAC address in the data frame changes from the MAC address of R1 to the MAC address HA2 of H2, and the source MAC address changes from HA1 to HA4.

        All in all, when communicating in different LANs , the IP address will always remain unchanged. Every time it passes through the router, the MAC address (source and destination) will change ; when communicating in the same LAN , neither the IP address nor the MAC address will change. .

ARP protocol principle:

        Under the IP protocol, the ARP protocol sends ARP request messages through broadcasts to obtain the mapping relationship between IP and MAC.

ARP protocol message types:

      ARP messages include ARP request packets and ARP response packets. The content of the message includes the following parts:

                Sender MAC address;

                Sender IP address;

                Target MAC address (if it is a packet request message, this item is 0 if it is unknown);

                Target IP address;

        The router will not forward ARP requests. ARP requests will only be broadcast locally and directly encapsulated in frames for transmission.

ARP related commands in Windows:

arp -a View ARP cache table
arp -d Clear ARP cache
arp -s ip address mac address

for static binding

Like: arp -s 192.168.1.123 a0-1a-64-aa-aa-aa

arp 192.168.1.2 Get the MAC address corresponding to the host 192.168.1.2

Proxy-ARP

        当出现跨网段的 ARP 请求时,由离源主机最近的路由器将自己的 MAC 地址返回给发送 MAC广播请求的主机,实现 MAC 地址代理最终使主机能够正常通信。

RARP 协议

        逆向地址解析协议,实现 MAC 地址到 IP 地址的映射。

3、ICMP 协议(网际控制报文协议)

        背景:IP 协议采用无连接的数据报转发方式,网络中的节点尽最大努力交付IP报文,整个过程并不保证可靠交付。

        ICMP 协议的作用:可以传送 IP 通信过程中出现的错误信息,进而帮助提升 IP 报文成功交付的概率。

        ICMP 协议封装在 IP 数据报中进行传输。

ICMP协议的报文类型:

ICMP报文的注意事项:

  • 对 ICMP 差错报告报文不再发送 ICMP 差错报告报文;
  • 对具有特俗地址(如127.0.0.1、0.0.0.0等)的数据报不发生 ICMP 差错报告报文;
  • 对具有多播地址的数据报都不发送 ICMP 差错报告报文;
  • 对第一个分片的数据报片的所有后续数据报片都不发送 ICMP 差错报告报文;

ICMP的应用:

路由追踪的过程:

        通过向目标发送一连串TTL值依次加1且端口不可达的数据报,从而实现对到达目标地址的路径跟踪。

H1发送一个 TTL=1 数据包,根据返回的超时消息可获得第一跳路由器的地址 RA

H1发送一个 TTL=2 数据包,根据返回的超时消息可获得第二跳路由器的地址 RB

        ……

H1发送一个 TTL = 4 数据包,数据包成功到达目标主机,返回一个端口不可达的错误,此时路由跟踪结束。

4、QoS:

        IPV4 网络存在以下几个问题:延迟、丢包、延迟抖动;

        QoS —— 服务质量,是用来解决网络延迟和阻塞等问题的一项技术。使用QOS的目的是为了区分流量,保证重要流量及时被转发。

5、IPV6 协议

        解决的问题:从根本上解决 IPV4 地址资源不足的问题

        相较于 IPV4 的改进:

  • 更大的地址空间,128位
  • 拓展的地址层次结构
  • 灵活的首部格式
  • 改进的选项
  • 允许协议继续扩充
  • 支持手动配置
  • 支持资源的预分配

IPV6 地址表示:

        IPv6地址由128位组成,分为前缀和后缀两部分。前缀部分用于标识网络,由IPv6地址分配机构分配;后缀部分用于标识主机,由网络接口ID生成

  • 使用冒号十六进制记法,把每一个16位的二进制值使用十六进制值表示,各值之间用冒号分隔。
  • 允许把数字前面的 0 省略
  • 支持将一组连续的 0 压缩成一对冒号代替(零压缩),但是双冒号的形式只能出现一次

如 IPV6 的初始地址为:0000:0000:0000:0db8:0000:0000:0042:8329

前导零进行省略:0000:0000:0000:db8:0000:0000:42:8329

压缩连续的零:::db8:0000:0000:42:8329  或 0000:0000:0000:db8::42:8329

因为连续的零只能出现一次,因此不能变成:::db8::42:8329

特殊的地址:

环回地址

        0000:0000:0000:0000:0000:0000:0000:0001,可以通过规则缩写为 ::1

未分配地址(全为0),不能分配给任何节点,也不能用作目的地址

        0000:0000:0000:0000:0000:0000:0000:0000,即 ::/128

在 IPV6 中,CIDR斜线表示方法仍然适用,如 60 位前缀12AB00000000CD30可以记为:

  • 12AB:0000:0000:CD30:0000:0000:0000:0000/60
  • 或 12AB::CD30:0:0:0:0/60
  • 或 12AB:0:0:CD30::/60

IPV6 的地址类型:

(1)单播:传统的点对点通信

(2)多播:一点对多点的通信

(3)任播:任播是IPV6 新增加的一个类型,数据报在交付时只交付其中的一个,通常是距离最近的一个。

地址类型 地址前缀 IPV6前缀标识
全球单播地址 全球路由选择前缀(48位) 前三位固定为001
链路本地(单播)地址 1111111010 FE80::/10
站点本地(单播)地址 1111111011 FEC0::/10
多播地址 11111111 FF00::/8
任播地址 从单播地址空间中进行分配,使用单播地址格式

全球单播地址的等级结构:

链路本地地址:

  • 每个设备的接口在启动 IPV6 时都会自动配置一个链路本地地址
  • IPV6 的 “邻居发现” (ND)机制要用到 IPV6 的链路本地地址,IPV6 中没有广播,也不需要使用ARP协议,“邻居发现” 是 IPV6 中与 IPV4 的 ARP 对应的寻址机制
  • 链路本地地址以 “FE80” 开头
  • 接口ID(接口表示符)由 EUI-64 算法生成,将 MAC 地址和其他的一些信息转换为 IPv6 地址的后 64 位;
  • 路由器不会转发链路本地地址

IPV6 多播(组播)地址:

  • 任何一个节点都可以是一个组播组的成员
  • 一个源节点可以发送数据包到组播组
  • 组播组的所有成员都能收到发往该组播组的数据包
  • 组播地址在 IPV6 中不能用作源地址使用,也不能出现在任何选择路由中

IPV6 任播地址:

  • 任播地址是 IPV6 特有的地址类型,他用来标识一组网络接口(主机、路由器、交换机等)
  • 路由器会将目的地址是任播地址的数据包发送给距离本地路由器最近的一个网络接口(一对一组中的一个)

IPV6报文的格式:

        首部长度固定40字节, 通过选项字段来扩充首部,并封装于有效载荷。

        IPV6 和 IPV4 二者是不兼容的(报文格式不同)。

        在 IPV6 网络中,除了逐跳选项拓展首部外,路由器都不处理其他的拓展首部,这样大大提高了路由器的处理效率。

        在 RFC 2460 中定义了六种拓展首部:

  • 逐跳选项
  • 路由选项
  • 目的站选项
  • 分片
  • 鉴别
  • 封装安全有效载荷

IPV4 到 IPV6 的过渡方案

        

IPV6 的隧道技术有多种,分为手动隧道和自动隧道

隧道技术 特殊地址
自动隧道 ISATAP隧道 ::0000:5EFE:w.x.y.z
IPV4 兼容 IPV6 自动隧道 ::w.x.y.z(0:0:0:0:0:0:w.x.y.z)
IPV6 to IPV4 隧道 完整的IPV6 to IPV4 主机地址由 IPV6 to IPV4地址的48位格式前缀(2002:A.B.C.D::/48)和后面的子网标识符ID以及64位的接口ID组成
手动隧道 IPV6-OVER-IPV4 GRE隧道 手动指定IPV4地址

三种过渡方案的对比:

特点
双协议栈技术 是实现其他IPV6过渡方案的基础技术
隧道技术 通常应用于IPV6孤网,通过现有的IPV4网络通信,通过再次封装,形成通信隧道
网络地址转换技术 通过地址转换协议,进行 IPV6 to IPV4 或IPV4 to IPV6 访问转换,可满足IPV4纯节点于IPV6纯节点之间的双向访问请求

参考:

[1] IPv4地址分类(A类 B类 C类 D类 E类)_ipv4分类-CSDN博客

[2] 一文读懂ARP协议,从IP获取对方MAC实操 - 知乎

Guess you like

Origin blog.csdn.net/hao_13/article/details/133484733