1. The question
1 How does one computer send messages to another computer? The two computers are not connected by any line, how can they send messages to him? There are so many computers in the world, how can we find the computer with that characteristic? Some people say that we can use MAC or IP to uniquely identify people. However, I am a little confused. The world is so big and there are so many computers. Go through all the computers? More than four programs send messages to a computer at the same time. How does the computer accurately send messages to these different programs? 5 What if the sent message is lost?
We answer these questions with the following explanation.
2. The agreement
First, in order for computers to communicate with each other, they must play by the same rules. For example, how to find a target, how to communicate, all of these need a rule. And we call this ruleProtocol. Such a collection of protocols associated with the Internet is called TCP/IP. TCP/IP is the general name of the protocol family in the communication process of IP protocol. An important aspect of the TCP/IP protocol family is layering. Let’s take a look at our network layers and the protocols at each layer.
3. Layer the network
Network layering is the standard seven-tier model known as the OSI seven-tier model. The TCP/IP five-tier model and TCP/IP four-tier model are optimized from the OSI seven-tier model.
Let’s look at a detailed one
Why stratify? There are benefits to having TCP/IP layered. For example, if the Internet was governed by only one protocol, when a design change was needed somewhere, all parts would have to be replaced altogether. After layering, you only need to replace the changing layers. Once the interfaces between the layers are laid out, the internal design of each layer is free to change. It is worth mentioning that the design becomes relatively simple after the layering. Applications at the application level can just think about the tasks assigned to them, without having to figure out where on earth they are, what their transmission routes are, and whether they can ensure delivery.
4. Common physical devices at each layer
Before going into detail on each layer, let’s take a look at the physical equipment of each layer.
5. Detail each layer
We are talking about the OSI seven-layer model, which is often tested in interviews.
5.1 the physical
The physical layer is responsible for utilizationCable, cable, twisted-pair, radio wavesWait till you connect the two computers. Connect the computers. Communication between computers is mainly based on electrical characteristics to send high and low voltage (electrical signals),High voltage corresponds to digit 1, low voltage corresponds to digit 0.
5.2 Data Link Layer
Origin of data link layer: the pure electrical signal 0 and 1 have no significance, so it is necessary to specify how many bits of electrical signal are in a group and what the meaning of each group is.
Functions of data link layer: it defines the grouping mode of electrical signals.
You can send bitstreams but without format it would be a mess, hence “frames”. In order to ensure the accuracy of data communication and realize the effective error control of data, error detection and other functions are added.
1. Ethernet protocol
The Ethernet protocol states that a group of electrical signals form a packet, which we call a packetframe. Each frame consists of two parts: Head and Data.
Frame sizes typically range from 64 to 1518 bytes. If the data to be transmitted is very large, it is divided into multiple frames for transmission. Head contains :(fixed 18 bytes)
- Sender/source address, 6 bytes.
- Receiver/destination address, 6 bytes.
- Data type, 6 bytes.
The bytes in the header part are fixed and fixed to 18 bytes.
Data contains :(minimum 46 bytes, maximum 1500 bytes)
- The content of the packet
Head length +data length = The minimum length is 64 bytes; the maximum length is 1518 bytes. If the head length exceeds the upper limit, fragments are sent
When you send data from one computer to another through the physical layer and the link layer, who sends it to whom, and how to distinguish the computers from each other, you have to give them a unique identification, right? Ethernet provides that devices that access the Internet must have a network adapter. The address of the sending end and receiving end refers to the address of the network adapter, that is, the MAC address.
2. The MAC address
Every computer connected to the network will have a network interface, and each network card will have a unique address, calledThe MAC address. Data transmission between computers is uniquely searched and transmitted by MAC address.The length is 48 bits in base 2, usually represented by a 12-digit hexadecimal number (the first six digits are the manufacturer number and the last six are the line number)
3. The radio:
With a MAC address, two hosts on the same network can communicate with each other. (One host obtains the MAC address of another host through ARP.)
In the same subnet, Computer 1 sends a packet to computer 4 that contains the MAC address of the recipient. When computer A sends the packet through broadcast, computers 2 and 3 in the same subnet will also receive the packet. Then, the computer receiving the packet will extract the MAC address of the packet and compare it with its own MAC address. If the MAC address of the packet is the same, it will accept the packet. Otherwise, the packet is discarded. Computer 4 finds that it contains its MAC address and responds.
5.3 the network layer
The network we live in is made up of countless subnetworks. When broadcasting, only computers in the same subnet can receive it. If there is no subnet this kind of division, then through Ethernet, MAC address, broadcast sending way, the computer in the world can communicate with each other, the problem is that the world wide Internet is composed of a small LAN isolated from each other, so if all communication uses Ethernet broadcast way, Packets sent by one machine would be sent to the whole world, and the entire network would crash.
A way must be found to tell which computers belong to the same broadcast domain and which do not, and if so, broadcast them, and if not, distribute packets to different broadcast domains/subnets via gateways and routes.
So we have our network layer, which deals with the activities of groups in the network, such as group routing. A new protocol was introduced to distinguish between different broadcast domains/subnets, hence the IP protocol.
1. The IP protocol
IP protocol, it defines the address, we call it IP address. There are two versions of the IP protocol, IPv4 and IPv6. Most of us are still using IPv4, and this is a key part of the interview, so let’s focus on IPv6.
This IP address consists of 32-bit binary numbers, which are generally divided into four decimal segments, and the address range is 0.0.0.0 to 255.255.255.255.
The IP address is divided into two parts
- Network: Identifies the subnet
- Host: Identifies a host
The number of bits occupied by the network part and the host part is not fixed. Note: A simple IP address segment only identifies the type of IP address. The subnet of an IP address cannot be identified from the network segment or the host segment.
If the network parts of two computers are identical, they are said to be in the same subnet. For example, at 192.168.33.1 and 192.168.33.2, the network part of these two IP addresses is 24 bits and the host part is 8 bits. So their network part is 192.168.33, so they are in the same subnet. For example, 192.16.10.1 and 192.16.10.2 do not tell you the number of bits of the network part and the host part, so it is not certain that they are in the same subnet. So you have a subnet mask.
The subnet mask is a 32-bit binary number that indicates the characteristics of a subnetwork. The network part of the subnet mask is all 1’s and the host part is all 0’s. The IP address of the above 192.16.10.1, for example, if the network is partly known before 24, after the host part is eight, the subnet mask is 11111111.11111111.11111111.00000000, written in a decimal is 255.255.255.0.
How to determine whether two IP addresses AND subnet masks in a subnet are respectively AND (both digits are 1, the result is 1; otherwise, the result is 0), AND then compare whether the result is the same, if yes, it indicates that they are in the same subnetwork, otherwise it is not.
For example, the subnet masks of 192.168.33.1 and 192.168.33.2 are 255.255.255.0. If you add the IP address to the subnet mask, you can obtain that the subnet mask is 192.168.33.0 and the subnet mask is 192.168.33.0.
2. The ARP protocol
Arp sends packets in broadcast mode to obtain the MAC address of the target host.
With THE IP protocol, we can determine in a subnet, in a subnet we also talked about in the link layer is through the MAC address communication, so now we only have the IP address of the target host, how can we get the MAC address of the target host, this time also introduced ARP protocol.
The sending host sends its own packets through broadcasting. After receiving the packets, all hosts open the packets and return their MAC addresses when they find that the target IP address is their own. The format of the packet is as follows: Packet format: (MAC address of the sender, MAC address of the destination, IP address of the sender, destination IP address, data)
3. The ICMP protocol
This agreement is also frequently tested. Let’s take a look. Why is ICMP needed? A newly built network, often need to carry out a simple test first, to verify whether the network is smooth; But THE IP protocol does not provide reliable transmission. If a packet is lost, the IP protocol does not inform the transport layer whether or why a packet is lost. Hence the ICMP protocol.
ICMP provides the following functions:
- Verify that the IP packet successfully reached the destination address
- Indicates the reason why an IP packet was discarded during sending
Note the following: 1.ICMP works over IP, but it is not a transport layer function, so it is still classified as a network layer protocol. 2. ICMP can be used only with IPv4. If IPv6 is used, ICMPv6 must be used.
Remember our usual ping command? In fact, ICMP is used.
So how do you verify that? (1) The ping command sends an ICMP Echo Request to the peer end. (2) The peer end returns an ICMP Echo Reply. (3) If the peer end does not return an ICMP Echo Reply, it times out and considers that the specified network address does not exist.
4.traceroute
Traceroute is also implemented based on ICMP.
Function:
Prints out how many routers the executable host goes through until it reaches the target host.
Note: Since traceroute is a router command, it should be a tracert command under Windows.
5.4 the transport layer
The function of the network layer is to establish host-to-host communication. The transport layer’s function is to establish port-to-port communication.
Through the mutual help of the physical, data link, and network layers, we have successfully transferred data from Computer 1 to computer 4. However, computer B has various applications in it. How will the computer know to whom the data is destined? Through a Port. For example, we know the 8080.
Added: Ports ranging from 0 to 65535 and 0 to 1023 are used by the system.
In other words, only with IP and port, we can communicate accurately. At this time, some people may say, I entered the IP address did not specify a port ah. In fact, for some transport protocols, there are some default ports. For example, the default HTTP transmission port is 80, which is also included in the packet.
In other words, only with IP and port, we can communicate accurately. At this time, some people may say, I entered the IP address did not specify a port ah. In fact, for some transport protocols, there are some default ports. For example, the default HTTP transmission port is 80, which is also included in the packet.
The two most common protocols at the transport layer are Transmission Control Protocol (TCP) and User Data Protocol (UDP). The biggest difference between TCP and UDP is that TCP provides reliable transmission, while UDP provides unreliable transmission. Look at the connection process mp.weixin.qq.com/s/Pw8v6sZy9 here…
5.5 the session layer
The session layer provides services that enable applications to establish and maintain sessions and synchronize sessions. The computer receives the sent data, but there are so many processes that it sends it to whichever process needs it. For example, if port 80 is needed for intra-system data communication, send data from the receiving port to the required port. In addition, the session layer can make the communication session resume communication from the parity point when the communication fails, that is, to control the information interaction. This ability is extremely important for transferring large files.
5.6 the presentation layer
One of the roles of the presentation layer is to provide a common language for heterogeneous machine communication so that interoperability can occur. The required data is now received correctly, but because the data may be transferred based on security, or algorithmic compression, and the network type is different. There has to be a bridge to sort it out and get back to what it should have been. For example, IBM hosts use EBCDIC encoding, while most PCS use ASCII. In this case, the session layer is needed to complete the transformation. Other functions such as data encryption, data compression.
5.7 the application layer
Finally, the application layer, the application layer is closest to our users. The application layer is the only window that the network can provide application service to the end user. Due to different requirements of users, the application layer contains multiple application entities that support different applications and provide multiple application services, such as email (MHS), file transfer (FTAM), virtual terminal (VT), and Electronic data interchange (EDI). The main protocols are FTP(port 21),SMTP(port 25),DNS, and HTTP (port 80).
Main protocols of the application layer: FTP (File Transfer Protocol), Telnet (Remote Login Protocol), DNS (Domain name Resolution Protocol), SMTP (Mail Transfer Protocol), POP3 (Post office Protocol), HTTP (Hyper Text Transfer Protocol)
1. The DHCP protocol
Dynamic Host Configuration Protocol (DHCP) is a LAN network Protocol that uses UDP. Use two iANa-assigned ports: 67 (server) and 68 (client). DHCP is usually used in a local area network (LAN) environment to centrally manage and assign IP addresses so that clients can dynamically obtain IP addresses, Gateway addresses, and DNS server addresses and improve address usage. To put it simply, DHCP automatically assigns IP addresses to Intranet machines without password login.
It is mainly used for two purposes: (1) for internal network or network service providers to automatically assign IP addresses; (2) to users for Intranet administrators as a means of central management of all computers.
DHCP implements the function of dynamic IP allocation and TDM of IP to solve the problem of IP resource shortage. DHCP allocates IP addresses in the following modes: Automatic Allocation the DHCP server assigns a permanent IP address to a host. The DHCP client can use the IP address permanently after renting it from the DHCP server for the first time. 2) Dynamic Allocation: The DHCP server assigns a time-limited IP address to a host. If the IP address expires or the host explicitly abandons it, the IP address can be used by other hosts. 3) Manual Allocation: The IP address of the DHCP client is specified by the network administrator. The DHCP server only sends the SPECIFIED IP address to the client host. Among the three address allocation methods, only dynamic allocation can reuse addresses that are no longer needed by clients.
2.DNS
The Domain Name System (DNS) is a service of the Internet. As a distributed database that maps domain names and IP addresses to each other, it makes it easier for people to access the Internet.
For example, our visit to www.baidu.com translates to 39.156.69.79
6. Learn the protocol and interview
- 1, HTTP protocol, including: encapsulation format, common response code, the difference between different versions, common request methods, what security risks exist, what is stateless protocol, etc.
- 2, HTTPS protocol: HTTP is plaintext transmission, HTTPS is encryption security, you need to know how HTTPS encryption, how to form a digital certificate, what symmetric encryption, asymmetric encryption.
- 3, TCP protocol: three handshake, four wave, how to ensure reliable transmission, flow control, congestion control.
- 4, UDP: this general understanding can be, it seems that the content is less
- 5. Recommended books for DNS, ICMP, ARP, and DHCP: Computer Networking: Top down, Illustrated HTTP
Reference article:
-
Blog.csdn.net/yaopeng\_20…
-
Blog.csdn.net/baidu\_3796…
-
Mp.weixin.qq.com/s/Y3-CM6EiI…
Please pay attention to the public number “programmer interview way” reply to “interview” to get a complete set of interview package!!
1. Computer network —- Three times handshake four times wave 2. An article that gives you a thorough understanding of the structure of HTTP request and response packets 3. A dream come true —– project self-introduction 4. An article that lets you thoroughly understand the past life of HTTP 5. An article that will get you through HTTP methods and status codes 6. Here’s your design pattern 7. Shock!!! Check out this programmer interview manual!! 9. Nearly 30 interviews shared