[JavaEE Elementary] TCP/IP Protocol (2)

Network Layer Key Protocols

IP protocol

The format of the protocol header is as follows:
insert image description here

  • 4-digit version number (version): Specifies the version of the IP protocol, which is 4 for IPv4. IPv6 is 6.
  • 4-bit header length (header length): describes how long the IP header is. (The IP header is variable-length) There is an option part in the header that is variable-length. is dispensable. The unit here is also four bytes.
  • 8-bit Type of Service (Type Of Service): 3-bit priority field (deprecated), 4-bit TOS field, and 1-bit reserved
    field (must be set to 0). The 4 bits represent the four forms/four working modes of the IP protocol. The 4-bit TOS respectively represent: minimum delay, maximum throughput, highest reliability, and minimum cost. These four conflict with each other, and only one can be chosen.
  • 16-bit total length (total length): describes the length of an IP packet (header + payload). This length minus the previous IP header length is the payload length. A complete TCP/udp datagram length.

If the data payload carried by an IP datagram is too long, exceeding 64kb, the data will be split at the network layer. Split a piece of data into multiple IP datagrams. Then send it to the receiver separately, and then reassemble it.
Receiver: data link layer, divides two data frames, obtains two IP datagrams, and hands them over to the network layer. transport layer.

  • 16-bit identification (id): uniquely identifies the message sent by the host. The identifiers of multiple packages split into the same data are the same.
  • 3-bit flag field: The first bit is reserved (reserved means that it is not used now, but it may be used in the future if I haven't figured it out yet). If the second
    bit is 1, it means that fragmentation is prohibited. At this time, if the packet length exceeds the MTU, the IP module will discard the packet. The third bit
    means "more fragments". If fragmented, the last fragment is set to 1, and the others are 0. Similar to a closing tag.
  • 13-bit fragmentation offset (framegament offset): identifies the sequence of multiple packets. is the offset of the fragment relative to the beginning of the original IP packet. In fact, it indicates where the current fragment is in the original message. The actual number of bytes offset is obtained by this value * 8. Therefore, except for the last message, the length of other messages must be an integer multiple of 8 (otherwise the messages are not continuous).
  • 8-bit time to live (Time To Live, TTL): the maximum time a piece of data can be transmitted on the network. The unit of this time is not "seconds", but "times". When a datagram is constructed, there will be a first-know TTL value (such as 32/64/128...) each time this report is forwarded by a router with TTL-1. If it has been reduced to 0 and the target has not been reached, it is considered at this time The package will never arrive. It can be discarded.
  • 8-bit protocol: describes which protocol the content of the current payload belongs to. (TCP/UDP)
  • 16-bit header checksum: only the header needs to be checked here, and the payload part (TCP/UDP datagram) itself already has a checksum. If the checksum is inconsistent, it can be discarded directly.
  • 32-bit source address and 32-bit destination address : The IP addresses seen here are 32-bit integers. What we see every day 161.185.187.142is expressed in dotted decimal notation . (Use three .to divide the 32-bit 4-byte number into four parts, and each part is 0-255represented by a decimal integer.)

The so-called address is expected to be different for each device. But with the development of the times, 32-digit numbers can only represent 4.29 billion numbers, that is, IP addresses are not enough. To solve this problem, there are many ways:

  1. Dynamically assign IP addresses.

  2. NAT Network Address Translation. In essence, it is to use an IP to represent a batch of devices.
    In the context of NAT, IP addresses are divided into two categories:
    (1) Intranet IP (private IP) 10.* , 172.16.*-172.31.* , 192.168.*
    (2) External network IP (public IP) and the rest is public IP

    NAT requires that the public network IP must be unique, and the private network IP can appear repeatedly in different LANs.
    If a device in a private network wants to access a device in the public network, a corresponding NAT device (router) is required to map the IP address to complete network access.
    Conversely, devices on the public network cannot directly access devices on the private network. Devices on private networks of different LANs cannot directly access each other.
    As long as the intranet IP is not repeated within the LAN, it can be repeated in different LANs.
    The NAT mechanism can effectively solve the problem of insufficient IP addresses, but it makes the network environment more complicated.

  3. IPv6: fundamentally solves the problem of insufficient IP. Use 16 bytes to represent an IP address.

At present, the world still uses NAT+Ipv4+dynamic allocation for network construction.

address management

The IP address is divided into two parts, the network number and the host number
. Network number: identifies the network segment, ensuring that the two network segments connected to each other have different identifications;
host number: identifies the host, and within the same network segment, the hosts have the same The network number, but must have a different host number;
that is, under normal circumstances: 192.168.0.10in IP: 192.168.0the network number 10is the host number.
insert image description here
From where to where an IP address goes is the network number, and from where to which is the host number, which is determined by the subnet mask .
insert image description here
Part 1 describes how many bits of the IP are network numbers.

routing

Routing is planning a path equivalent to using a map to navigate.
Since the real network environment is very complex, any node (router) cannot perceive the whole picture of the network environment. A router only knows some of its neighbors at most. If you want to forward a relatively long path, it will be more troublesome.

data link layer protocol

Consider the transmission between adjacent nodes. (two devices directly connected via network cable/optical fiber/wireless)

ethernet protocol

Ethernet frame format:
insert image description here
Ethernet data frame = frame header + payload + frame trailer Frame
header: contains destination address (mac address (physical address)), source address, type.
Payload: The complete IP datagram.

How do IP and mac work with each other?
IP is used to describe the starting and ending points of the entire transmission process, and mac is used to describe the starting and ending points of two adjacent nodes.
insert image description here

This is another protocol in the data link layer: the ARP protocol.
Through this protocol, a router/switch can recognize other devices in the LAN. A table is created in the switch/router through the ARP protocol. This table is equivalent to a hash table, which can establish the mapping relationship between IP and mac.

PERSON

MTU is a data link layer data frame, which represents the maximum length that can carry data. (The length of the load)
The specific length of the load has a lot to do with the physical medium used. Of course, it also has a lot to do with the protocol used by the data link layer. For example, the Ethernet protocol MTU1500 bytes.
Formally, because of the MTU, the IP protocol is used to packetize and group packets.
IP sub-packet groups are usually not divided according to the maximum length of this IP. With a high probability, the MTU of the data link layer is smaller than 64kb.

Important Protocols at the Application Layer

DNS (Domain Name Resolution System)

In fact, to access a server on the network, you need an IP address. But the IP address is too difficult to pronounce, so some simple words are used to form a string to represent this address. Each domain name corresponds to one/N IP addresses. That being the case, it is necessary to be able to map domain names and IP addresses.
In the early days, there were very few servers on the Internet. The mapping relationship between the domain name and IP was only maintained by using a hosts file. Each user only needed to manually create his own hosts file. Today’s computers still have this file , can also be used.
insert image description here
Later, the Internet developed vigorously, and now many new websites are born every day. At this time, it is unrealistic to rely on mobile phones for maintenance, so now there is a DNS server to maintain the mapping relationship between domain names and IPs. When When you want to access a domain name, it will automatically request the DNS server, and then return the specific IP address for access.

If the DNS server configuration of the computer is wrong, or the DNS server is down, a typical situation will occur: when the network is normal, applications such as QQ can be used, but the web page cannot be opened.

The DNS server of our own computer can be configured as follows,

First open the "Advanced Network Settings" in the "Network and Internet" in the settings, and click "More Network Adapter Options".
insert image description here
Here you can configure the address of the DNS server yourself.

Guess you like

Origin blog.csdn.net/qq_61138087/article/details/131435092