"Computer Network" IPv4

1. IPv4 packet

IPv4 is now the commonly used IP (version 4). IP defines the basic unit of data transmission-IP packet and its exact data format. IP also includes a set of rules that specify how to handle packets and how to control errors. In particular, IP also contains the idea of ​​unreliable delivery and the idea of ​​packet routing associated with it.

1.1 IPv4 packet format

An IP packet consists of two parts: header and data. The length of the first part of the header is fixed, a total of 20 B, which is required for all IP packets. Behind the fixed part of the header are some optional fields whose length is variable to provide mechanisms such as error detection and security. The format of the IP datagram is shown in the figure:

Insert picture description here

The meanings of some of the main fields of the IP header are as follows:

  • version

    Refers to the version of IP, the currently widely used version number is 4

  • Header length

    4 digits

    The unit of length is 32 bits, and the maximum value is 60 B (15 × 4 B)

    The most commonly used header length is 20 B, and no options (ie optional fields) are used at this time

  • Total length

    16 digits

    Refers to the length of the sum of the header and data, in bytes

  • Logo

    16 digits

    It is a counter, which is incremented by 1 each time a datagram is generated and assigned to the identification field. But it is not a "serial number" because IP is a connectionless service

  • Sign

    3 digits

    The lowest bit of the flag field is MF, MF = 1 means there are more fragments, MF = 0 means the last fragment

    The one bit in the middle of the flag field is DF. Fragmentation is allowed only when DF = 0

  • Slice offset

    13 digits

    It only shows the relative position of a certain piece in the original group after the longer group is divided. The slice offset uses 8 bytes as the offset unit, that is, the length of each slice must be an integer multiple of 8 B (64 bits)

  • Time to Live (TTL)

    8 digits

    The maximum number of routers that a datagram can pass through in the network. The router reduces the TTL by 1 before forwarding the packet. If the TTL is reduced to 0, the packet must be discarded

  • protocol

    8 digits

    Indicate which protocol is used for the data carried in this packet, that is, which transport layer protocol the data part of the packet should be handed over, such as TCP, UDP, etc. The value of 6 means TCP, and the value of 17 means UDP

  • First checksum

    16 digits

    The header checksum of the IP datagram only checks the header of the packet, not the data part

  • source address

    Sender's IP address

  • Destination address

    IP address of the recipient

1.2 The process of forwarding packets at the network layer

  1. Extract the IP address D of the destination host from the header of the datagram to get the destination network address N
  2. If the network N is directly connected to this router, the datagram will be delivered directly to the destination host D, which is called direct delivery by the router; otherwise, it will be delivered indirectly, go to step 3.
  3. If there is a specific host route with a destination address of D in the routing table (specify a specific route to a specific destination host, usually to control or test the network), then the datagram is sent to the next hop router specified in the routing table ; Otherwise, go to step 4
  4. If there is a route to network N in the routing table, send the datagram to the next hop router specified in the routing table; otherwise, go to step 5
  5. If there is a default route in the routing table, send the datagram to the default router specified in the routing table; otherwise, go to step 6
  6. Report forwarding packet error

2. IPv4 address

Each host (or router) connected to the Internet is assigned a 32-bit globally unique identifier, which is an IP address

Traditional IP addresses are classified addresses, divided into five categories: A, B, C, D, and E

No matter what type of IP address, it is composed of network number and host number , which is simply the network address and host address

The classified IP address is shown in the figure below:

Insert picture description here

Among the various types of IP addresses, some IP addresses have special uses and do not need to be used as the host's IP address:

  • The host number is all 0 means the network itself , such as 202.98.174.0
  • The host number is all 1 means the broadcast address of this network , such as 202.98.174.255
  • 127.0.0.0 is reserved as the loop self-check address, this address represents any host itself, and the IP datagram whose destination address is the loopback address will never appear on any network
  • 32 bits are all 0s, that is, 0.0.0.0 means this host on this network
  • 32 is all 1s, that is, 255.255.255.255 represents the broadcast address of the entire TCP/IP network

In actual use, it is used for the router to isolate the broadcast domain, 255.255.255.255 is equivalent to the broadcast address of the network

The IP address has the following important characteristics:

  1. IP address is a hierarchical address structure. The advantages of two levels are :

    • The IP address management agency only assigns the network number when assigning the IP address, and the remaining host number is assigned by the unit that obtained the network number, which facilitates the management of the IP address
    • The router only forwards packets according to the network number connected to the destination host (regardless of the destination host number), so that the number of items in the routing table can be greatly reduced, thereby reducing the storage space occupied by the routing table
  2. IP address is the interface that identifies a host (or router) and a link

    When a host is connected to two networks at the same time, the host must have two corresponding IP addresses at the same time, and its network number net-id must be different

    Since a router should be connected to at least two networks (so that it can forward IP datagrams from one network to another), a router should have at least two different IP addresses

  3. Several LANs connected by repeaters or bridges are still one network (the same broadcast domain), so these LANs all have the same network number net-id, but the host-id must be different

  4. All networks assigned to the network number net-id, a small area network, or a wide area network that may cover a large geographic area, are equal

  5. The network number in the IP address of the host or router on the same LAN must be the same. The router always has two or more IP addresses, and each port of the router has an IP address with a different network number.

3. Subnet division and subnet mask

3.1 Subnetting

Disadvantages of two-level IP addresses:

  • Utilization of IP address space is sometimes very low
  • Assigning a network number to each physical network will make the routing table too large and degrade network performance
  • Two-level IP address is not flexible enough

Since 1985, a new "subnet number" field has been added to the IP address, making the two-level IP address become a three-level IP address. This practice is called subnetting.

The basic idea of ​​subnetting is as follows:

  • The division of subnets is purely an internal matter of an organization, and the organization still appears as a network without subnetting externally.
  • Borrowing several bits from the host number as the subnet number, of course the host number is reduced by the same bits. The structure of the third-level IP address is as follows: IP address = {<network number>, <subnet number>, <host number>}
  • For all IP datagrams sent from other networks to a certain host in the organization, the router that connects to the organization's network is still found based on the destination network number of the IP datagram. Then the router, after receiving the IP datagram, finds the destination subnet according to the destination network number and subnet number. Finally, the IP datagram is delivered directly to the destination host.

3.2 Subnet mask

In order to tell the host or router to subnet a class A, B, and C network, use the subnet mask to express the borrowing of the host number in the source network

The subnet mask is a 32-bit binary string corresponding to the IP address. It consists of a string of 1s followed by a string of 0s, where 1 corresponds to the network number and subnet number in the IP address, and 0 corresponds to the host number. The computer only needs to calculate the IP address and its corresponding subnet mask by bit and budget to get the network address of the corresponding subnet

The current Internet standards stipulate that all networks must use a subnet mask

If a network is not subnetted, then the default subnet mask is used:

  • Class A address: 255.0.0.0
  • Class B address: 255.255.0.0
  • Class C address: 255.255.255.0

4. Unclassified inter-domain routing (CIDR)

Unclassified meets routing is an IP address division method proposed on the basis of variable-length subnet mask to eliminate the traditional A, B, and C network division, and can realize the supernet construction with the support of software

The main features of CIDR are as follows:

  • Eliminate the concept of traditional IP classification and division, and make more effective use of IPv4 address space

    CIDR uses the concept of "network prefix" instead of the concept of subnet. Therefore, the unclassified two-level addressing of the IP address is: IP::= {<network prefix>, <host number>}

    CIDR also uses "slash notation" (or CIDR notation), which is the number of bits occupied by the IP address/network prefix

    For example, for 128.14.32.5/20the address, which is a mask 20 and a subsequent consecutive 12 consecutive 0 by bit-wise method "and" can be obtained network prefix of the address:

    IP = 10000000.00001110.00100000.00000101, mask =11111111.11111111.11110000.0000

    Network prefix 10000000.00001110.00100000.00000000==128.14.32.0

  • Combine consecutive IP addresses with the same network prefix into a "CIDR address block"

    A CIDR address block can represent many addresses. This kind of address aggregation is called route aggregation, or constitutes a supernet.

    Route aggregation is an item in the routing table that can represent the routes of multiple original traditional classification addresses, which helps reduce the direct exchange of routing information by routers, thereby improving network performance

The number of addresses in the CIDR address block must be an integer power of 2. The actual number of addresses that can be assigned is usually 2 N − 2 2^N-22N2 N N N represents the number of digits of the host number, the host number all 0 represents the network number, the host number all 1 is the broadcast address

The advantage of CIDR lies in the flexibility of the network prefix length. Because the prefix length of the upper network is shorter, the corresponding routing table has fewer items, and the internal network prefix can be extended to flexibly divide the subnet.

Guess you like

Origin blog.csdn.net/dreaming_coder/article/details/114010228