Introduction to Internet protocols (II)

Source: Internet
Author: User


The previous article analyzed the overall concept of the Internet, from bottom to bottom, and the design philosophy of each layer of protocol.
This is a question from the designer's perspective. Today I want to switch to the user's perspective to see how users interact with these protocols from top to bottom. ========================================================== ================================= Getting started with Internet protocols (2) author: Ruan Yifeng
 
(Next) 7. A summary first summarizes the previous content. We already know that network communication is the exchange of data packets. Computer A sends A packet to computer B. The latter receives the packet and replies to the packet to implement communication between the two computers. The structure of the data packet is basically as follows:
 
To send this package, you need to know two addresses:

* Recipient's MAC address * recipient's IP address
With these two addresses, data packets can be delivered to the receiver accurately. However, as mentioned earlier, the MAC address has limitations. If the two computers are not in the same subnet, they will not be able to know the MAC address of the other computer. They must be forwarded through the gateway.
 
Computer 1 sends a packet to computer 4. It first checks whether the computer No. 4 is in the same sub-network and finds that it is not (this article introduces the judgment method), so it sends this packet to Gateway. Through the routing protocol, Gateway A finds that computer 4 is located in sub-Network B and sends data packets to Gateway B. Then, Gateway B forwards data packets to computer 4. The MAC address of gateway A must be known when computer 1 sends data packets to Gateway. Therefore, the destination address of the data packet is actually divided into two situations:
Scenario Packet address
Same Subnet MAC address of the peer, IP address of the peer
Non-same subnet The MAC address of the gateway.
Before sending data packets, the computer must determine whether the peer is in the same sub-network and then select the corresponding MAC address. Next, let's look at how this process is completed in actual use. 8. You have set up a 8.1 static IP address for accessing the Internet. You have bought a new computer, plugged in the network cable, and started the system. Can the computer access the Internet at this time?
 
Usually you must make some settings. Sometimes, the Administrator (or ISP) will tell you the following four parameters. You can enter them in the operating system and the computer will be connected to the Internet: * the IP address of the Local Machine
* Subnet Mask
* IP address of the Gateway
* The IP address of DNS is in the Windows Settings window.
 
These four parameters are indispensable. Later, I will explain why you need to know them before accessing the Internet. Because they are given, the computer will be assigned the same IP address each time it starts up, so this situation is called "static IP address surfing the Internet ". However, this setting is very professional and common users are daunting. If the IP address of a computer remains unchanged, other computers cannot use this address, which is not flexible enough. For these two reasons, most users use "Dynamic IP addresses for Internet access ".
8.2 Dynamic IP addresses are called "Dynamic IP addresses". After a computer is started, it is automatically assigned to an IP address. The DHCP protocol is used. This Protocol stipulates that a computer in each sub-network is responsible for managing all the IP addresses of the network. It is called a "DHCP server ". When a new computer joins the network, it must send a "DHCP request" packet to the "DHCP server" to apply for IP addresses and related network parameters. As mentioned above, if the two computers are in the same subnet, they must know the MAC address and IP address of the other computer to send packets. However, the newly added computer does not know these two addresses. How can we send data packets? The DHCP protocol has made some clever provisions. 8.3 DHCP protocol first, it is an application layer protocol built on UDP protocol, so the entire packet is like this: (1) the first "Ethernet header ", set the MAC address of the sender (Local Machine) and the MAC address of the receiver (DHCP server. The former is the MAC address of the local Nic. If you do not know the latter, enter a broadcast address: FF-FF. (2) set the sender's IP address and the receiver's IP address. At this time, the local machine does not know the two. Therefore, the sender's IP address is set to 0.0.0.0, and the receiver's IP address is set to 255.255.255.255. (3) set the sender port and receiver port in the last "UDP Header. This part is stipulated by the DHCP protocol. The sender is port 68 and the receiver is port 67.
This packet can be sent after being constructed. Ethernet is broadcast transmission, and each computer in the same subnetwork receives the packet. Because the recipient's MAC address is a FF-FF-FF-FF-FF-FF, can not see who is sent, so each computer that receives this package, you must also analyze the IP address of this package, in order to determine whether to send to 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 is 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 a "DHCP response" packet back. The structure of the response packet is similar. The MAC address of the Ethernet header is the NIC address of both parties, and the IP address of the IP header is the IP address of the DHCP server (sender) and 255.255.255.255.255 (receiver ), the UDP header ports are 67 (sender) and 68 (receiver). The IP address assigned to the request end and the specific parameters of the network are included in the Data section.
After receiving the response packet, the newly added computer knows its IP address, subnet mask, gateway address, DNS server, and other parameters. 8.4 Internet access settings: In summary, you need to remember that, whether it is "static IP Address" or "Dynamic IP Address", the first step for computer internet access is to determine four parameters. These four values are important and worth repeating:
* Local IP Address
* Subnet Mask
* IP address of the Gateway
* Dns ip Address
With these numeric values, the computer can surf the Internet. Next, let's look at an example of how the Internet protocol works when a user accesses a webpage. 9. One instance: webpage access
9.1 The local parameters are assumed that, after the steps in the previous section, you have set your network parameters: * local IP Address: 192.168.1.100
* Subnet mask: 255.255.255.0
* Gateway IP Address: 192.168.1.1
* Dns ip Address: 8.8.8.8 then open the browser and enter www.google.com in the address bar to access Google.
 
This means that the browser will send a webpage request packet to Google. 9.2 DNS protocol we know that to send data packets, you must know the IP address of the other party. But now, we only know the website www.google.com and its IP address. The DNS protocol can help us convert this URL to an IP address. The DNS server is known to be 8.8.8.8, so we send a DNS packet (port 53) to this address ).
Then, the DNS server responds and tells us that Google's IP address is 172.194.72.105. So we know the IP address of the other party. 9.3 subnet mask next, we need to determine whether the IP address is in the same subnet, which requires the subnet mask. It is known that the subnet mask is 255.255.255.0. In this tutorial, it performs a binary AND operation on its IP address 192.168.1.100 (both digits are 1 AND the result is 1; otherwise, it is 0 ), the calculation result is 192.168.1.0, AND then an AND operation is performed on the Google IP address 172.194.72.105. The calculation result is 172.194.72.0. The two results are not equal, so the conclusion is that Google and the local machine are not in the same subnet. Therefore, to send a data packet to Google, it must be forwarded through the gateway 192.168.1.1. That is to say, the recipient's MAC address will be the gateway's MAC address. 9.4 The application layer protocol uses the HTTP protocol to browse Web pages. The entire packet structure of the web page is as follows:
GET, HTTP, 1.1
Host: www.google.com
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.1 )......
Accept: text/html, application/xhtml + xml, application/xml; q = 0.9, */*; q = 0.8
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-CN, zh; q = 0.8
Accept-Charset: GBK, UTF-8; q = 0.7, *; q = 0.3
Cookie :......
We assume that this part is 4960 bytes in length and will be embedded in TCP packets. 9.5 TCP data packets require a port. The HTTP port of the receiver (Google) is 80 by default, and the sender (local) port is a random integer between 51775 and. The header length of a TCP packet is 20 bytes, and the total length of the packet embedded with HTTP is 4980 bytes. 9.6 IP protocol, TCP data packets are then embedded into IP data packets. IP packets must be set to the IP addresses of both parties. This is known. The sender is 192.168.1.100 (Local Machine), and the receiver is 172.194.72.105 (Google ).
The Header Length of the IP data packet is 20 bytes, and the total length of the embedded TCP data packet is 5000 bytes. At the end of the 9.7 Ethernet protocol, IP data packets are embedded into Ethernet data packets. For an Ethernet packet, you must set the MAC address of both parties. the sender is the MAC address of the local Nic, and the receiver is the MAC address of the gateway 192.168.1.1 (obtained through ARP ). The maximum length of an Ethernet data packet is 1500 bytes, and the current IP data packet length is 5000 bytes. Therefore, IP data packets must be divided into four packages. Because each packet has its own IP header (20 bytes), the IP packet lengths of the four packets are 1500, 1500, 1500, and 560, respectively. 9.8 when the server responds to the forwarding through multiple gateways, Google's server 172.194.72.105 receives the four Ethernet packets. According to the serial number of the IP header, Google puts together four packets, extracts the complete TCP packet, reads the "HTTP request" in it, and then generates "HTTP Response ", send it back using the TCP protocol. After the local machine receives the HTTP response, it can display the webpage and complete a network communication.
 
This example has been simplified, but it roughly reflects the entire communication process of Internet protocols. (End)
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.