Writing in the front
On June 20, 2018, I got my graduation certificate and officially ended my student life.
On July 2, 2018, I started my first official job as Android development engineer of Renrenche.
On July 13, 2018, I decided to urge myself to learn, so I plan to start the road of the public account again. Force oneself planned to learn, planned to output. Because recently happened to catch up with the explosion of demand, so this period of study plan, do not need a lot of time to invest in the basic computer knowledge, focusing on the training of their own internal skills. I bought a computer network course some time ago, so I plan to record this knowledge recently.
Note the body
Here is a series of articles about computer networks, mainly my own study record of a paid course. There is no course link here. If you are interested in the course, you can chat with me in the background. The following content and pictures are collected by me from the paid content of Geek Time. If there is any infringement, please inform me and delete them immediately.
The following is from the free public section of this course. Paid content, if the viewer is interested, you can buy it and view it)
HTTP protocol correlation
When we type https://www.kaola.com into a browser, it’s a URL. The browser only knows the name of the link is https://www.kaola.com, but it doesn’t know anything else useful, so the next step is to open the address book and look up the IP address behind the link. The common address book protocol is DNS, and a more accurate address book lookup protocol, HTTPDNS, can also be used. Whichever way you look it up, you’ll end up with this address: 106.114.138.24. This is the SERVER IP address of Netease Kaola, which is the “house number” of the Internet world. Knowing the destination address, the browser begins to package its request. The HTTPS protocol is now commonly used. Of course, whatever the agreement is, it will specify the information you need to carry for the request, such as “what to buy and how much to buy”.
TCP protocol related
The layer where DNS, HTTP, and HTTPS reside is called the application layer. After application layer encapsulation, the browser will be the application layer package to the next layer to complete, through socket programming to achieve. The next layer is the transport layer. There are two protocols at the transport layer: connectionless protocol UDP and connection-oriented protocol TCP. For payments, TCP is often used. Connection-oriented means that TCP guarantees that the packet will reach its destination. If it does not arrive, it resends until it arrives. TCP has two ports, one for the browser to listen to, and one for the e-commerce server to listen to. The operating system often uses ports to determine which process it should give the package to.
Obtaining an IP Address
Once the transport layer is wrapped, the browser passes the package to the operating system’s network layer. The protocol at the network layer is IP. In IP protocol, there will be the active IP address, that is, the IP address of the browser machine and the target IP address, that is, the IP address of the e-commerce site server. (That is, the IP address we obtained through DNS protocol above)
Obtaining a MAC Address
Now that the operating system knows the destination IP address, it starts to figure out how to find the target machine based on the number. The operating system will often determine whether the destination IP address is local or out-of-town. If it’s a local, you can tell by the number, but obviously the e-commerce site is not local, but far away. The operating system obviously knows that the request is going to go far away from the local place, even if it doesn’t know where the far place is. If you don’t know where the distance is, what does the operating system do with it?
Here we can use the analogy: if you want to go to the customs, then the request packet to go to the gateway.
When the operating system is started, the DHCP protocol is used to configure the IP address and the default gateway IP address 192.168.1.1. How does the operating system send the IP address to the gateway? In the local communication basic rely on roar, so the operating system loud roar, who is 192.168.1.1 ah? At this point, the gateway will answer, I am, my local address is at the east end of the village. The local address is a MAC address, and the yell is ARP.
routing
The operating system then passes the IP packet to the next layer, the MAC layer. The nic then sends the packet. Because the packet contains a MAC address, it can reach the gateway. After receiving the packet, the gateway determines the next step based on its own knowledge. A gateway is usually a router, and the route to an IP address is called a routing table. The router is a bit like a city pass in one of the countries xuanzang crossed on his westward journey. Each city gate is connected to two countries. Each country is like a local area network (LAN). Within each country, you can use the local address MAC for communication. Once you cross the city gate, you need to bring out the IP header, which says that the poor monk is from the Eastern Tang dynasty (the source IP address) and wants to go to the west to pray for buddhist scriptures (the target IP address). Pass by treasure land, stay overnight, leave tomorrow, how should I go next?
Chengguan is often aware of these “knowledge”, because chengguan and neighboring chengguan will often communicate. This communication protocol is called routing protocol, OSPF and BGP are commonly used.
Request and response
Each gate is a country. When the network packet knows which gate to go to next, it still needs to use the MAC address of the internal country to find the next gate through the MAC address of the next gate, and then asks the way to the next gate until it exits the last gate. Finally – a gateway knows where the network packet is going. So, shout out to the country, who is the target IP? The target server responds with a MAC address. After the network packet is cleared, the target server can be found through this MAC address. The target server finds a MAC address match, removes the MAC header and sends it to the network layer of the operating system. When the IP addresses match, remove the IP header. The IP header contains a layer that encapsulates THE TCP protocol and then passes it to the transport layer, the TCP layer. In this layer, for each packet received, there is a reply indicating that the packet was received. This reply packet is not the result of the order request, such as whether the purchase was successful, how much money was deducted, etc., but only a description of the TCP layer, that is, the reply after receiving. Of course, this reply will walk back along the direction just come, to report peace. Because once out of the country, the westward road is extremely difficult and dangerous, if in this process, the network packet is lost, for example, into the desert, or be robbed and killed by robbers how to do? So to report a peace. If the packet does not arrive after a period of time, the sending TCP layer will re-send the packet, the same process as above, until a safe reply is received one day. This retry is not a re-request of the action that your browser will order again. In the case of the browser, an order is sent and the TCP layer retries itself. Unless something goes wrong with TCP, such as a broken connection, the browser’s application layer resends the order request. After the network packet reaches the TCP layer safely, there is a target port number in the TCP header. By this port number, it can be found that the process of the e-commerce site is listening to this port number, assuming a Tomcat, and sends the packet to the e-commerce site.
The final destination
The e-commerce site process gets the content of the HTTP request and knows what to buy and how much to buy. Often the Tomcat that an e-commerce site initially receives a request is only a receptionist who handles the request as a whole, rather than doing everything himself. For example, the receptionist would tell the special order management process, register to buy an item, how much to buy, tell the inventory management process, how much to reduce the base, tell the payment process, how much to pay, and so on. How do you tell the relevant processes? This is usually done through RPC calls, or remote procedure calls. A remote procedure call is when the administrative order process is told, the receptionist does not have to worry about the intermediate network interconnection issues, which are handled by the RPC framework. There are many kinds of RPC frameworks, some are based on HTTP protocol in HTTP packets, some are directly encapsulated in TCP packets. When the receptionist finds that the appropriate department has finished processing, she replies with an HTTPS package to say that the order has been successfully placed. The HTTPS package, as it arrived, will make its way to your PC, and eventually to the browser, indicating that the payment was successful.
Notes summary
Why do you have a MAC address when you have an IP address
-
1. IP addresses are dynamically assigned in the LAN. If I am 192.168.2.100, if I am offline, the IP may be assigned to another computer. IP and device do not always correspond, which creates problems for communication, but MAC addresses are different. MAC addresses and devices are one-to-one and globally unique. So there is no problem with LAN using MAC address for communication.
-
2. Historical legacy: In the early Ethernet, there were only switches, but no routers. Ethernet communication was carried out through MAC addresses. Then came the Internet. In order to be compatible with the original mode, IP+MAC address communication was adopted. Why don’t we just start over? Just look at the situation with IPv6. Therefore, the MAC address was first followed by the IP address, and the IP address was mainly put forward because of the defects of the MAC address itself. It is also interesting to change this question into why IP address is needed when there is a MAC.
-
3. The defect of MAC address itself: because THE MAC address is written in the network card by the hardware provider, although the MAC address is unique, it cannot indicate the user’s position in the entire Internet, unless maintaining a super large MAC address corresponding table, then the addressing efficiency will surely explode. But IP addresses solve this problem, because the IP address is given to you by the isp, so the entire network knows where you are.
Nic MAC codes are assigned by a unique organization in the world. Unauthorized manufacturers have no right to produce nics. Each nic has a fixed card number, and the card number is directly marked on any standard nic. It is usually a group of 12 hexadecimal numbers. The first six digits represent the nic manufacturer. The following digit is the device number.
The end of the
This is a note from my study of Computer Network these days. Most of it was based on previous summaries, which I wrote down again. It is a confirmation to oneself study result, hope can see some help to each officer.
I am an Android developer, and maintain a public account together with a bunch of kids from all walks of life on the Internet: IT Interview Pit Filling Team. The content is based on the pit we stepped on during the interview process.