Preface โšพ

As we all know, the computer network is the front end of the interview is very love test of the interview questions, have to say that the classic eight-part essay. When I started to contact the net on Monday, I also saw problems like three-way handshake and four-way handshake. At the beginning, my knowledge was relatively superficial, and my understanding of network knowledge was always limited to knowing some content. But as I learn more, I gradually feel that before I know something, it is not only necessary to know what it is. And why is it there? What problem does it solve? Such learning will be more conducive to applying it to our daily development.

In the following article, I will share a process of learning network planning in the process of preparing for the autumn recruitment exam, as well as some questions about the regular examination of network planning.

Below begins to enter today’s article explanation ~๐Ÿ˜œ

๐Ÿ 1. Basic knowledge

1. Column learning

At the beginning, I was faced with a very heavy book, U1S1, which was issued by the school. Facing the book with nearly 1000 pages, MY heart was really broken. Later, by chance, I saw the article of a front-end blogger on a public account. Then I saw many of his selected columns on CSDN. After reading his blog, I unconsciously felt that… I didn’t know there was such a good article. This is a bit too much nonsense… ๐Ÿ˜œ

I was learning the first zero one blogger’S TCP column, the blogger’s every article is very friendly to small white type, very easy to understand. A link to the TCP column is attached below at ๐Ÿ‘‡

The serial number The article link
1 TCP/IP Overview of network layering and protocols Lpyexplore.blog.csdn.net/article/det…
2 TCP/IP Indicates the division and classification of IP addresses Lpyexplore.blog.csdn.net/article/det…
3 [TCP/IP] a simple understanding of link layer Lpyexplore.blog.csdn.net/article/det…
4 TCP/IP Explain the DNS process in detail Lpyexplore.blog.csdn.net/article/det…
5 TCP/IP illustrates the communication mechanism of TCP Lpyexplore.blog.csdn.net/article/det…
6 Column portal Blog.csdn.net/l_ppp/categ…

The above articles can be learned in order

2, books learning

After learning the above five blogs, it took about 15-20 hours. After reading, it is a little inside the door. But there’s more to it than that, so after studying the blog posts, I continued to dig deeper with books.

I searched zhihu and Douban, as well as the recommendation of my friends around me. Everyone said that the book which is friendly to the front end is: “Illustrated TCP/IP”. See below ๐Ÿ‘‡

This book explains much of computer networking in graphical form. It is too friendly for beginners and readers who get sleepy when reading books. Strong Amway!

After reading this book, it’s basically enough to handle the interview. If you still want to dig deeper, you can read the book with the dark cover… I’ve just heard of it, but I haven’t seen it, so here’s a brief summary

Once you have the basics ready, look at some of the interview questions and try to review them and answer them in your own words. At the same time, in the following content of the article, I will also sum up the series of topics I met ~

โšฝ 2. Mind mapping

Let’s start with a mind map to understand the knowledge system of this series of surface problems. The details are as follows: ๐Ÿ‘‡

With mind mapping in the bag, here’s how to solve the problem

๐ŸŽณ 3. OSI seven-layer model

1. What is the OSI model?

The OSI seven-layer model is the seven layers of network communication. It is divided into seven levels so that developers can implement different parts of the entire system in different areas. Just like a very large project, each employee has his own good position and specialized work.

Then the seven layers mainly include: physical layer, data link layer, network layer, transmission layer, session layer, presentation layer and application layer.

Then we talk about the role of each level.

The first one is the application layer. The application layer provides services to the application and specifies the details related to communication within the application. Protocols include file transfer, email, and remote login (virtual terminal).

Second, the presentation layer. The presentation layer converts the information processed by the application into a format suitable for network transmission, or converts the data from the next layer into a format that can be processed by the previous layer. Therefore, it is mainly responsible for data format conversion.

Third, the session layer. The session layer is responsible for establishing and disconnecting communication connections, as well as data segmentation and other data transfer related management.

Fourth, transport layer. The transport layer plays the role of reliable transmission, and it is only processed on the nodes of the communication parties, not on the router.

Fifth, the network layer. The network layer transmits data to a destination address, which can be an address that multiple networks connect to through routers. This layer is therefore responsible for addressing and routing.

Sixth, data link layer. The data link layer is responsible for the communication transmission among nodes connected at the physical layer.

Seventh, the physical plane. Responsible for 0, 1 bit flow (0, 1 sequence) and the high voltage, the light between the exchange.

2. The OSI seven-layer model follows principles

The OSI reference model follows five principles:

  • There are clear boundaries between the levels to facilitate understanding of the functions of each level;

  • Each layer implements different functions and does not affect each other;

  • Between layers is the relationship between service and served;

  • Hierarchical division is beneficial to the formulation of international standard agreement;

  • The more layers you have, the more you can avoid functional duplication between layers.

๐Ÿ 4. TCP and UDP

1. Differences between TCP and UDP

TCP UDP
TCP is at the transport layer UDP is at the transport layer
connection-oriented Connectionless oriented
Word oriented stream For a message
One-to-one communication One-to-one, one-to-many, many-to-one, many-to-many communication
Reliable connections need to be established There is no need to establish a reliable connection
Suitable for reliable transmission applications, such as Web Browsing, email, and file transfer Suitable for real-time applications: online games, live streaming, IP phone calls, voice conferences, and so on

Answer in Plain English:

  • TCPIt’s connection-oriented,UDPIs connectionless, i.eBefore sending dataNo connection is required.
  • TCPProvide reliable transmission service throughTCPConnect the transmitted data, error – free, not lost, not repeated, and arrive in sequence, whileUDPIs the best possible delivery, no guarantee of reliable transmission.
  • Therefore, becauseTCPReliable, connection-oriented and without data loss, soTCPSuitable for exchange of large amount of data.
  • TCPByte stream oriented, actuallyTCPThink of the data asA series of unstructured byte streams;UDPIt is packet-oriented and has no congestion control. Therefore, when the network is congested, the sending rate of the original host will not be reduced, but packet loss will occur during the process, so it is useful for real-time applications, such asIPPhone calls, video conferencing and live streaming.
  • eachTCPConnections can only be one-to-one,UDPSupports one-to-one, one-to-many, many-to-one, and many-to-many interactive communication.
  • TCPThe first cost of is20 bytesAnd theUDPThe only8 bytes.
  • To sum up,TCPIs connection-oriented reliability transmission, whileUDPIs not reliable.

Note: TCP connections need to be established for three times, and TCP packets can be sent in groups. Therefore, connection establishment and grouping costs are incurred.

2. Advantages and disadvantages of TCP/UDP

(1) The advantages of TCP

  • Reliable and stable.

  • The reliability of TCP is reflected in the fact that TCP has three handshakes to establish a connection before transmitting data.

  • And in data transmission, there are confirmation, window, retransmission, congestion control and other mechanisms;

  • It also saves resources by disconnecting after the data has been transferred.

(2) Disadvantages of TCP

  • Slow, inefficient, occupy high system resources, vulnerable to attack.
  • TCPBefore transferring data, a connection needs to be established, which consumes time;
  • In addition, confirmation mechanism, retransmission mechanism and congestion control mechanism will consume a lot of time when transmitting data.
  • At the same time, all transport connections are maintained on each device, in fact, each connection will occupy the systemCPU, memory and other hardware resources;
  • And, becauseTCPThere’s a three-way handshake, which can also lead toTCPEasy to be taken advantage ofDOS ใ€ DDOSSuch attacks.

(3) Advantages of UDP

  • Faster and slightly more secure than TCP.
  • UDPIs a stateless transport protocol, andUDPThere is noTCPHandshakes, confirmations, Windows, retransmissions, congestion control, etc., so it’s very fast at transferring data. There is noTCPAnd these mechanisms,UDP ่พƒ TCPThere are fewer vulnerabilities for attackers to exploit.
  • butUDPIt is also impossible to avoid attacks, such as:UDP floodAttack.

(4) Disadvantages of UDP

  • Unreliable and unstable.
  • becauseUDPThere is noTCPThose reliable mechanisms, so when it comes to data transfer, if the network quality is not good, it’s very easyPacket loss.

3, DDOS attacks (caused by the shortcomings of TCP and UDP DDOS attacks)

(1) What is a DDOS attack?

  • Distributed denial of sevice attacks;
  • That is to make a large number of simultaneous service requests to the target system.

(2) DDOS attack mode?

How does the attacker attack the target host?

  • To interfere with or even block normal network communication by overloading the network.
  • Overload the server by flooding it with service requests.
  • Block a user from accessing the server.
  • Blocks communication between a service and a specific system or individual.

(3) How to deal with DDOS attacks?

  • The blacklist.
  • DDOSCleaning: Data requested by usersReal-time monitoringIn timeDOSCleans abnormal traffic, such as attack traffic, without affecting services.
  • CDNTo speed up.
  • High imitation server: A high imitation server is capable of independent defenseMore than 50 GBPS ( 1Gbps=1024Mbps, or 1,000 megabits per second) servers that can help websitesDenial of service attack, regular scanningNetwork master node.

4. Why is TCP reliable?

  • TCPthroughInspection and,The serial number,Confirmation reply,Retransmission control,Connection managementandWindow controlAnd other mechanisms to achieve reliable transmission.
  • So how to achieve reliable transmission through the above mechanism?
  • inTCPWhen data from the sender reaches the receiving host, the receiving host returns a notification that the message has been received. This message is called an acknowledgement reply(ACK). (Confirm the response)
  • On the contrary, after the sender sends data, and does not wait for a confirmation response within a period of time, the data is likely to be lost.
  • If no acknowledgement is received within a certain period of time, the sender can assume that the data has been lost and resend it. Thus, even if packet loss occurs, data can still reach the peer end and reliable transmission can be achieved. (Retransmission of lost packets)
  • In addition, there may be some other reason for the delayed arrival of the acknowledgement, in which case the sending host will also retransmit the data according to the mechanism. (Delayed retransmission)
  • But this is a huge disaster for the target console. Because the target will receive the same data over and over again.
  • To do this, a new mechanism, serial numbers, needs to be introduced. The serial number identifies whether data has been received and needs to be received. (Serial number)
  • Serial numbers are given in order to each byte of data that is sentMark the number. The receiving end queries the received dataTCPThe serial number and the length of the data in the header, and send back the serial number you should receive next as a confirmation reply. (Serial number)
  • In this way, through the serial number, confirm the response mechanism, to achieveTCPReliable transmission.

Note: Serial numbers are mainly used to allow the receiver to discard data and return the next reply number, so that the same data is not received frequently.

TCP’s three-way handshake and four-way wave

(1) TCP three-way handshake

Scene simulation:

  • I’m on the phone with you, the interviewer. I’ll start by asking, hello, hello, can you hear me?
  • You’ll tell me back, I hear you! Can you hear me?
  • I’ll get back to you. Got it. We can start talking.

Three handshakes:

  • First, the client sends a message withSYNFlag packets to each other;
  • When received, the receiver returns a message withSYN/ACKFlag of the packet returned to the sender, on behalf of successful message delivery;
  • Then the sender sends back a packetACKFlag for the packet that represents the end of the handshake.

(2) why does TCP require three handshakes?

  • Verify that the server and client are compliantTCP/IPAgreement;
  • To prevent an invalid connection request packet segment from being sent to the server suddenly, an error may occur.

(3) FOUR waves of TCP

First wave:

  • The client process sends a connection release packet and stops sending data.

Second wave:

  • Server receivedConnection release message,Confirmation messageAt this point, the server startsclose-wait(Off wait) state. (The client releases data to the server, but the server sends data, and the client still receives it)
  • When the client receives an acknowledgement request from the server, the client entersFin-wait-2(Terminate wait 2) state, waiting for the server to sendConnection release message(The final data sent by the receiving server is needed before that).

Third wave:

  • After the server sends the final data, it sends a connection release message to the client and the server entersLast-ack(Final confirmation).

Fourth wave:

  • After receiving the connection release packet from the server, the client must send an acknowledgement message to enter the connectiontime-wait(Time wait) status.
  • Once the server receives an acknowledgement from the client, it immediately enters the serverclosedState.
  • At this point, the end of thisTCPThe connection. (Server EndTCPConnect earlier than the client)

(4) Why does TCP wave four times?

  • The reason for the four waves is to make sure that the data has been sent.

  • TCP is in full-duplex mode. When host 1 sends a FIN packet segment, it only indicates that host 1 has no data to send. Host 1 tells host 2 that all data has been sent.

  • When host 2 returns an ACK packet, it indicates that it knows that host 1 has no data to send, but host 2 can still send data to host 1.

  • If host 2 also sends a FIN packet segment, host 2 also has no data to send, and host 1 is told that host 1 has no data to send either.

  • Finally, host 1 sends an ACK packet to confirm the end of the handshake, and the two hosts happily disconnect the TCP connection.

(5) What is connection Oriented Protocol? What is connectionless Protocol?

Connection-oriented protocol:

  • When communicating with each other, a virtual communication line needs to be established in advance.
  • The communication process consists of three phases: establishing the connection, maintaining the connection, and disconnecting the connection.

Connectionless protocol:

  • In contrast to connection-oriented communication, the communication parties do not need to establish a communication line in advance, but send each packet with destination address to the communication line in groups, and the system independently selects the line for transmission.
  • A connectionless only “data transfer” process.

(6) Why is making a connection three times a handshake and closing a connection four times a wave?

  • When the connection is established, the server is inlistenReceived the request to establish a connectionSYNAfter the packet, the server sends itACK ๅ’Œ SYNSend it to the client in a packet.
  • When the connection is closed, the server receives theFINPacket only indicates that1.They’re not sending data anymore but they’re still receiving data, and2.You may not have sent all your data to the other party, so you can shut it down immediately, or you can send some data to the other party, and โ‘ข you can send it laterFIN The message is given to the peer to indicate agreement to close the connection now. Therefore, our own sideACK ๅ’Œ FINgenerallySend the, resulting in an extra one.

Note: โ‘ โ‘กโ‘ข indicates the first, second and third wave of the hand

(7) What if the connection has been established, but the client suddenly fails?

  • TCPThere is also aLife timer.
  • When the client fails, the server will not waste resources by waiting forever.
  • The server resets this timer every time it receives a request from the client, usually for a time of2hIf,2hWhen no data has been received from the client, the server sends oneProbe message segmentTo the client, every other75sSend once.
  • If there is no response after 10 probe segments are sent, the server assumes that the client is faulty and then closes the connection.

Note: 10 x75 = 750 s = 12.5 min

๐Ÿ’ 5. TCP communication mechanism

1. TCP retransmission control

  • As we all know, packet loss may occur in the process of data transmission for various reasons. When packet loss occurs, that is, after sending data and waiting for a period of time, the sender does not receive the response from the receiver, it is regarded as packet loss and resends the data.
  • Packet loss can be divided into two types: (1) Packet loss during sending; โ‘ก Packets are lost during receiving.
  • So, how long after the sender sends the data and does not receive an acknowledgement before deciding that the data packet is lost?
  • This generally changes as the network environment changes,TCPIt is calculated every time a packet is sentRound-trip timeAs well asdeviationTo determine the waiting time.
  • If packet loss occurs again after retransmission, the next waiting time increases exponentially by 2 times and 4 times.
  • However, it certainly will not be retransmitted indefinitely. When the retransmission times reach a certain extent [1], it will be judged as an abnormal network and the communication between the two ends will be forcibly closed.

[1] : TCP has a keepalive timer. If no data is received from the client after 2h, the timer will be reset. After that, the timer will be sent once every 75s.

2, TCP sliding window control

Problem solving:

  • What is the reason for a sliding window?
  • What problems can sliding Windows solve?

Answer in Plain English:

  • As we all know, data should not be sent at once, otherwise we don’t know where to find it if it is lost, so we should take measures to send it in segments.
  • But,TCPSending data in segments, while improving the reliability of transmission, has a fatal drawbackVery inefficient ใ€‚
  • Because each piece of data must wait for the receiving end to confirm the response before continuing to send, if the whole data is divided into many segments, the communication performance will be very lowTCPThe introduction of thewindowThe concept.
  • The so-called window means that multiple segments of data can be sent consecutively without waiting for a confirmation reply from the receiver.
  • For example: Suppose you want to send4Segment data, if each time to send after receiving to send again, then back and forth8Times. But with a sliding window, four pieces of data can be sent simultaneously, and the receiver sends back the corresponding acknowledgement to the sender.
  • At this time, the sender will continue to send data larger than the serial number in the confirmation sequence according to the corresponding acknowledgement reply.

3. Retransmission control of sliding Windows

  • If the sliding window technology is used, the packet loss of some data will not be greatly affected.
  • Because the receiver will receive the data from the sender side, while in some way to tell the sender side which piece of data is missing.

4. TCP traffic control mechanism

Why do you need a flow control mechanism?

  • Sometimes, the data sent by the sender to the receiver exceeds the maximum carrying capacity of the receiver. As a result, the data cannot be received. As a result, the data will be retransmitted later, which wastes performance.

How to solve this problem? Flow control mechanism

  • To prevent that from happening,TCPProvides a kind ofmechanism(i.e., flow control mechanism) to keep the data sent by the sender at the receiver as much as possibleWithin bearing range.
  • And the way to do that is,The receiving end ๅ‘ The senderTell yourself what you can receiveData sizeIn this way, the data sent by the sender will not exceed this value each time, which is regarded asThe window size.
  • If the receiver is temporarily unable to receive any data, it will inform the sender, so the sender will suspend the transmission of data.
  • However, for the normal transmission of subsequent data, the sender will send a window probe to the receiver from time to time to tentatively see whether the receiver can continue to receive data.

5. TCP congestion control

  • Due to the advent of window control, data is no longer sent in a segment, but sent in consecutive segments of packets, so sometimes if there is a network congestion, and we send a large number of packets at the same time, it is very likely to cause the network crash.
  • TCP mitigates this problem using a technique called slow start. So what is slow start?
  • Instead of sending a large number of packets all at once, send some first and then send more depending on how they are sent and received.
  • The summary is that each packet sent will end in1, 4-trichlorobenzeneBut the window size does not increase exponentially indefinitely. Instead, some adjustments will be made when a value is reached, calledSlow start threshold ใ€‚

The difference between flow control mechanism and congestion control mechanism:

  • Flow control is dominated by the receiving end, the receiving end is clear about the window size they want, and then the sending end sends the data to the receiving end;
  • The congestion control mechanism is dominated by the sending end. The sending end tentatively sends data to the receiving end in an exponential growth of 1,2,4 to detect the carrying capacity of the receiving end. When the receiving end can no longer receive data, the sending end will know that the receiving end can’t carry so much data, so it will adjust downward.

๐Ÿธ 6. Conclusion

In the above article, there are two ways to learn computer network knowledge, and 24 questions are used to help you better understand the content of computer network in the front-end interview.

For the front end, the content of the network survey will be relatively shallow, so Monday also used a more accessible way to comb out some classic topics. If you have friends who want to further study, you can also read books to enrich your knowledge

Finally, I wish all the friends who read this article can get their favorite offer ~

๐Ÿฃ Egg One More Thing

๐Ÿท๏ธ PDF

๐Ÿ‘‰ wechat public account Monday laboratory, click the navigation bar below the interview column briefly view the keyword to obtain ~

๐Ÿท๏ธ Update address

๐Ÿ‘‰ offer comes to the interview column

๐Ÿท ๏ธ set pieces

  • If you think this article is helpful to you, you might as well like to support yo ~~๐Ÿ˜‰
  • That’s all for this article! See you next time! ๐Ÿ‘‹ ๐Ÿ‘‹ ๐Ÿ‘‹