Writing in the front

The whole summer vacation go to the interview, interview a lot of companies, whether small factory or a company) asked about the depth of the different network theory is the most easy to interview questions, though we seldom go to practice it in the project, but understand its principle, makes us behind if the network communication works, can show you in front of the interviewer is the basis of a solid, We can also have more understanding of this part of the study in the future.

Many students will memorize this part when preparing for the interview, which is really difficult to master. Personally, I concluded that the best way to learn network principles is not to memorize them deliberately, but to fully understand the whole principle in combination with reality. It may be hard to learn at first, but use a little attention, read it a few times, ask yourself why, and think of yourself as a developer of network principles. It’s enough to prepare for the interview with clear logic rather than memorizing this part.

And there are many ways interviewers can ask the same questions, but many of them are just the same. One of the things I remember most is typing in the URL, going to the page and rendering it, what happens? The background of this interview question involves a lot of knowledge about network principles. We will not share all of them in this article. Instead, we will first make clear the origin and network hierarchy division to complete the purpose of this article.

First, why network hierarchy division?

Speaking of the network level division is not strange, I just touched the network level when a face meng force, so many layers, a layer is not on the line? There are many protocols between layers, and there are various packets. I gave up the first time.

When I picked up the network layer again, I was determined to understand it from its roots. First understand its principle, it must know its origin, that is, why to carry out network hierarchy division? That’s a good question.

If “the deer” is a web developer, at first thought of communication between the computer and the computer can complete the communication, only need a thread to the right, but the world so big, so many computer, distance and far, not only waste line, haven’t appear all sorts of line secretly cut by you, there is no doubt that communication between the computer wouldn’t work. (Wireless network came out later. Although the connection between gateway and route was also needed, each computer was not connected in pairs, but connected to each other in a unit of area.)

No, the boss said, “the deer” you give me a way to change, change not to come out can’t sleep tonight, “the fawn carefully wanted to think,” this is a technical process, the need for comprehensive improvement, also found that the so-called computer connection can only be transmitted between 0 and 1 signal, another computer do not know what so many 0, 1, on behalf of, And “deer” also found that the production of computers from different manufacturers since there is a connection to realize communication is also very troublesome, simply define a set of rules, no matter “master” computer or “want” computer, must obey this set of rules, in fact, this set of rules is what we often say “network protocol”.

The origin of the network layer, how to talk about the network protocol. Let’s continue, through the above question, the problem of sending 0 and 1 signals between computers through the wire although the rules of communication, but in addition to such meaningless signals like 0 and 1, there are other kinds of problems in the network, how to identify two computers? And how to find out their address? And how different computer applications know they are passing data to themselves, and how different communication data formats are specified.

Deer found that if all the questions were written down in a set of protocols that set the rules for communication between the two parties, but what? If some rules have communication problems and affect other rules, the most common one is packet. If a packet contains various protocols, it will be chaotic.

“Deer” in order to be able to design it better, decided to adopt a hierarchical structure, which can not only define the functions of different layers, but also realize the changes between layers without affecting each other, which is the benefits we often hear of network hierarchical division.

Second, how is network stratification stratified?

Now that we’ve decided to layer, how many layers should we do?

The original network layer was the standard seven layer, or OSI seven layer model.

Reference model is a standard system for interconnection between computer or communication systems developed by the International Organization for Standardization (ISO), commonly known as OSI reference model or seven-layer model.

We also know the TCP/IP four-tier model and the TCP/IP five-tier model. In fact, the so-called TCP/IP four layer model and TCP/IP five layer model is based on the OSI seven layer optimization, merging some layers, in fact, is still essentially the same, but my personal favorite to use five layer to explain.

Three, what is the role of each layer?

This part involves many protocols and knowledge points of each layer, but we do not share them in detail in this section. Why? We must before concrete deep brain has a specific network layered structure, want to know what to do each layer is first, the relationship between layer and layer, and then in the next section into how each protocol in each layer of communication, the benefits of such learning coherent, and not when I was learning the surface also do not understand, is deeply meng finally forced state.

3.1 the physical

The physical layer, as the name suggests, connects computers physically, just as we talked about the physical connections between computers. It is mainly used to transmit 0 and 1 signals, which has been analyzed above. After all, 0 and 1 signals do not have any practical significance, so we use another layer to specify what the meaning of different combinations of 0 and 1 is.

3.2 Data link Layer

Since the physical layer of the lower layer cannot specify what meanings the signals of different combinations of 0 and 1 represent, we can specify a set of protocols in the data link layer to specifically group 0 and 1 signals and specify what meanings the different groups represent, so that both computers can identify. This protocol is called the Ethernet protocol (the Ethernet protocol details are described in the next section).

But the question is, how do we identify each other and how do we know their address when we send them to each other’s computers?

3.2.1 MAC address

What do we mean by MAC addresses? It is the unique identifier of a computer device on the network. It is identified as a MAC address by a hexadecimal number since the computer is produced by the manufacturer.

Now that we know the MAC address as the identifier, how do we know the MAC address of the computer we’re communicating with?

3.2.2 radio

And I’m going to talk about broadcasting in more detail in the next video, but all you need to know in this video is that broadcasting helps us know each other’s MAC addresses. So now that we know the MAC address, we can communicate? There are two situations in broadcast. One is that a computer in the same subnetwork (in the same LAN) obtains the MAC address of the other computer through ARP. Different networks (different Lans) are assigned to the gateways (routers) of the two Lans for processing. There’s a lot of detail here that I’ll focus on in the next section, but in this section you just need to know how to identify a computer and how to get a MAC address.

3.3 the network layer

Both the physical layer and the data link layer have their work to do, which is what we covered above (many of which are not covered in detail in this section). It seems to me that the upper two layers can complete normal communication, so what is the network layer doing?

The origin of the network layer is because in the data link layer, we say that the communication between two computers is divided into the same sub-network and different sub-network, then the problem comes, how to judge whether two computers are in the same sub-network (LAN)? That’s what the network layer is all about.

3.3.1 IP

The IP address that we usually use, that’s the thing at the network layer, the protocol that’s specified is the IP protocol. The IP address must also be an address. The MAC address has a unique identifier on it. To make it easier for you to understand IP address and MAC address, we can abstract the IP address into a logical address, that is, the MAC address is a physical address, that is, fixed. IP addresses are dynamically assigned, not fixed.

We use IP addresses to determine whether two computer devices are in the same subnetwork, so how does it determine that, you ask, and who assigns it IP addresses? And how to allocate some of the questions, we are not in a hurry, here just say about the general process, a detailed follow-up to write a big.

Since we use IP addresses to determine whether two computers are in the same LAN, we need to know each other’s IP addresses first. DNS resolution As you know, you can resolve a domain name to an IP address. Ok, we know the IP addresses of two computers, how to determine whether the same LAN?

3.3.2 Subnet mask

Hey hey, is a only heard of, but do not know this what function of a noun, have no matter, wait me to chat, you understand is to do what.

Subnet masks are used to identify IP addresses in the same LAN. Okay? What information? An IP address consists of 32 binary bits, that is, four decimal bits (for example, 255.255.255.000).

Subnet mask is made up of 32 bits, but can only use 0 or 1, such as 11111111.11111111.11111111.00000000.

What does that mean? The 1 part represents the network part and the 0 part represents the host part. How does this relate to whether two computers are on the same LAN? Yes, it does! An operation (AND operation) is performed on the IP addresses of the two computers AND their subnet masks. If the result is the same, the two computers are on the same LAN; otherwise, they are not.

How to calculate AND, the composition of IP packets AND other issues will not be described here.

3.4 the transport layer

Well, if you think computers can communicate, then “xiaolu” congratulations to you, you have basically understood the function of the above layers, but if you are playing LOL while chatting with your friends on QQ, suddenly, the chat information of your teammates in the game appears in the QQ window, huh? What happened?

In fact, the above level is not enough, the above reason is that, although two computers can communicate, but every day the computer is running a lot of programs, who knows the information you transmit belongs to which programs, can not complain about LOL chat information ran to the QQ window.

You can guess what the transport layer is used for. Yes, the transport layer’s main function is to enable “port to port” communication. Different programs running on the computer are assigned different ports, so that data can be correctly transferred to different applications.

3.4.1 track the UDP protocol

Adding port numbers also requires a set of rules, that is, UDP protocol, but UDP protocol has a disadvantage, once the communication, do not know whether the other party has received the data, we define a set of rules, so that it can confirm with the other party, then TCP appeared.

3.4.2 TCP protocol

We usually talk about the TCP triple handshake and the four wave, yeah, that’s what’s done in the transport layer, the TCP triple handshake involves a lot of content thieves, you could write a long article on it alone, I’m not going to state it here, you know that it’s done in the transport layer and what it does, you can recognize it.

3.5 Application Layer Protocols

“Feed, what you send me is broken data, disorderly of, my TM ability parse? Can you send it to me according to my rules? “

“Okay, not next time.”

You’ve probably guessed the application layer protocol, which dictates the data format of the application. The format of email, HTTP, and FTP data that we often use is defined at the application layer.



Beg praise: original not easy, beg a praise!

The article may be wrong and inadequate, but also to correct. Because the network principles section covers a large amount of knowledge, today’s article is sufficient to get a start on the layering model of networks. The follow-up article will continue to update, if you feel good, for praise, for forwarding, for attention oh!

Github is constantly updated

Github: Follow me on Github Blog!