当前位置:网站首页>Fundamentals of network communication (LAN, Wan, IP address, port number, protocol, encapsulation and distribution)
Fundamentals of network communication (LAN, Wan, IP address, port number, protocol, encapsulation and distribution)
2022-04-23 20:09:00 【Xiao Zhang to learn】
Catalog
Independent mode : Computers are independent of each other .
With the development of the times , There is an increasing need for computers to communicate with each other , Sharing software and data , That is, multiple computers work together to complete the business , There is network interconnection .
Network interconnection : Connect multiple computers together , Complete data sharing .
The essence of data sharing is Network data transmission , That is, computers transmit data through the network , Also known as Network communication .
Depending on the size of the network interconnection , Can be divided into LAN and WAN .
One 、 LAN and WAN
1.1 LAN LAN
LAN , namely Local Area Network
, abbreviation LAN
.
Local
That is, it identifies that the LAN is local , A locally formed private network
The hosts in the LAN can easily communicate with each other , Also known as Intranet ; There is no connection between LAN and LAN , It's impossible to communicate .
There are many ways to build a network through a LAN : Through the router / These switches are called local area networks .
-
Direct connection based on network cable
Connect the three main engines with two wires , These three hosts constitute a LAN . -
Based on switch
The network ports on the switch are peer-to-peer .( They all have the same mouth ) The effect is to set up a LAN with the devices plugged into it . This Hosts inside the LAN can access each other , Switch is to build several devices into a LAN . -
Router based construction
There are actually two types of ports in the router :WAN Mouth and LAN mouth .
Which is inserted inLAN
Equipment on the mouth , In a LAN .
adoptWAN
The port is connected to another lan ;
The router is connected to two LANs (LAN The mouth is a ,WAN Another one ).
1.2 Wide area network
Wide area network , namely Wide Area Network
, abbreviation WAN
.
Through the router , Connecting multiple LANs , Physically form a wide range of networks , A wide area network is formed . All LANs within the WAN belong to their subnets .
Wan is actually between LAN and WAN , There are no clear boundaries . Think of a larger lan , It can be called " Wide area network "
The world's largest wan , be called Internet
( The Internet ).
Two 、 Network communication foundation
The purpose of network interconnection is Network communication , That is, network data transmission , A little bit more specific , It is between different processes in the network host , Data transmission based on network .
that , In the formed network , How to determine from which host , Transfer data to that host ? That's what you need to use IP Address to identify .
2.1 IP Address
IР Address : Describes the location of a host on the network ( Locate a network location of the host ).( It's equivalent to the receiving address when buying express )
Format :
IP The address is a 32 The binary number of bits , This is not convenient for people to read and remember , It is usually divided into 4 individual “8 Bit binary number ”( That is to say 4 Bytes ), Such as :01100100.00000100.00000101.00000110.
Usually use “ dotted decimal ” In the way of , namely a.b.c.d In the form of (a,b,c,d All are 0~255 A decimal integer between ). Such as :100.4.5.6.
special IP:
127.* Of IP The address is used for local loopback (loop back) test , Usually 127.0.0.1
( Loopback IP , Represent your own host ).
2.2 Port number
Port number : Describes an application on a host .( Equivalent to the recipient's phone number )
Format :
The port number is essentially a 2 Bytes (16 position ) Of unsigned integers (0~65535 Number of ranges ), In network communication , The process can bind a port number , To send and receive network data .
Two different processes , Cannot bind the same port number , But a process can bind multiple port numbers .
3306 mysql
Default port number .
When the server program starts , You need to bind a port number , So that the client program can access .
Well known port number : hold 0-1024
These port numbers , It has been divided into some specific functions .
Many network services are very commonly used , A very wide range of services , For better management, assign some special port numbers to these services , It's not mandatory , It's just advice .
such as :
80: http The server
443 :https The server
22: ssh
23: ftp
If you deploy yourself http The server , You can bind him to 80, It can also be bound to other ports . image java Well known in http The server tomcat, The default port used is not 80 It is 8080.
2.3 agreement
agreement , Short for network protocol , Network protocol is network communication ( Network data transmission ) A set of conventions that all network devices passing through must follow together 、 The rules . How to establish a connection 、 How to identify each other, etc . Only by following this Agreement , Computers can communicate with each other .
agreement (protocol) Finally, it is reflected in the format of data packets transmitted on the network .
Why an agreement is needed ?
When it comes to network communication , In essence, it transmits optical and electrical signals ; Through the frequency of the optical signal ( High frequency / Low frequency ) The level of the electrical signal ( High level / Low level ) To express 0 and 1. To deliver all kinds of different messages , We need to agree on the data format of both parties .
2.4 Protocol layer
The process of network communication is actually very complicated , There are a lot of details . If only one agreement is passed , To agree on all the details , This agreement will be huge , complex ; A better way is to put a large and complex agreement , Split into several small , A simpler agreement , Each agreement , Responsible for part of the work .
Protocol layering is similar to when making a phone call , Define different levels of protocols :
Our agreement has only two layers ; But the actual network communication will be more complex , It needs to be divided into more levels .
The benefits of layering :
benefits 1: Each layer protocol does not need to understand the details of other layer protocols .( Better packaging )
Caller , You don't need to understand how the phone works , Can complete the operation of making a phone, the person who makes a phone , You don't need to be a language master .
benefits 2: Replace the protocol of the corresponding layer with another protocol .( Better decoupling )
Caller , You don't have to use a wired phone , You can use a wireless phone .
Caller , You can also use English , Do not use Chinese 》
OSI Seven layer network model
OSI: namely Open System Interconnection
, Open Systems Interconnection .
- OSI The seven layer network model is a logical definition and specification : Logically divide the network into 7 layer .
- OSI The seven layer model is a framework design method , Its main function is to help different types of hosts to achieve data transmission ;
- Its greatest advantage is Service 、 The three concepts of interface and protocol are clearly distinguished , The concept is clear , The theory is also relatively complete . Through seven hierarchical structure models, the reliable communication between different systems and different networks can be realized .
OSI The seven layer model is both complex and impractical : therefore OSI The seven story model didn't land 、 Realization .
When actually building a network , Just to OSI Partial layering in seven layer model design , That is, the following TCP/IP Five floors ( Or four floors ) Model to achieve .
TCP/IP Five floors ( Or four floors ) Model
TCP/IP Is a synonym for a group of agreements , It also includes many agreements , Make up the TCP/IP Protocol cluster .
TCP/IP The communication protocol uses 5 The hierarchy of layers , Each layer calls the network provided by its next layer to fulfill its own needs .
The following four layers of code logic are implemented by the operating system, driver and hardware .
From a global perspective , Think it's 5 layer , But the bottom physical layer describes the hardware device ,( It has nothing to do with software , Far away from the procedural ape ), At this time, it is considered to be the fourth floor .
The physical layer : Hardware equipment in network communication ( Ethernet cable / network card …), Conventions for hardware devices , This is the scope of the physical layer protocol , It is necessary to ensure the communication between all hosts and network devices , They all match each other .
The physical layer is responsible for light / How electrical signals are transmitted . For example, the current Ethernet network cable ( Twisted pair Line )、 The coaxial cable used in early Ethernet ( Now it's mainly used in cable TV )、 Optical fiber , current wifi The use of electromagnetic waves in wireless networks belongs to the concept of physical layer . The capacity of the physical layer determines the maximum transmission rate 、 transmission distance 、 Anti interference, etc . A hub (Hub) Working on the physical level .
Data link layer : Be responsible for the completion of adjacent ( A network cable is connected ) Communication between two devices .[ Local ]
Responsible for the transmission and identification of data frames between devices . For example, drivers of network card devices 、 Frame synchronization ( That is to say, what signal is detected from the network cable is counted as the beginning of a new frame )、 Collision detection ( Automatically resend if a conflict is detected )、 Data error checking, etc . There's Ethernet 、 Token ring network , wireless LAN Equal standard . Switch (Switch) Working at the data link layer
The network layer : be responsible for Point to point communication .[ overall situation ]
Any node in the network , Communication to any node ( Not necessarily adjacent , More refers to non adjacent ), The network layer is responsible for between these two points , Plan a suitable route .( The actual network environment structure is very complex . There is more than one route between two points . We need the most appropriate one from the planning office ).
Transport layer : be responsible for End to end communication .
Start and end , Just focus on the results ( Whether the data arrives or not ), Don't focus on the process ( Don't care which way the data goes )
For example, when buying express, you need to fill in your recipient's address and recipient's name . The merchant should send the express to me according to this address , Me and the merchant , All focus on the results , Don't focus on the process , Express companies should pay attention to the process in the middle .
application layer : Closely related to applications .( The data you transmitted , What is it for , Different applications have different uses )
For example, one day I bought a bed brush online :
merchants , Standing on the transport layer : Consider whether this thing can be sent to me .
Courier Services Company : Plan the route at the network layer .
Express little elder brother : Stand on the data link layer , Ride an electric car to pull the goods to the distribution center .
Electric cars / Container trucks / The highway station is on the physical layer : Provide the basis for transmission .
The above four steps are only considering how the package is transported , Regardless of what's in this package , I don't care what the things in the package are for . And I'm : Stand on the application floor as the person who buys a bed brush , Is to hold a certain purpose / Purpose to buy .
The layer where the network device is located
For one station host , Its operating system kernel implements content from transport layer to physical layer , That is to say TCP/IP The lower four layers of the five layer model ;
For one station Router , It has achieved From the network layer to the physical layer , That is to say TCP/IP The lower three layers of the five layer model ;
For one station Switch , It has achieved From data link layer to physical layer , That is to say TCP/IP The lower two layers of the five layer model ;
Notice that we're talking about Switches and routers in the traditional sense , Also known as layer 2 switch ( Working in TCP/IP The lower two layers of the five layer model )、 Three layer router ( Working in TCP/IP The lower three layers of the five layer model ).
3、 ... and 、 Packaging and distribution
- Different protocol layers have different names for packets , stay The transport layer is called segment (segment), In the network layer, it's called datagram (datagram), stay The link layer is called frame (frame).
- When the application layer data is sent to the network through the protocol stack , A data header should be added to each layer of the protocol (header), be called encapsulation (Encapsulation).
- Header information It contains something similar to how long the first part is , load (payload) How long is , What is the upper layer protocol .
- Data is packaged into frames and sent to the transmission medium , After reaching the destination host, the corresponding header of each layer protocol is stripped , According to the first part of “ Upper layer protocol field ” The data is handed over to the corresponding upper layer protocol for processing .
3.1 encapsulation
for example , Use QQ Send a message to a classmate , user A On the keyboard , Entered a "hello", Press the send key .
application layer (QQ Applications )
According to the user's input ,QQ According to the application layer protocol designed by the program ape , Construct the data into an application layer protocol message ( agreement : It's a convention , message : A set of data that complies with this Agreement ). notes :QQ Application layer protocol used , It's development QQ The programmer set it himself , Suppose that the current application layer protocol format is :
The application layer protocol calls the... Provided by the operating system API( be called socket API), Put the data of the application layer , To the transport layer ( Has entered the operating system kernel ).
Transport layer ( Operating system kernel )
According to the data just transmitted , Based on the currently used transport layer protocol , To construct a transport layer protocol message . The most typical protocol of transport layer is UDP,TCP. With TCP For example :
TCP Datagram =TCP Headlines + Data load (Payload, That is, a complete application layer data ).
TCP There is a lot of information in the header of , The most important , Namely **“ Source port " and “ Destination port ”**, Similar to sender's phone and recipient's phone .
You can simply put this structure TCP The process of message is regarded as a string splicing ( What we spell here is binary data ). Next, the datagram of this transport layer , To the network layer .
The network layer ( Operating system kernel )
Got the complete transport layer datagram , According to the current network layer protocol ( for example IP), Package again , hold TCP Datagram structure causes IР The datagram , Here is the last protocol header :
IP The datagram =IР Protocol header + load ( complete TCP/UDP Datagram )
There is also a lot of important information in this header , One of the most important is Source IP And purpose IP, Similar to the sender's address , And the recipient's address . Then , Current network layer protocols , It will IP The datagram , To the data link layer .
Data link layer ( The driver )
In just now IP Based on datagram , According to the protocol of the data link layer currently used , Give the datagram constructed as a data link layer . Typical data link layer protocols , be called “ Ethernet ”, It will be constructed into a " Ethernet data frame ":
Ethernet data frame = Frame head +IP The datagram + Frame tail
The most important information is stored in the frame header : What is the address of the device to be sent next ;
The end of the frame is responsible for checking the sum .
IP The address written in the agreement , Is the beginning and end .( Xi'an to angung town )
Ethernet data frame , The address written in the frame header , Is the address of the next adjacent node .( Xi'an and Changchun )
As the data is forwarded to the next device , The address in the frame header , It's always changing .
People in Xi'an , the address for this place , It says Xi'an / changchun ;
People in Changchun , the address for this place , It's about Changchun / Baicheng ;
People in Baicheng , the address for this place , It says Baicheng / An Guang town ;
Data link layer , The above data will be handed over to a physical layer .
The physical layer ( Hardware device )
The work done by the physical layer , According to the Ethernet data frame just now ( In fact, it's a group 0 1) Take this 0 1 Become high and low level , Through the network cable . Or take the 0 1 Become high frequency / Low frequency electromagnetic waves , Through optical fiber / Spread out wirelessly .
Here we are , At this point, the data has left the current host , To the next device .
Next device , It could be a router / Switch / Other equipment .
3.2 Divide up
Distribution is the reverse process of packaging :
encapsulation It's from the top down , The data is added to the protocol header in turn ( Package express );
Divide up It's from the bottom up ,, The data is removed from the protocol header at one time ( Demolition Express );
The physical layer ( Hardware device , network card )
host B Your network card senses a set of high and low levels , Will translate these levels into 0 1 A string of data , Then this string 0 1 Is a complete Ethernet data frame . The physical layer gives this data to the data link layer .
Data link layer ( drive )
The data link layer is responsible for parsing this data , Remove the head and tail of the frame , Take out the inside IP The datagram , Then give it to the network layer protocol .
The network layer ( Operating system kernel )
Network layer protocol (IP agreement ) This data will be analyzed again , Get rid of IP Protocol header , Take out the inside TCP The datagram is then handed over to the transport layer ;
Transport layer ( Operating system kernel )
Transport layer protocol (TCP agreement ) This data will be analyzed again , Get rid of TCP Headlines , Take out the inside TCP The datagram , Give it to the application layer .
application layer ( Applications QQ)
The application layer will call socket API
Read the application layer datagram from the kernel , Then it is parsed according to the application layer protocol , Display in the window according to the analysis results .
The above discussion is only about the starting point and the ending point .A and B There are many routers and switches in the middle ?
No matter how complex the network is , The overall transmission process here is similar . It's just Keep repeating the process of packaging and distribution .
版权声明
本文为[Xiao Zhang to learn]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204232005319057.html
边栏推荐
- TI DSP的 FFT与IFFT库函数的使用测试
- Inject Autowired fields into ordinary beans
- Kubernetes getting started to proficient - install openelb on kubernetes
- LPC1768 关于延时Delay时间与不同等级的优化对比
- 如何在BNB鏈上創建BEP-20通證
- NC basic usage 1
- AQS learning
- selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ executable needs to be in PAT
- antd dropdown + modal + textarea导致的textarea光标不可被键盘控制问题
- 【2022】将3D目标检测看作序列预测-Point2Seq: Detecting 3D Objects as Sequences
猜你喜欢
STM32基础知识
Kubernetes入门到精通-裸机LoadBalence 80 443 端口暴露注意事项
FFT物理意义: 1024点FFT就是1024个实数,实际进入fft的输入是1024个复数(虚部为0),输出也是1024个复数,有效的数据是前512个复数
Openharmony open source developer growth plan, looking for new open source forces that change the world!
Redis cache penetration, cache breakdown, cache avalanche
Building googlenet neural network based on pytorch for flower recognition
Command - sudo
CVPR 2022 | QueryDet:使用级联稀疏query加速高分辨率下的小目标检测
PHP reference manual string (7.2000 words)
C6748 software simulation and hardware test - with detailed FFT hardware measurement time
随机推荐
MFC obtains local IP (used more in network communication)
The textarea cursor cannot be controlled by the keyboard due to antd dropdown + modal + textarea
Esp8266 - beginner level Chapter 1
Kubernetes introduction to mastery - ktconnect (full name: kubernetes toolkit connect) is a small tool based on kubernetes environment to improve the efficiency of local test joint debugging.
Five minutes to show you what JWT is
Devops integration - environment variables and building tools of Jenkins service
VeraCrypt文件硬盘加密使用教程
MySQL数据库 - 单表查询(二)
nc基础用法2
MySQL数据库 - 连接查询
【数值预测案例】(3) LSTM 时间序列电量预测,附Tensorflow完整代码
Inject Autowired fields into ordinary beans
TI DSP的 FFT与IFFT库函数的使用测试
antd dropdown + modal + textarea导致的textarea光标不可被键盘控制问题
How about Bohai futures. Is it safe to open futures accounts?
Speex Wiener filter and rewriting of hypergeometric distribution
[2022] regard 3D target detection as sequence prediction - point2seq: detecting 3D objects as sequences
NC basic usage 3
aqs的学习
nc基础用法1