Interview surprise: talk about the TCP/IP protocol? Do you understand what each layer does?

2022.07.22
Interview surprise: talk about the TCP/IP protocol? Do you understand what each layer does?

The role of the application layer is responsible for data communication between applications. Different network applications require different application layer protocols, such as e-mail transmission SMTP protocol, file transmission FTP protocol, network remote access Telnet protocol and so on.

TCP/IP contains a four-layer model, from the upper layer to the lower layer: the application layer, the transport layer, the network layer, and the data link layer. Some materials will also say that TCP/IP is a five-layer model. The so-called five-layer model means that there is a physical layer under the data link layer. As a software engineer, you generally do not need to pay attention to the physical layer, so we usually say TCP/IP. The IP four-layer model is more.

1. Application layer

The role of the application layer is responsible for data communication between applications. Different network applications require different application layer protocols, such as e-mail transmission SMTP protocol, file transmission FTP protocol, network remote access Telnet protocol and so on.

Common agreement

There are two common protocols at the application layer:

DNS Domain Name System (Domain Name System), DNS is a mapping between domain name and IP, because the communication between programs relies on IP, but the IP address is not easy to remember, and the domain name is easy to remember, so the two are used as A key-value is mapped together, so that the corresponding IP can be found after knowing the domain name replacement, which is convenient for users to memorize, and at the same time, it can satisfy the data communication between programs.

HTTP (HyperText Transfer Protocol) is the most widely used network protocol on the Internet. All WWW (World Wide Web) documents must comply with this standard.

2. Transport layer

The main role of the transport layer is responsible for data transmission between two hosts. Such as Transmission Control Protocol (TCP), which can ensure that data is reliably sent from the source host to the destination host.

Note: The subject objects described by the application layer and the transport layer are different. The subject of the application layer description is "between applications", and the subject of the transport layer description is "between two hosts". Among them, a host can contain multiple applications, so the two are different.

Common agreement

There are two common protocols at the transport layer:

  • TCP (Transmission Control Protocol): Provides a stable, connection-oriented, byte-stream-oriented protocol.
  • UDP (User Datagram Protocol): Provides a connectionless, unstable, datagram-oriented protocol.

3. Network layer

The role of the network layer is responsible for address management and routing on the network. During data communication, you can choose many paths (to the destination), for example, from Xi'an to Beijing, you can choose from Xi'an->Taiyuan->Beijing, or choose from Xi'an->Zhengzhou->Shijiazhuang->Beijing, You can also choose from Xi'an -> Yan'an -> Hohhot -> Zhangjiakou -> Beijing, which way to choose? This is the responsibility of the network layer.

4. Data link layer

The role of the data link layer is to be responsible for the transmission and identification of data frames between devices. When data is transmitted, it needs to pass through multiple devices for data transmission, and the data link layer is responsible for data transmission and identification between adjacent devices. The data link layer can completely eliminate the difference between the network layer and the physical layer, and effectively identify and transmit data at the link layer.

5. Physical layer (optional)

The role of the physical layer is to convert data into signals, and then convert signals into data. The conversion method varies depending on the communication medium, so there is no specific protocol.

Summarize

TCP/IP contains a five-layer (or four-layer) model, from the upper layer to the lower layer:

  • Application layer: responsible for data communication between applications.
  • Transport Layer: Responsible for data transfer between two hosts.
  • Network layer: Responsible for network address management and routing.
  • Data link layer: responsible for the transmission and identification of data frames between devices.
  • Physical layer (optional): Responsible for the conversion between data and signals.