[Network] Introduction to Network Basics

LAN and WAN

Independent mode: computers are independent of each other; network interconnection: multiple computers are connected together to complete data sharing

局域网LAN: The number of computers is more, and they are connected together through switches and routers. Compared with the wide area network, the range is smaller. This small range can be specifically a family, school, or company. 私网和内网It usually refers to the same concept, and both refer to local area networks formed within organizations such as enterprises, schools, or families.

广域网WAN: Connect computers thousands of miles away. The so-called "local area network" and "wide area network" are just relative concepts. They can also be regarded as a relatively large local area network. The Internet can be viewed as a wide area network. 公网和外网Usually refer to the same concept, they can be seen as part of the WAN

We may also have heard of concepts such as MAN and campus network. A MAN is actually a computer communication network established within a city, while a campus network corresponds to a computer communication network established within a campus. . Metropolitan area network and campus network are actually relative concepts, and we can all regard them as a large local area network.

How to distinguish between WAN and LAN

In general, whether a network is a WAN or a LAN can be preliminarily distinguished by whether there is a router. In theory, if a network is connected 存在路由器, the network can be connected to other local area networks and the Internet, thus forming a network 广域网. And if it is in a network 没有路由器, it can only communicate with devices in the same local area network, so it can be regarded as局域网 . This distinction may not be entirely accurate. For example, in some large enterprises or schools, multiple routers may be used to separate the networks of different departments or floors. In this case, the entire network can still be considered as one LAN rather than multiple WANs

protocol

protocol concept

“协议”本质就是一种约定, the two sides of the communication have made some kind of agreement, and then they can use this agreement to accomplish something.

Computers have various components: devices such as CPU\graphics card\network card, etc. are connected internally by wires, so the internal nature of a computer is also a small network structure, and there is also an agreement between the internal devices of the computer and the identification. The protocol is not only exclusive to the network, for example, the driver must pass the protocol to access the hardware. And if these lines can be extended very long, and the hard disk is placed far away, then it still belongs to the same computer, but the network cable is stretched, then we are now storing data from writing local programming to remote through the network. Putting the CPU and so on in the distance is equivalent to building the various functions of one computer with multiple computers and connecting them through the network.

So in computer architecture there is network, in network there is architecture

We didn't talk about the protocol when we were learning the system, so why are we discussing it now? This is because multiple hosts are far away. In order to reduce communication costs, a protocol is needed.

所有的网略的问题都是由于传输距离变长了, Having said so long, we are actually talking about why there is an agreement, so how to simply understand what is an agreement:

Understand the agreement :

Due to the need to spend money to make calls, two thoughtful teenagers thought of a way: make a phone call and hang up immediately after the ringing, indicating that it is time to go out to play. We can know what to do with the number of ringtones, reducing costs

By ringing a few times, it represents different meanings. This meaning does not need to be explained. The two parties have already reached a consensus. This is called an agreement, and in computer language it is called an agreement .

If one host wants another host to do something during the calculation, it is stipulated that only one byte will be sent, and different numbers in the byte represent different meanings, thus reducing the cost

Although there is an agreement now, there are many computer manufacturers and different operating systems. They may have their own agreements, so at this time it is necessary to agree on a common standard for everyone to abide by. This is the network protocol ( TCP /IP standard) .

protocol layering

Layering : When making a phone call, from the perspective of people, it is communication between people. From the perspective of communication equipment, it is communication between phones. This is layering. The language layer and the communication device layer are different, use together

Advantages of layering : Modularization of software can be carried out very well 解耦. After decoupling, if we replace the communication equipment, the upper layer does not need to be changed, and if the upper layer language changes, the lower layer does not need to be changed. So any modification to any layer does not affect other layers

Basis for layering : The functions are relatively concentrated, and modules with a relatively high degree of coupling are placed on one layer, that is, high cohesion. Each layer solves specific problems and functions are decoupled.

Data Transfer Conditions

Packet delivery capability : If data is to be transmitted between two distant hosts, the ability to deliver the data to another host must first be provided.
Path selection capability : There are thousands of hosts, if you don’t know where to Not even one.
Error tolerance and error correction ability : If an error occurs, a copy must be retransmitted.
Data parsing ability : The data is passed to the host to identify what it is, and then the data can be used.

And each layer here has its own protocol, and each layer protocol solves the problems of the current layer.

OSI seven-layer model (understand)

hierarchical name Function Overview of the functions of each layer
application layer Protocols for Featured Applications Protocols for each application
presentation layer Conversion between the inherent data format and the network standard data format Receive files in different forms, such as text streams, images, sounds, etc.
session layer communication management. Responsible for establishing and disconnecting communication connections. Manage layers below the transport layer When to establish a connection, when it is appropriate to disconnect and how long to maintain the connection
transport layer Manage data transmission between two nodes responsible for reliable transmission (ensure that data is reliably delivered to the destination address) Is there any data loss
Network layer Address Management and Routing Which route is passed to the destination address
data link layer Transfer and identify data frames between interconnected devices Conversion between data frame and bit stream
physical layer Use '0' and '1' to represent high and low voltage Conversion of bit streams and electronic signals, specifications of connectors and network cables

However, the OSI seven-layer model is complex and impractical, so it was adjusted during the actual implementation, so there is the TCP/IP four-layer protocol we see now ( except for the physical layer ).

image-20230504000037357

TCP/IP five-layer (four-layer) model

TCP/IP is a synonym for a set of protocols, and it also includes many protocols, forming the TCP/IP protocol cluster. The TCP/IP communication
protocol adopts a 5-layer hierarchical structure, and each layer calls its next Network to meet their own needs.
Physical layer : Responsible for the transmission of optical/electrical signals. For example, the network cable (twisted pair) commonly used in Ethernet now, the coaxial cable used in early Ethernet (mainly used in cable TV now), Optical fiber, the use of electromagnetic waves in the current wifi wireless network, etc. all belong to the concept of the physical layer. The capability of the physical layer determines the maximum transmission rate, transmission distance, anti-interference, etc. The hub (Hub) works at the physical layer.
Data link layer : responsible for the transmission and identification of data frames between devices. For example, the driver of the network card device, Frame synchronization (that is, what signal is detected from the network line is counted as the start of a new frame), collision detection (automatic retransmission if a collision is detected), data error checking, etc. There are Ethernet, token ring, wireless Standards such as LAN. The switch (Switch) works at the data link layer.
Network layer : responsible for address management and routing selection. The line (routing) for data transmission between hosts. Router (Router) works at the network layer.
Transport layer : responsible for data transmission between two hosts. Such as Transmission Control Protocol (TCP), which can ensure reliable data transfer from the source The host sends to the target host.
Application layer : Responsible for communication between applications, such as simple email transfer (SMTP), file transfer protocol (FTP), network remote access protocol (Telnet), etc. Our network programming is mainly for the application layer

Notice:

We think less about the physical layer. Therefore, it can also be called the TCP/IP four-layer model in many cases.

The data link layer solves the problem of transmission, the network layer solves the problem of path selection, the transport layer solves the problem of error correction, and the application layer solves the problem of data analysis.

Here the network card layer in the data link layer is part of the driver. The network layer and transport layer are implemented by the operating system itself. All operating systems are the same, so hosts around the world can be interconnected.

Here TCP and IP are the two most representative protocols of the transport layer and the network layer. This protocol stack is named the TCP/IP model, which is enough to see the importance of these two protocols. Their importance is endowed by the operating system. .

Computer layered architecture diagram:

img

In network communication, there will be a system call interface at the time of the application layer and transport layer, mainly the system call interface of the file class.

Basic process of network transmission

masthead

Each layer of the protocol has it, and the final performance of each protocol is that the protocol must have报头

For example: when we receive the package, we will not only receive the items, but also express boxes and express orders. This extra courier is called header . If we want to send data, the data sent may be a little more than we want, and the extra part is the header

image-20230504084444172

The express order number is for the courier to see. This express order is an agreement set by the express company itself . This express order can be identified in their logistics system.

From this, it can be concluded that the protocol is usually expressed through the protocol header. Each piece of data must have its own header when it is finally sent or in different protocol layers.

Principles of LAN Communication

两台局域网的主机是能够直接通信的

Each host has a network card, and each network card has its own address, called a MAC address , just like our ID card, which identifies the network card唯一性

Although the MAC address is unique in the world, it should not be used globally, but only to identify its own uniqueness in the local area network.

instruction:ifconfig

image-20230504121742701

Note: The MAC address of the cloud server here is a virtual address.

LAN communication principle:

There are many machines in the LAN:

image-20230504122346190

If MAC1 wants to send a message to MAC7, all other hosts can also receive it, but other hosts make internal protocol judgments and find that they are not sent to themselves, so they will be discarded automatically. In the end only MAC7 received it.

Ethernet (understand)

Ethernet and Token Ring are different communication standards

Ethernet (Ethernet) is a computer local area network technology. Its communication method: everyone can receive the message sent, but when MAC1 wants to send the message to MAC7, MAC3 wants to send the message to MAC5, but they cannot send the message at the same time (data overwrite). The principle of Ethernet sending messages is to allow only one host to send messages in the LAN at any one time. Otherwise, a collision will occur , and if a collision occurs, the message will be invalidated and resent. How to treat the network resources in the LAN: Looking at the network resources from the perspective of the system is a critical resource .

The solution of the token ring network is that whoever holds the token ring sends data . A host without a token cannot send messages. similar to locks in the system

Network transmission flow chart

  • Two hosts in the same network segment perform file transfer

image-20230504230407623

  • File transfer between hosts across network segments. Data travels from one computer to another through one or more routers

image-20230505000230583

Packet Encapsulation and Demultiplexing

Different protocol layers have different names for data packets, which are called segments at the transport layer, datagrams at the network layer, and frames at the link layer. Application layer data is sent to the network through the protocol
stack When uploading, each layer of protocol must add a data header (header), which is called encapsulation

If they use qq to chat, they think that they are chatting directly at the user layer, but in fact, the chat is realized only after the data is delivered downward (encapsulation) and unpacked upward (divided).

**Packet encapsulation: **When delivering downward, each layer will add its own header, 报文=报头+有效载荷, and then deliver the packet downward

Data packet sharing: When unpacking upward, because the same layer has the same protocol, it can recognize the header, it will unpack the header, and unpack the payload upward. This creates a symmetrical structure

The process behaves like a graph (traces are preserved):

image-20230504233637287

It can be seen that the header and payload of the same layer are exactly the same, how the left side is sent and the right side is received, so it can be considered as direct communication in the same layer protocol; it can also be understood as downward delivery.

The communication process between two computers on different network segments is different in the router part:

image-20230504234616176

A device must span at least two networks in order to forward datagrams across the network. A router must span at least two networks, and the router must have two network interfaces. When the router part is passed to the token ring driver, the added header is the token ring protocol (re-encapsulating the header), which is different from the left, but it does not affect the symmetry.

Simply understand the part of the router that transmits data: like we took off our coats and changed them to new ones, but the person has not changed. It can be concluded that the role of the IP layer is to shield the differences in the underlying network .
Different protocol layers have different names for data packets, which are called data segments at the transport layer, datagrams at the network layer, and data frames at the link layer. When the application layer data is sent to the network through the protocol stack, each layer protocol must add a data header (header), which is called encapsulation .

6. IP and MAC address

There are two versions of the IP protocol, IPv4 and IPv6. When referring to the IP protocol, if there is no special description, the default refers to IPv4

image-20230505073132613

  • IP address

The above representation with 4 stanzas is called IPv4. IPv6 is represented by 16 bytes

The IP address is used to identify the addresses of different hosts in the network in the IP protocol;
for IPv4, the IP address is a 4-byte, 32-bit integer;
we usually use 点分十进制the string of " " to represent the IP address, for example 192.168.0.1 ; Each number separated by dots represents a byte, the range is 0 - 255

MAC addresses are usually used in LANs, and IP addresses are usually used in WANs

  • MAC address

The MAC address is used to identify the connected nodes in the data link layer;
the length is 48 bits and 6 bytes. It is generally expressed in the form of hexadecimal numbers plus colons (for example: 08:00:27:03:fb :19)
It is determined when the network card leaves the factory and cannot be modified. The mac address is usually unique (the mac address in the virtual machine is not the real mac address, and may conflict; some network cards also support user configuration of the mac address)

Both of these can represent addresses, why are there two addresses :

In Journey to the West, we often hear a saying that every time a Tang monk passes through a country, he will tell the leader: The poor monk came from the Tang Dynasty in the east, and went to the west to worship Buddha and learn scriptures. And the leader will ask him where he came from the last stop, and then tell him where to go to the next stop: for example: the last stop was the daughter country, and the next stop should be Heifengling

Here, Dongtu Datang and Xitian are IP addresses , which will not change from beginning to end.
The daughter country and Heifengling are the MAC addresses , which keep changing. IP address and MAC address are equivalent to the relationship between the ultimate goal and the stage goal

The IP address provides the direction; the MAC address provides the feasible path . The two MAC addresses here must be next to each other, so they are in the same LAN

Guess you like

Origin blog.csdn.net/weixin_60478154/article/details/130498661