TCP/IP Protocol-IP protocol

Source: Internet
Author: User
Tags rfc

A contented mind is a perpetual feast.

"Contentment Changle"

reference : TCP/IP Primer Classic (fifth edition)

TCP/IP Detailed Volume One: protocol

First, Introduction

  IP protocol (Internet Protocol, Internetwork Protocol) is the most core protocol in the TCP/IP protocol family, and is located in the Network layer of the protocol stack.

Since it is located in the network layer, so the main function of IP protocol is to provide hardware-independent logical addressing and support the routing of data transmission between the network , we will introduce these two functions in the following section, the first to analyze the IP header

Second, IP header

We said in the TCP/IP protocol-Getting started: When the TCP fragment or UDP datagram of the transport layer is delivered to the network layer, the IP protocol will encapsulate the IP header on the segment or datagram, then we analyze the IP header, the IP datagram format is as follows

The meanings of each of these fields are as follows:

4-bit version: The current protocol version number is 4, which is IPV4

4-Bit header length: We note that the length of each row is a number of 4 bytes, and the header length refers to the amount of the first digit, the number of rows. Because the header length is only 4 bits, the maximum length of the IP header is (24-1) *4=60 bytes

8-bit service type (TOS): Includes a 3 bit priority sub-field (now ignored), 4 bit TOS subfield and 1 bit unused bit but must be set to 0. The 4 bit TOS represents: Minimum delay, maximum throughput, maximum reliability and minimum cost, only 1 bit in 4 bit, if 4 bit is 0, it means General Service

16-bit total length: Total length refers to the number of bytes in the entire IP datagram, with the total length-the first ministerial degree, we can know the length of the data section, this field occupies a bit, so the maximum IP datagram length is 216-1 = 65535 bytes. Although the maximum length can reach 65535, it is generally not as large as the MTU limit of the link layer

16-bit ID: the identity field uniquely identifies each datagram sent by the host. The 16-bit identification, 3-bit flag, and 13-bit offset are discussed in detail when discussing sharding and reassembly

8-bit time-to-Live (TTL): The TTL sets the maximum number of routers that datagrams can pass, and it specifies the lifetime of the datagram. Its initial value is set by the source host, each through a router that handles it, its value is reduced by 1, when the field is 0 o'clock, the datagram is discarded, and send an ICMP message to notify the source host

8-bit protocol: The Protocol field is also known as the Protocol domain, which is used to mark which protocol the data is from the upper layer: 1 for the ICMP protocol, 2 for the IGMP protocol, 6 for the TCP protocol, and 17 for the UDP protocol

16-bit first Test and: The Test and field is the test and code calculated according to the IP header, calculated by setting the field to 0, and then to the header (excluding the data portion) each of each of the three-bit inverse code summation, and finally the result exists in the field. When the receiver receives the IP datagram, it also deserializes each of the first bits of the header, this time because it contains the previously computed test and, so if nothing goes wrong, the receiver calculates the result to be 1. If not for full 1,ip will discard the received datagram, but do not generate error messages, from the upper layer to find and process

The source IP address and destination IP address are more intuitive

Options: This field is a variable-length optional information in the datagram, and since these options are rarely used, not all hosts are supported, so there is no more detailed introduction, so refer to the relevant RFC documentation

By the above, the length of the IP header is fixed 20 bytes When the selected item does not exist

  

Third, logical addressing

Let's talk about the main functions of the IP protocol, first of all the logical addressing, in the TCP/IP protocol-Getting started we have introduced some of the relevant concepts, let's review

IP Address: The IP protocol identifies the identity of the device in the network, with a length of

Subnet mask: Similar to IP address, used to identify network number (including subnet number) and host number

Knowing the IP address and subnet mask, we can discuss subnetting

  

Sub-Network Division

Since network systems are interconnected by countless network devices through transmission media, all devices in the network are in the same set. When the data from one host to another host, if the two hosts are not directly connected, need to go through the intermediary device, when the network of equipment is too large, transmission efficiency will be greatly reduced. If the whole network system is divided into many subnets, the efficiency of transmission can be increased by distinguishing different subnets. The idea of subnetting is that the network system is divided into many large networks, each large network contains many subnets, and each subnet contains many hosts

The IP protocol identifies the network number, the subnet number, and the host number by dividing the IP address into different parts. In the previous article we have discussed five types of IP addresses (not given the subnet number section), assuming that the local subnet uses the Class B address, the subnet number length is 10 bits, the subnet mask of the local subnet will be like this

Assume that the IP address of this machine is 255.255.255.195, i.e.

We found that the first 26 bits of two addresses are the same, that is, the network number and subnet number portion of any host's IP address is the same as the subnet mask of the subnet on which it resides. In this way, we can use the subnet mask to know whether an IP address is a subnet, and then through the host number to distinguish each host within the subnet .

  

 CIDR: Type-free inter-domain routing

The IP address is represented by 32 bits, so the number of IP addresses is limited, with a maximum of 232-1 IP addresses, and many of them are not available. When the number of devices in the network reaches a certain amount, the IP address will not be enough! One solution is to use more bits to represent an IP address, such as a 128 bit, which is IPv6, which is not discussed here. Another way is to use the same IP address to represent different hosts depending on the length of the network number, which is classless inter-domain routing .

We talked about an IP address that uniquely identifies a single device in the network, and the idea of CIDR is to identify multiple hosts with an IP address. The idea is to use a slash (/) as a delimiter, followed by a decimal value at the IP address to represent the number of digits in the address in the network number. For example: In CIDR address 205.123.196.183/25, the first 25 bits are the network number (including the subnet number), and the next 7 bits are the host number, which enables the reuse of IP addresses

 Special IP Address

As mentioned earlier, there are some IP addresses are not available, specifically what? See the table below

Note: 0 indicates that all bits are 0;-1, indicating that all bits are 1;netid, SubnetID, and HostID respectively, representing a field that is not full 0 or all 1. The subnet number column is empty to indicate that the address is not subnetting

The table is divided into three parts: the first two are special source addresses, the middle is a special loopback address, and the last four are broadcast addresses

Iv. Routing Options

Let's start by understanding a few concepts.

 Router (Router)

the front has been talking about routers, in the end what is a router? Routers are the devices responsible for filtering traffic based on logical addresses, " also known as Gateway Devices (gateways) are used to connect a number of logically separate networks "--Baidu encyclopedia. Simply put, a router is a tool for directing IP packets, telling the datagram where the next station should go

Routing tables (routing table)

A routing table is a table that stores a path to a specific network address, which holds the topology information around the network perimeter.

When the router is working, if the datagram is sent to any router or a specific router each time it is forwarded, the efficiency of the transfer will be very low, because each send is rerouted (as you go to a place where you never remember the route, you have to ask for directions every time you go to that place). If you can record the destination address of this transmission after each transmission, then the next time you need to send to this address, I can find a shortest route according to the recorded information to send it, rather than through the other road origin forwarding (is to remember the route to this place, next time you can go directly to the past), A routing table is a way to store information about these transport paths.

Each item in the routing table contains the following information:

Destination IP address . It can be either a full host address or a network address, specified by the flag field

The IP address of the next-station router, or a network IP address that is directly connected . The next station router is a router on a directly connected network that can forward datagrams. It is not the final destination, but it can forward datagrams to the final destination

flag . One of the flags indicates whether the destination IP address is a network address or a host address, and another flag indicates if the next station router is a real next-station router or a directly connected interface

Specify a network interface for the transmission of datagrams

  

Route selection

For the host, routing is a simple thing, if the destination host directly connected to the source host, then the direct send can be, if not directly connected, then just send to the default route, so that the router to forward the line.

For routers, you need to complete more functions, as follows:

① searches the routing table for a table that exactly matches the destination IP address (both the network number and the host number match). If found, send the message to the next station router or directly connected network interface specified in the table

② searches the routing table for a table that matches the destination network number. If found, the message is sent to the next station router or directly connected network interface specified in the table. All hosts on the destination network can be disposed of through this table.

③ If none of the above two steps are found, look for the table labeled Default. If found, send the message to the next station router specified in the table

If none of the above three steps are successful, then the datagram cannot be sent.

This loops until the destination is reached or the TTL is reduced to 0.

V. View information about interfaces and networks

View Native network interface information (including physical address, IP address, subnet mask, MTU, etc.): $ ifconfig

View routing Table information: $ route

or $ netstat-rn

Note : This article is only a general introduction to the IP protocol, more details of the problem is not involved, such as when the datagram sent failed to deal with, and so on. For more details, please refer to the RFC documentation or other information

TCP/IP Protocol-IP protocol

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.