Introduction to Internet protocols (II)

Source: Internet
Author: User

(Link)

  VII. A summary

First, make a summary of 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:

MAC address of the recipient

IP address of the other party

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 The MAC address of the other party and the IP address of the other party.
Non-same subnet MAC address of the gateway, IP address of the other party

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. User's Internet access settings

  8. 1 static IP Address

You bought a new computer, plugged in the network cable, and started the computer. 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 into the operating system and the computer will be connected to the Internet:

Local IP Address

Subnet Mask

IP address of the Gateway

Dns ip Address

Is 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 address for Internet access ".

  8. 2. Dynamic IP Address

The so-called "Dynamic IP Address" means that an IP address is automatically assigned to the computer after it is started. The DHCP protocol is used.

This Protocol stipulates that a computer in each sub-network is responsible for managing all 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, so the entire packet is like this:

(1) 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 received this package, you must also analyze the IP address of this package, in order to determine whether to send your own mail. 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 has been sent to me", and other computers can discard this packet.

Next, the DHCP server reads the data of the packet, allocates the 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 NIC address of both parties, and the IP address of the IP header is the IP address of the DHCP server (issuer) and ipv0000255 (receiver), UDP header ports are 67 (sender) and 68 (receiver), and the IP address assigned to the request end and 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: Summary

In this section, you need to remember that, whether it is "static IP Address" or "Dynamic IP Address", the first step for accessing the computer 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 Local Parameters

We assume 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

IP address of the Gateway: 192.168.1.1

Dns ip Address: 8.8.8.8

Then he opened his browser and entered the URL 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, we must know the IP address of the other party. But now, we only know the website www.google.com, and do not know 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 subnetwork. This requires a 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 (the two digits are the same 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 Google's 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.

  Application Layer Protocol

The Web browser uses the HTTP protocol, and its entire packet structure is as follows:

The HTTP content is similar to the following:

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 protocol

TCP data packets must be configured with a port. The http port of the receiver (Google) is 80 by default, and the sender (local) port is a random integer between 1024-65535, which is assumed to be 51775.

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

Then, the TCP packet is embedded into the IP packet. 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.

  9. 7 Ethernet protocol

Finally, 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.

  Server Response

After forwarding by multiple gateways, Google 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.

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.