Network Basic Plus

1. CS architecture and BS architecture

C / S is: Client and Server, client and server architecture

B / S: Browse and Server, browser and server architecture

Client<===========>Server

客户端软件send             服务端软件recv
操作系统                   操作系统
计算机硬件<====物理介质=====>计算机硬件


Browser<===========>Server

2. Network communication

网络存在的意义就是跨地域数据传输=》称之为通信
网络=物理链接介质+互联网通信协议

3. OSI seven-layer protocol

img

img

五层协议
    应用层
    传输层
    网络层
    数据链路层
    物理层

协议:规定数据的组织格式
    格式:头部+数据部分

    封包裹的过程:数据外加头
    拆包裹的过程:拆掉头获取数据

img

五层协议
计算机1:                            计算机2:

应用层                               应用层
传输层                               传输层
网络层                               网络层
数据链路层                            数据链路层
物理层  <===========交互机===========> 物理层
                                     0101010101010

(源mac地址,目标mac地址)(源ip地址,目标ip地址)数据

3.1 Physical layer

Origin of the physical layer: As mentioned above, if you want to play together with isolated computers, you must connect to the Internet. The implication is that computers must complete networking

img

Physical layer function: mainly send high and low voltage (electrical signal) based on electrical characteristics, high voltage corresponds to number 1, low voltage corresponds to number 0

3.2 Data link layer

The origin of the data link layer: pure electrical signals 0 and 1 have no meaning, you must specify how many bits of the electrical signal, and what each group means

The function of the data link layer: defines the grouping of electrical signals

Ethernet protocol:

In the early days, each company had its own grouping method, and later a unified standard was formed, namely the Ethernet protocol ethernet

ethernet regulations

  • A set of electrical signals form a data packet, called a "frame"
  • Each data frame is divided into two parts: header and data
head data

head contains: (fixed 18 bytes)

  • Sender / source address, 6 bytes
  • Receiver / target address, 6 bytes
  • Data type, 6 bytes

data contains: (minimum 46 bytes, maximum 1500 bytes)

  • The specific content of the data packet

head length + data length = the shortest 64 bytes, the longest 1518 bytes, if it exceeds the maximum limit, send it in fragments

mac address:

The source and destination addresses contained in the head are derived from: ethernet stipulates that all devices connected to the Internet must have a network card, and the addresses of the sending end and the receiving end refer to the address of the network card, that is, the mac address

mac address: Each network card is burned to the world's only mac address when it leaves the factory. The length is 48 digits in binary, usually represented by 12 digits in hexadecimal (the first six digits are the manufacturer's number, the last six digits are the pipeline number)

* Broadcast: *

With the mac address, two hosts in the same network can communicate (one host obtains the mac address of another host through the arp protocol)

Ethernet uses the most primitive way, broadcast to communicate, that is, computer communication basically depends on roar

3.3 Network layer

Origin of the network layer: With ethernet, mac address, and broadcast transmission methods, computers in the world can communicate with each other. The problem is that the world-wide Internet is

It is composed of small local area networks that are isolated from each other. If all communications are broadcast by Ethernet, the packets sent by one machine will be received all over the world.

This is not just a question of inefficiency, it will be a disaster

Using routing (distribution of data packets to different broadcast domains / subnets), the mac address is indistinguishable, it is only related to the manufacturer

Network layer function: introduce a new set of addresses to distinguish different broadcast domains / subnets, this set of addresses is the network address

ARP protocol

The origin of the arp protocol: computer communication basically depends on the roar, that is, the broadcast method. All upper-layer packets must be encapsulated with an Ethernet header at the end, and then sent through the Ethernet protocol. When talking about the Ethernet protocol, we learned

Communication is based on the broadcast method of mac. When the computer sends a packet, it is easy to obtain its own mac. How to obtain the mac of the target host requires the arp protocol

arp protocol function: send packets in broadcast mode to get the mac address of the target host

Protocol working mode: each host IP is known

For example: host 172.16.10.10/24 access 172.16.10.11/24

One: First distinguish the subnet you are in by ip address and subnet mask

Scenes Packet address
Same subnet Target host mac, target host ip
Different subnets Gateway mac, target host ip

Two: Analysis 172.16.10.10/24 and 172.16.10.11/24 are in the same network (if they are not the same network, then the target ip in the table below is 172.16.10.1, the gateway mac is obtained through arp)

Source mac Target mac Source ip Target ip Data section
Sender host Sender mac FF: FF: FF: FF: FF: FF 172.16.10.10/24 172.16.10.11/24 data

Three: This packet will be transmitted in the self-network of the sending end in a broadcast manner. After all hosts receive the packet and unpack it, if the target ip is its own, it will respond and return to its mac.

3.4 Transport layer

The origin of the transport layer: the IP of the network layer helps us to find the molecular network, the mac of the Ethernet layer helps us find the host, and then everyone uses applications, and your computer may open qq, storm video, etc. program,

Then we found a specific host through ip and mac, how to identify the application on this host, the answer is the port, the port is the number associated with the network card of the application.

Transport layer function: establish port-to-port communication

Supplement: Port range 0-65535, 0-1023 is occupied by the system

tcp protocol:

Reliable transmission, TCP data packets have no length limit, in theory can be infinitely long, but in order to ensure the efficiency of the network, usually the length of TCP data packets will not exceed the length of IP data packets to ensure that a single TCP data packet does not need to be divided.

Ethernet header ip header tcp header data

udp protocol:

Unreliable transmission, the "header" part only has a total of 8 bytes, the total length does not exceed 65,535 bytes, just put into an IP data packet.

Ethernet header ip header udp head data

img

3.5 Application layer

The origin of the application layer: users use applications, all work in the application layer, the Internet is developed, everyone can develop their own applications, data is diverse, you must specify the data organization

Application layer function: Specifies the data format of the application.

Example: TCP protocol can transfer data for various programs, such as Email, WWW, FTP, etc. Then, there must be different protocols stipulating the format of emails, web pages, and FTP data, and these application protocols constitute the "application layer".

img

3.6socket

Socket translates into a socket. Socket is an abstraction layer between the application layer and the transport layer. It abstracts the complex operations of the TCP / IP layer into a few simple interface supply layer calls. The implemented processes communicate in the network.

img

4. Network communication

To achieve network communication, each host needs to have four elements

  • IP address of this machine
  • Subnet mask
  • Gateway IP address
  • DNS IP address

There are two ways to get these four elements

1. Static acquisition

Manual configuration

2. Dynamic acquisition

Get via dhcp

Ethernet header ip header udp head dhcp packet

(1) The first "Ethernet header" sets the MAC address of the sender (this machine) and the MAC address of the receiver (DHCP server). The former is the MAC address of the local network card, the latter does not know at this time, fill in a broadcast address: FF-FF-FF-FF-FF-FF.

(2) The "IP header" at the back sets the IP address of the sender and the IP address of the receiver. At this time, the machine does not know about both. Therefore, the IP address of the sender is set to 0.0.0.0, and the IP address of the receiver is set to 255.255.255.255.

(3) The last "UDP header" sets the port of the sender and the port of the receiver. This part is specified by the DHCP protocol. The sender is port 68 and the receiver is port 67.

After the data packet is constructed, it can be sent out. Ethernet is broadcast, and every computer on the same subnet has received this packet. Because the MAC address of the receiver is FF-FF-FF-FF-FF-FF, you ca n’t see who it was sent to, so each computer that receives this packet must also analyze the IP address of this packet to determine whether it is Not for yourself. When the IP address of the sender is 0.0.0.0 and the receiver is 255.255.255.255, the DHCP server knows that "this packet was sent to me", and other computers can discard this packet.

Next, the DHCP server reads the data content of this packet, assigns an IP address, and sends back a "DHCP response" packet. The structure of this response packet is similar. The MAC address of the Ethernet header is the network card address of both parties. The IP address of the IP header is the IP address of the DHCP server (sender) and 255.255.255.255 (receiver). The UDP header The ports are 67 (sender) and 68 (receiver). The IP address assigned to the requester and the specific parameters of this network are included in the Data section.

The newly joined computer receives this response packet, so it knows its IP address, subnet mask, gateway address, DNS server and other parameters

For details, please refer to: https://www.cnblogs.com/linhaifeng/articles/5937962.html#_label13

Guess you like

Origin www.cnblogs.com/chenyoupan/p/12722194.html