Easy Tutorial
❮ Javascript Check Arrayisobject Html Meta Intro ❯

Summary of Basic Knowledge of Computer Networks

Classification Programming Technology

The core content of computer network learning is the study of network protocols. Network protocols are a set of rules, standards, or agreements established for data exchange in computer networks. Because different users' data terminals may adopt different character sets, and the two need to communicate, they must do so based on certain standards. A very vivid analogy is our language; our vast country has a rich variety of local languages, and the gap between dialects is huge. Dialects from Area A may be completely unacceptable to people from Area B, so we need to establish a language standard for the whole country to communicate, which is the role of our Mandarin. Similarly, globally, our standard language for communicating with foreign friends is English, which is why we have to study English hard.

Computer network protocols, like our languages, are diverse. ARPANET, a network protocol launched by ARPA between 1977 and 1979, was widely popular, mainly because it introduced the well-known TCP/IP standard network protocol. The TCP/IP protocol has now become the "universal language" of the Internet. The following figure is a schematic diagram of different computer groups communicating using TCP/IP.

1. Network Hierarchy Division

In order to enable computers produced by different computer manufacturers to communicate with each other, and to establish computer networks on a larger scale, the International Organization for Standardization (ISO) proposed the "Open System Interconnection Reference Model" in 1978, known as the famous OSI/RM model (Open System Interconnection/Reference Model). It divides the communication protocol of computer network architecture into seven layers, from bottom to top: Physical Layer, Data Link Layer, Network Layer, Transport Layer, Session Layer, Presentation Layer, and Application Layer. The fourth layer completes the data transmission service, and the top three layers are user-oriented.

In addition to the standard OSI seven-layer model, there are also common network hierarchy divisions such as the TCP/IP four-layer protocol and the TCP/IP five-layer protocol. The correspondence between them is shown in the following figure:

2. OSI Seven-Layer Network Model

The TCP/IP protocol is undoubtedly the foundation of the Internet. Without it, it is impossible to go online, and any operation related to the Internet is inseparable from the TCP/IP protocol. Whether it is the OSI seven-layer model or the TCP/IP four-layer or five-layer model, each layer has its own exclusive protocol to complete its corresponding work and communicate with the upper and lower levels. Since the OSI seven-layer model is the standard division of network hierarchy, we take the OSI seven-layer model as an example to introduce from bottom to top.

1) Physical Layer

Activate, maintain, and close the mechanical, electrical, functional, and procedural characteristics between communication endpoints. This layer provides a reliable physical medium for the upper-layer protocols to transmit data. In simple terms, the physical layer ensures that raw data can be transmitted on various physical media. Remember two important device names in the physical layer: repeaters (also known as amplifiers) and hubs.

2) Data Link Layer

The data link layer provides services to the network layer based on the services provided by the physical layer. Its most basic service is to reliably transmit data from the network layer to the target machine's network layer of the adjacent node. To achieve this goal, the data link must have a series of corresponding functions, mainly including: how to combine data into data blocks, which are called frames in the data link layer, and frames are the transmission units of the data link layer; how to control the transmission of frames on the physical channel, including how to handle transmission errors, how to adjust the transmission rate to match the receiver; and the management of establishing, maintaining, and releasing data link connections between two network entities. The data link layer provides reliable transmission on an unreliable physical medium As the application of the Internet continues to expand, the drawbacks of the original IPv4 are gradually exposed, namely that too many bits are occupied by the network number, while too few bits are allocated for the host number, making the available host addresses increasingly scarce. Currently, in addition to using NAT to allocate reserved addresses within enterprises, a high-level IP address is usually further divided to form multiple subnets for use by different scales of user groups.

The main purpose here is to effectively utilize IP addresses in the case of network segmentation, by taking the high-order part of the host number as the subnet number, expanding or compressing the subnet mask from the usual network boundary to create more subnets for a certain class of address. However, when creating more subnets, the number of available host addresses on each subnet will be reduced compared to the original.

What is a subnet mask?

A subnet mask is used to indicate whether two IP addresses belong to the same subnet, and it is also a 32-bit binary address, where each bit is 1 representing a network bit and 0 representing a host bit. Like IP addresses, it is also represented in dotted decimal notation. If two IP addresses have the same result when calculated with the subnet mask bit by bit, it means they belong to the same subnet.

When calculating the subnet mask, we need to pay attention to the reserved addresses in the IP address, that is, the "0" address and the broadcast address, which refer to the IP addresses when the host address or network address is all "0" or "1", representing the local network address and broadcast address, which are generally not included in the calculation.

Calculation of subnet mask:

For IP addresses that do not need to be further divided into subnets, the subnet mask is very simple, that is, according to its definition, such as a certain B class IP address 10.12.3.0, which does not need to be further divided, then the subnet mask for this IP address is 255.255.0.0. If it is a C class address, then its subnet mask is 255.255.255.0. Other classes are similar and will not be described in detail. The following is the key to introduce an IP address that still needs to be divided into a subnet network number with its high-order host bits, and the remaining is the host number of each subnet, so how to calculate the mask for each subnet.

Here is a summary of common interview questions related to subnet masks and network division:

1) Calculate using the number of subnets

Before calculating the subnet mask, it is necessary to understand the number of subnets to be divided and the number of hosts required in each subnet.

(1) Express the number of subnets in binary;

For example, to divide a B class IP address 168.195.0.0 into 27 subnets: 27 = 11011;

(2) Obtain the number of bits of this binary, which is N;

This binary is a five-digit number, N = 5

(3) Obtain the class subnet mask of this IP address, and set the first N bits of the host address part to 1 to obtain the subnet mask for the IP address division.

Set the first 5 bits of the host address of the B class address subnet mask 255.255.0.0 to 1, and get 255.255.248.0

2) Calculate using the number of hosts

For example, to divide a B class IP address 168.195.0.0 into several subnets, each with 700 hosts:

(1) Express the number of hosts in binary;

700 = 1010111100

(2) If the number of hosts is less than or equal to 254 (note to remove the two reserved IP addresses), then obtain the number of bits of the host in binary, which is N, here N < 8. If it is greater than 254, then N > 8, which means that the host address will occupy more than 8 bits;

This binary is a ten-digit number, N = 10;

(3) Use 255.255.255.255 to set all the host address bits of this class IP address to 1, and then set the last N bits to 0 from the back to the front, which is the subnet mask value.

Set all the host addresses of the B class address subnet mask 255.255.0.0 to 1, and get 255.255.255.255, and then set the last 10 bits to 0 from the back to the front, which is: 11111111.11111111.11111100.00000000, that is, 255.255.252.0. This is the subnet mask for the B class IP address 168.195.0.0 that wants to be divided into 700 host Imagine for a moment, if you are the client and you want to disconnect from the server, what should you do? The first step is to stop sending data to the server and wait for the server's response. However, that's not the end of it. Although you have stopped sending data to the server, because you have already established an equal connection, the server also has the initiative to send data to you at this time; therefore, the server also needs to stop sending data to you and wait for your confirmation. In essence, it is to ensure the complete execution of a contract between both parties!

Protocols using TCP include: FTP (File Transfer Protocol), Telnet (Remote Login Protocol), SMTP (Simple Mail Transfer Protocol), POP3 (opposite to SMTP, used for receiving emails), HTTP protocol, etc.

8. UDP Protocol

UDP (User Datagram Protocol) is a connectionless communication protocol. UDP data includes destination port number and source port number information. Since communication does not require a connection, it can achieve broadcast transmission.

UDP communication does not require confirmation from the recipient, which is an unreliable transmission and may result in packet loss. In practical applications, programmers are required to verify through programming.

UDP and TCP are at the same layer, but it does not care about the order of packets, errors, or retransmissions. Therefore, UDP is not used for those connection-oriented services that use virtual circuits. UDP is mainly used for those query-response services, such as NFS. Compared to FTP or Telnet, these services require less information exchange.

Each UDP message consists of two parts: the UDP header and the UDP data area. The header consists of four 16-bit long (2-byte) fields, which respectively indicate the source port, destination port, message length, and checksum. The UDP header consists of four fields, each occupying 2 bytes, as follows:

Protocols using UDP include: TFTP (Trivial File Transfer Protocol), SNMP (Simple Network Management Protocol), DNS (Domain Name System), NFS, BOOTP.

Differences between TCP and UDP: TCP is a connection-oriented, reliable byte stream service; UDP is a connectionless, unreliable datagram service.

9. DNS Protocol

DNS stands for Domain Name System, which is used to name computers and network services organized into a domain hierarchy. It can be simply understood as converting URLs into IP addresses. Domain names consist of a series of words or abbreviations separated by dots, and each domain name corresponds to a unique IP address. On the Internet, domain names and IP addresses correspond one-to-one, and DNS is the server that performs domain name resolution. DNS naming is used in TCP/IP networks such as the Internet to look up computers and services through user-friendly names.

10. NAT Protocol

NAT (Network Address Translation) is a Wide Area Network (WAN) access technology that converts private (reserved) addresses into legal IP addresses. It is widely used in various types of Internet access methods and networks. The reason is simple, NAT not only perfectly solves the problem of IP address scarcity but also effectively avoids attacks from the outside network, hiding and protecting the computers inside the network.

11. DHCP Protocol

DHCP (Dynamic Host Configuration Protocol) is a local area network protocol that works using the UDP protocol. It has two main purposes: to automatically assign IP addresses to internal networks or network service providers, and to provide a means for users or internal network administrators to centrally manage all computers.

12. HTTP Protocol

HyperText Transfer Protocol (HTTP) is the most widely used network protocol on the Internet. All WWW files must comply with this standard. What requests does the HTTP protocol include?

GET: Request to read information marked by the URL.

POST: Add information (such as comments) to the server.

PUT: Store a document under the given URL.

DELETE: Delete the resource marked by the given URL.

Differences between POST and GET in HTTP:

1) Get retrieves data from the server, while Post transmits data to the server.

2) Get adds parameter data to the query string in the URL where the submission form's Action attribute points to, with values corresponding to each field in the form, visible in the URL.

3) Get transmits a small amount of data, not exceeding 2KB; Post transmits a larger amount of data, generally not limited by default.

4) According to the HTTP specification, GET is used for information retrieval and should be safe and idempotent.

I. Safe means that the operation is used to retrieve information rather than modify it. In other words, GET requests should generally not have side effects. That is, it only retrieves resource information, just like a database query

❮ Javascript Check Arrayisobject Html Meta Intro ❯