Simple working principle of IP protocol[Copy link]
IP is a connectionless protocol. It is mainly responsible for addressing between hosts and setting up routes for data packets. It does not establish a session before exchanging data. Because it does not guarantee correct delivery, on the other hand, IP does not need to receive confirmation when data is received, so it is unreliable.
There are some fields that will be attached to the data packet when the data is passed down from the transport layer. Let's take a look at these fields:
Source IP address: Use the IP address to determine the sender of the datagram.
Destination IP address: Use the IP address to determine the destination of the datagram.
Protocol: Tell the IP of the destination machine whether to pass the packet to TCP or UDP.
Checksum: A simple mathematical calculation used to verify the integrity of the received packet.
TTL survival time: Specifies how long (in seconds) a datagram can stay on the network before it is discarded. It prevents packets from endlessly circulating in the network. The router will decrement the TTL according to the time the data resides in the router. Among them, the TTL is reduced by at least one second when the datagram passes through a router.
According to the knowledge we mentioned earlier about ARP, if the target IP address is a local address, IP will directly transmit the data packet to that host; if the target address is a remote address, IP will search the local routing table for the route of the remote host (it seems like we usually dial 114). If a route is found, IP will use it to transmit the data packet. If not found, the data packet will be sent to the default gateway of the source host, also known as a router. (I have been struggling with the definitions of gateways and routers for a long time. In fact, I think it is not necessary to stick to the concepts when learning. Now there are more and more products that combine hardware and software. It is easy to distinguish them at the moment, as long as we can solve practical problems when we use them.)
In this way, when the router receives a packet, the packet is passed up to IP:
(1) Every time the data packet passes through a router, the TTL is reduced by 1. If it drops to 0, the packet will be discarded.
(2) If the packet is too large for the next network, IP will split it into several small packets.
(3) If the packet is broken up, IP creates a new header for each new packet, which includes: a flag to show that other small packets follow; a small packet ID to identify all the small packets together; and a small packet offset to tell the receiving host how to reassemble them.
(4) IP calculates a new checksum.
(5) IP obtains the destination hardware address of a route.
(6) IP forwards the packet.
At the next host, the packet is sent to TCP or UDP. This process is repeated for each router until the packet reaches its final destination. When the packet reaches its final destination, IP assembles the small packets into the original packet.