Transfer http://blog.csdn.net/goodboy1881/article/details/668556
------------------------------------------------------
Put the three Protocols together for learning because these three protocols are on the same layer. ARP is used to find the MAC address of the Ethernet NIC of the target host, and the IP address carries the message to be sent. The data link layer can get the data transmission information from ARP, and get the data information to be transmitted from the IP address.
1. IP protocol
The IP protocol is the core of the TCP/IP protocol. All TCP, UDP, imcp, and IGCP data are transmitted in the IP data format. Note that the IP address is not a reliable protocol, the IP protocol does not provide a processing mechanism after the data is not transmitted-this is considered an upper-layer protocol-TCP or UDP to do. Therefore, TCP is a reliable protocol, and UDP is not that reliable. This is not a reference.
1.1.ip protocol header
One by one, it is a textbook practice. I am only interested in the eight-bit TTL field. Do you still remember what this field is? This field specifies the number of routes that the packet passes through before it is discarded (this shows the reliability of the IP protocol package, which does not guarantee that the data is delivered ), each time an IP packet passes through a vro, the TTL value of the packet is reduced by 1. When the TTL of the packet becomes zero, it is automatically discarded. The maximum value of this field is 255. That is to say, a protocol package will be discarded when it passes through the vro for 255 times. The number varies depending on the system, generally, it is 32 or 64. tracerouter works in this way. The tranceroute-M option requires a maximum value of 255, because the TTL only has 8 bits in the IP protocol.
The current IP version number is 4, which is also called IPv4. IPv6 is also available, and it is widely used.
1.2.ip Route Selection
When an IP packet is ready, how does the IP packet (or router) Send the packet to the destination? How does it select a proper path for "Shipping?
The most special case is direct connection between the target host and the host, so the host does not need to look for a route, so it is enough to directly pass the data. As for how to directly transfer it, it depends on the ARP protocol, which will be discussed later.
Generally, the host is connected to the target host through several routers. Then, the router needs to find a suitable destination for the IP packet through the IP packet information, such as a suitable host or a suitable route. The router or host will process an IP packet in the following way:
- If the TTL (lifecycle) of an IP packet reaches, the IP packet is discarded.
- Search the route table and search for matched hosts first. If the target host is exactly the same as the IP address, send the packet to the target host.
- Search the route table. If a host fails to match, the router in the same subnet is matched. This requires assistance from the "subnet mask (1.3. If a vro is found, the package is sent to the vro.
- Search for the route table. If a vro fails to match the same subnet, The vro matches the same network number (described in Chapter 1). If a vro is found, the package is sent to the vro.
- Search for the Land game table. If none of the preceding operations fail, search for the default route. If the default route exists, send the packet
- If all of them fail, discard the package.
This once again proves that the IP package is unreliable. Because it does not guarantee delivery.
1. 3. subnet addressing
The IP address is defined as the network number + host number. However, all hosts require subnet addressing. That is to say, the host number is subdivided into subnet number + host number. In the end, an IP address becomes the network number + subnet number + host number. For example, a Class B address: 210.30.109.134. Generally, the red part of the IP address is the network number, the blue part is the subnet number, and the green part is the host number. There is no hard rule about how many digits represent the subnet number. InsteadSubnet Mask, Campus network I believe most people have used it. There is something in the settings of campus network that contains 255.255.255.0, which is the subnet mask. The subnet mask is a string of 32-bit binary numbers in the form of 1 and 0, for example, 255.255.255.0 (binary is 11111111.11111111.11111111.00000000) for the Class B address, because 210.30 is the network number, the next 109.134 is the combination of the subnet number and host number, and because the subnet mask is only the last eight bits is 0, therefore, the host number is the last eight bits of the IP address, that is, 134, and the remaining is the subnet number-109.
2. ARP Protocol
Do you still remember that in the Ethernet protocol of the data link layer, each packet has a MAC address header? We know that each Ethernet card has a MAC address, which is unique. How does the IP package know the MAC address? This is the work of ARP.
ARP (Address Resolution) is a resolution protocol. The host has no idea which interface the IP address corresponds to. When the host wants to send an IP packet, will first check their ARP high-speed cache (is a IP-MAC address corresponding to the table cache), if the queried IP-MAC value does not exist, then the host sends an ARP Protocol broadcast packet to the network, the IP address to be queried in the broadcast package. All Hosts that directly receive the broadcast package will query their own IP addresses. If a host that receives the broadcast package finds that it meets the conditions, prepare an ARP packet containing your MAC address and send it to the host that sends the ARP broadcast, the broadcast host will update its ARP cache after obtaining the ARP package (that is, the place where the corresponding table of the IP-MAC is stored ). The host that sends the broadcast prepares the data packet sending at the data link layer with the new ARP cache data.
A typical ARP cache information is as follows:ARP-"Command:
Interface: 192.168.11.3 --- 0x2
Internet address physical address type
192.168.11.1 00-0d-0b-43-a0-2f dynamic
192.168.11.2 00-01-4a-03-5b-ea dynamic
This is the result.
Such a high-speed cache has a time limit, generally 20 minutes (the derivative System of the Berkeley system ).
3. RARP protocol (omitted)
TCP/IP Study Notes (3)-IP protocol, ARP protocol, RARP Protocol