Technology Sharing

Common computer network interview questions (I)

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Common questions in computer network interviews involve multiple aspects, including network protocols, network architecture, network security, data transmission, etc. The following are detailed explanations of some common questions:

1. What is the OSI seven-layer model? What is the function of each layer?

OSI seven-layer modelIt is a standard system developed by the International Organization for Standardization (ISO) for interconnection between computer or communication systems. From top to bottom, it is:

  1. Application Layer: Provide interactive services for applications, such as HTTP, FTP, SMTP and other protocols.
  2. Presentation Layer: Data representation, security, and compression, converting application layer data into a format suitable for network transmission.
  3. Session Layer: Establish, manage, and terminate sessions, and organize and coordinate communications between two session processes.
  4. Transport Layer: Responsible for providing data transmission services for communication between two host processes, including TCP and UDP protocols, to achieve reliable data transmission.
  5. Network layer: Select appropriate routing and switching nodes to ensure timely data transmission, the main protocol is IP.
  6. data link layer: When transmitting data between two adjacent nodes, the IP datagrams handed down by the network layer are assembled into frames and necessary control information is added.
  7. Physical Layer:Realize transparent transmission of bit streams between adjacent computer nodes, shielding the differences in transmission media and physical devices as much as possible.

2. What is the difference between TCP and UDP?

TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) are both transport layer protocols. Their main differences include:

  1. Connectivity: TCP is a connection-oriented protocol, which requires a connection to be established before transmitting data; while UDP is a connectionless protocol, which does not require a connection to be established before sending data.
  2. reliability: TCP provides reliable transmission and ensures correct data transmission through mechanisms such as sequence numbers, confirmation responses, and timeout retransmission; UDP does not provide reliability guarantees, and data may be lost or arrive out of order.
  3. Transmission efficiency: Since TCP needs to establish a connection and perform reliability checks, its transmission efficiency is relatively low; UDP does not have these overheads and has a higher transmission efficiency.
  4. Application Scenario: TCP is suitable for application scenarios that require reliable transmission, such as file transfer, web browsing, etc.; UDP is suitable for application scenarios that have high real-time requirements and can tolerate a certain amount of data loss, such as live video streaming, online games, etc.

3. What is the difference between HTTP and HTTPS?

The main difference between HTTP (Hypertext Transfer Protocol) and HTTPS (Hypertext Transfer Protocol Secure) is security:

  1. safety:HTTP transmits plain text, and the data is easily intercepted and tampered with; HTTPS adds the SSL/TLS protocol layer on the basis of HTTP to encrypt the data transmission and ensure the security of data transmission.
  2. The port number: HTTP uses port 80 by default; HTTPS uses port 443 by default.
  3. performance: Since HTTPS requires encryption and decryption operations, its performance will be lower than that of HTTP.

4. What is the process of TCP three-way handshake and four-way wave?

TCP three-way handshakeThe process is as follows:

  1. The client sends a SYN packet (synchronization sequence number) to the server and enters the SYN_SENT state, waiting for the server to confirm.
  2. After receiving the SYN packet, the server confirms the client's SYN (ack=j+1) and sends a SYN packet (i.e., SYN+ACK packet) at the same time. At this time, the server enters the SYN_RCVD state.
  3. After the client receives the SYN+ACK packet from the server, it sends a confirmation packet ACK (ack=k+1) to the server. After this packet is sent, the client and server enter the ESTABLISHED state and complete the three-way handshake.

TCP four times waveThe process is as follows:

  1. The client sends a FIN to close the data transmission from the client to the server, and the client enters the FIN_WAIT_1 state.
  2. After receiving the FIN, the server sends an ACK to the client, confirming that the sequence number is the received sequence number + 1 (the same as SYN, one FIN occupies one sequence number), and the server enters the CLOSE_WAIT state.
  3. The server closes the connection with the client, sends a FIN to the client, and enters the LAST_ACK state.
  4. After receiving the FIN, the client sends an ACK to the server, confirming the sequence number is the received sequence number + 1, and the client enters the TIME_WAIT state. After receiving the ACK, the server closes the connection. If the client still does not receive a reply after waiting for 2MSL, it enters the CLOSED state.

5. Why does TCP require three handshakes instead of two?

The main reason why TCP requires a three-way handshake instead of a two-way handshake is to ensure that both parties have the ability to receive and send data, thereby establishing a reliable connection. Specifically:

  • First handshake: The client sends a SYN packet, and the server confirms the client's sending capability.
  • Second handshake: The server sends a SYN+ACK packet, and the client confirms the server's receiving and sending capabilities.
  • The third handshake: the client sends an ACK packet, and the server confirms the client's receiving capability.

If there are only two handshakes, the following situation may occur: the client sends a connection request, but does not receive a confirmation because the connection request message is lost, so the client retransmits the connection request. Later, the confirmation is received and the connection is established. After the data transmission is completed, the connection is released. The client sends a total of two connection request segments, the first of which is lost and the second reaches the server. However, the first lost segment is just stranded for a long time at some network nodes, and it is delayed until a certain time after the connection is released before it reaches the server. At this time, the server mistakenly believes that the client has sent a new connection request, so it sends a confirmation segment to the client and agrees to establish a connection. Since the client has not sent a data request at this time, the server will wait for the client to send data, resulting in a waste of resources.

6. What are the commonly used HTTP request methods? What are their differences and uses?

Common HTTP request methods include GET, POST, PUT, DELETE, CONNECT, OPTIONS and TRACE, among which GET and POST are the most commonly used.

  • GET: Used to send a request to obtain data on the server. The parameters are included in the URL and are suitable for scenarios where the amount of requested data is not large and security requirements are not high.
  • POST: Used to submit data to the resource specified by the URL. Parameters are passed through the request body and are suitable for submitting large amounts of data or for scenarios with high security requirements.

Other request methods such as PUT and DELETE are used to modify data on the server, delete resources on the server, etc. These request methods have their own specific uses and applicable scenarios.

The above is a detailed explanation of the common questions in computer network interviews. These questions cover many aspects such as network protocols, network architecture, data transmission, etc., and are important contents for testing the applicant's computer network knowledge.