The Internet Protocol (IP) is used for Internet communication. The IP protocol is used to connect multiple packet-switched networks, transport datagrams between original and destination addresses, and reassemble data sizes to suit different network requirements.

IP is the core protocol of the TCP/IP family. The version number of the most commonly used IP protocol is 4, that is, IPV4. Its next version is IPV6.

2. Format of IP packets

(1) Version contains four characters, indicating the IP protocol version. The IP protocol version used by the communication parties must be the same. The widely used IP protocol version is 4 (IPv4). Regarding IPv6, it is still in the draft stage.

(2) The header length is 4 bits, and the largest decimal value that can be represented is 15. Note that the number represented in this field is in 32-bit word length (a 32-bit word is 4 bytes), so when the head of an IP is 1111 (15 in decimal), the head is 60 bytes. When the header length of an IP packet is not a multiple of 4 bytes, it must be filled with the last fill field. Therefore, the data part always starts at an integer multiple of 4 bytes, which is convenient when implementing IP protocol. The disadvantage of limiting the header length to 60 bytes is that it may sometimes be insufficient. But this is done in the hope that users will minimize overhead. The most common header length is 20 bytes (that is, 0101), with no options.

(3) The distinction service occupies 8 bits, which is used to get better service. This field was called service type in the old standard, but has never actually been used. In 1998, IETF changed the name of this field to DS(Differentiated Services). This field is only useful if the discriminating service is used.

(4) Total Length The total length refers to the length of the header and the sum of the data, in bytes. The total length field is 16 bits, so the maximum length of a datagram is 216-1=65535 bytes. Each data link layer below the IP layer has its own frame format, including the Maximum length of the data field in the frame format, which is called the Maximum Transfer Unit (MTU). When a datagram is encapsulated as a link layer frame, the total length of the datagram (including the data header) must not exceed the MTU value of the following data link layer.

(5) Identification occupies 16 bits. The IP software maintains a counter in memory that increments by 1 each time a datagram is generated and assigns this value to the identification field. But this “identifier” is not a serial number, because IP is a connectionless service and datagrams are not received in order. When a datagram must be fragmented because its length exceeds the MTU of the network, the value of this identity field is copied to the identity field of all datagrams. The same value of the identity field enables the fragmented datagrams to be correctly reassembled into the original datagrams.

(6) Flag occupies 3 bits, but only 2 bits are meaningful at present. ● The lowest value in the flag field is More Fragment (MF). MF=1 means the datagram followed by “sharding”. MF=0 indicates that this is the last of several datagrams. The bit in the middle of the field is marked as DF(Don’t Fragment), meaning “cannot Fragment”. Sharding is allowed only when DF=0.

(7) slice offset accounted for 13 bits. Slice offset indicates the relative position of a slice in the original group after a longer slice is sharded. That is, where the film starts relative to the starting point of the user data field. The offset unit is 8 bytes. That is, the length of each shard must be a multiple of 8 bytes (64 bits).

(8) The TTL occupies 8 bits. The commonly used abbreviation of the TTL field is TTL(Time To Live), indicating the life of a datagram in the network. This field is set by the source point that sent the datagram. The goal is to prevent undeliverable datagrams from traveling around the Internet indefinitely and thus consuming network resources for nothing. The original design used seconds as the unit of TTL. Each time you pass through a router, subtract the TTL from the amount of time the datagram spent at the router. If the datagram spent less than one second on the router, reduce the TTL value by one. When the TTL value is 0, the datagram is discarded.

(9) The protocol occupies 8 bits. The protocol field indicates which protocol is used for the data carried by the datagram, so that the IP layer of the destination host knows which processing process to hand over the data part.

(10) the head check sum occupies 16 bits. After receiving an IP packet, the sum of each 16 bits in the header is also performed. If there is no error during transmission, the calculation results should be all ones. If not all ones, that is, check and error, the received datagram is discarded, but no error message is generated. The upper layer finds the lost datagram and retransmits it. This field verifies only the header of the datagram, but does not include the data portion. This is because each time the datagram passes through a router, the router recalculates the header checksum (some fields, such as lifetime, flags, slice offsets, etc., can change). Not checking the data portion reduces the computational effort.

3. IP Address An IP address identifies the location of a system on a network. Each IP address consists of two parts: the network number and the host number. Network ID Identifies a physical network. All hosts on the same network must have the same network ID. The ID is unique on the entire Internet. The host number is a TCP/IP host on the network. The host number is unique to a network number. Each TCP/IP host is identified by a logical IP address.

The IP address can be expressed in binary or dotted decimal notation. Each IP address is four bytes and consists of four 8-bit fields, called 8-bit bodies.

IP address has gone through three historical stages. The three stages are:

IP address of the class. The most basic addressing method.

Subnets. Improvements to the most basic addressing methods.

Construct a supernet. Relatively new classification – free addressing methods.

1>. Type A IP address (0.0.0.0 to 127.255.255.255) starts with “0”. The length of the network segment is 8 bits, and the length of the variable part is 7 bits. The host segment contains 24 bits. The 7-bit variable network segment recognizes 2^7=128 (0~127) networks, of which 0 and 127 are otherwise used, so only 126 class A network addresses are available. In addition, the host bit all “0” represents the network itself, and all “1” represents the network broadcast, so A class A network address can recognize 2^24-2 assignable addresses.

Type B addresses (128.0.0.0 to 191.255.255.255) start with 10. The length of the network segment is 16 bits, and the length of the variable part is 14 bits. The host segment contains 16 bits. A 14-bit variable network segment can recognize 2^14 networks. In addition, host bits all “0” and all “1” function as class A addresses, so A class B network can allocate 2^16-2 addresses.

3>. Class C IP addresses (192.0.0.0 to 223.255.255.255) start with 110. The length of the network segment is 24 bits, and the length of the variable part is 21 bits. The host segment contains 8 bits. A 21-bit variable network segment can recognize 2^21 networks. The number of host addresses that can be allocated is 2^8-2.

4>. Class D addresses (224.0.0.0 to 239.255.255.255) are multicast addresses, starting with 1110. There are 2^28 multicast addresses regardless of network segment or host segment. Used to identify a predefined set of hosts. When a host uses multicast communication, it can send multicast datagrams to all hosts in the same group at one time.

5>. E address (240.0.0.0-255.255.255.255) is reserved for research use. The address starts with 1111 and does not distinguish between network segments and host segments. All the 32-bit ones represent the broadcast within the network. Therefore, there are 2^28-1 class E addresses.

Private IP address and special IP address

According to the purpose and security level, IP addresses can be roughly divided into two types: public and private. Public addresses are used on the Internet and can be accessed at will.

To connect to the Internet, an organization network must apply for a public IP address. However, considering special situations such as network security and internal experiments, three zones are reserved as private addresses in the IP address, and their address ranges are as follows:

Class A: 10.0.0.0/8 (subnet mask) 10.0.0.0-10.255.255.255 Class B: 172.16.0.0/12 172.16.0.0-172.31.255.255 Class C: 10.0.0.0/8 (subnet mask) 10.0.0.0-10.255.255.255 192.168.0.0/16 192.168.0.0-192.168.255.255

Networks using reserved addresses can only communicate internally and cannot interconnect with other networks. Because the reserved address in the local network may also be used by other networks, if the network interconnection is carried out, there will be problems when searching for routes because the address is not unique. However, these networks that use reserved addresses can connect to external networks by translating the reserved addresses into public addresses. This is also an important way to ensure network security.

Note: 127 (01111111) is reserved for local software loopback test for communication between local processes. If a host sends an IP packet whose destination address is a loopback address (for example, 127.0.0.1), the protocol software on the host processes the data in the packet and does not send the packet to any network. An IP datagram whose destination address is a loopback address will never appear on any network, because address 127 is not a network address at all.

The network ID is 0. If the host uses BOOTP to determine the local IP address, the IP address can only be used as the source IP address during initialization.

4. Subnets 1. Meaning of subnets

Organize the use of different physical media, storage of address space, control of network traffic, and security factors.

2. Subnet mask

RFC950 defines the use of subnet masks. The subnet mask is a 32-bit binary number. The bits corresponding to the network address are all 1’s and the bits corresponding to the host location are all 0’s.

The default subnet mask of A class A network is 255.0.0.0, that of A class B network is 255.255.0.0, and that of A class C network is 255.255.255.0

The subnet mask tells the router which part of the address is the network address and which part is the host address. The router correctly determines whether any IP address belongs to the local network segment and routes the IP address correctly.

3. Subnets

Class A addresses 0.0.0.0 to 127.255.255.255 Class B addresses 128.0.0.0 to 191.255.255.255 Class C addresses 192.0.0.0 to 223.255.255.255

Class A private address 10.0.0.0 to 10.255.255.255 Class B Private address 172.16.0.0 to 172.31.255.255 Class C private address 192.168.0.0 to 192.168.255.255

CIDR (Classless Inter-domain Routing). CIDR’s greatest feature is the use of a slash (/) to indicate a subnet mask, which indicates how many bits of 1 there are in the subnet mask. We often see this representation in the IP addresses that carriers give me, and we often need to figure out what IP addresses are available to us based on this representation.

If telecom gives us the address 61.168.1.32/28, what are the available IP addresses? We’re not going to answer that, but we’ll come back to that when we get into subnets.

For A Class A network, the default subnet mask is 255.0.0.0 and /8 in CIDR mode. For A Class B network, the default subnet mask is 255.255.0.0.0 and /16 in CIDR mode. For A Class C network, the default subnet mask is 255.255.255.0 and /24 in CIDR mode

So if you look at this, you know, PI over 8 means 8 bit 1, which is 1 byte, PI over 16 means 16 bit 1, which is 2 bytes, and PI over 24 means 24 bit 1, which is 3 bytes, and you remember this default rule, and it’s an important trick for you to learn about subnets and to do subnets in your head. For example, how much is a subnet mask 255.255.255.128 in CIDR? First of all, this is a class C network address, the front three bytes is 255, converted into a binary 1, namely 11111111.11111111.11111111, namely 24 to 1. 128 is converted to binary bit 10000000, that is, 1 occupies one bit. Because the subnet mask occupies 25 ones, it is represented by /25 (/25) using CIDR, that is, 255.255.255.128 (/25). If the IP segment is 192.168.1.0, it is represented by CIDR as 192.168.1.0/25.

Again, for example, 192.168.1.0, 255.255.255.192, with CIDR said? Firstly, it is judged that it is a class C network, which occupies 3 bytes (24 bits) 1,192 when converted into binary bits 11,000,000, occupying 2 bits of 1, and a total of 26 bits of 1. So CIDR is represented as 192.168.1.0/26.

The main points of subnets: 1, how many networks (subnets) need to be divided into? If you want to divide 4 networks, 2X=4, X=2, if you want to divide 8 networks, 2X=8, X=3, now you know why you have to figure out a power of 2, X is a power of 2. So what does X stand for? X is the number of bits 1, such as 11000000, which means borrowing 2 bits, that is, X=2. If a byte (8 bits) is 11000000, it means that four networks can be divided (22=4). If the value is 11110000, it means that four bits are borrowed and 16 networks can be divided (24=16).

2. How many IP addresses does each network need? The calculation formula is as follows: 2^y-2, where y represents the number of zeros. For example, 11111000 represents the number of zeros, that is, y=3. 2^3=8-2=6, that is, the number of available IP addresses for each network is 6. If each network requires the IP of 60 hosts, how do you calculate it? So 2 to the y is greater than or equal to 60, so 2 to the sixth is 64 minus 2 is 62, so all y values are 6.

3. What subnets (block size) are there? Calculation formula: 256- Subnet mask. If the subnet mask is 255.255.255.192, the block size is 256 to 192=64, that is, the block size is 64. The value increases from 0 to 64 until the subnet mask is reached. The intermediate result is the subnet. In this example, the subnet is 0, 64, 128, and 192. For example, if the subnet mask is 255.255.255.128, the block size is 256-128=128, that is, the block size is 128, and the subnet is 0 and 128.

4. What is the subnet NUMBER and broadcast address of each subnet? The subnet id is a simple value, that is, the subnet block value. For example, if the mask is 192, the subnet block value is 256-192=64, and the subnet id is 0, 64, 128, and 192. If the mask is 128, the subnet is 128, and the subnet must be 0 or 128. The broadcast address is also very simple, always the number before the next subnet. For example, if the subnet ID is 0, 64, 128, or 192, the broadcast addresses are 63, 127, or 191. If the subnet number is 0, 128, then the broadcast address is 127. This is because each subnet number (which is also an IP address) and broadcast address cannot be assigned to the host.

5. What are the available (legal) host addresses for each subnet? For example, if the subnet id is 0, 64, 128, or 192, the available host addresses are 1-62, 65-126, and 129-190. 0 is a subnet address, 63 is a broadcast address, and 128 and 192 are subnet addresses. 127 and 191 are broadcast addresses.

6, class C network subnet division, for example, 192.168.10.0, 255.255.255.224 1, how many subnets can be divided into? According to the previous knowledge, the first 224 is converted into binary, 11100000. 1 occupies 3 bits, so 2^3=8, can be divided into 8 subnets. 2. How many IP addresses are available for each subnet? 2^5-2=30. The number of available IP addresses is 30. 256-224=32, that is, the base of 32 keeps increasing until 224, that is, 0, 32, 64, 96, 128, 160, 192, 224. 192.168.10.0, 192.168.10.32, 192.168.10.64, 192.168.10.96, 192.168.10.128, 192.168.10.160, 192.168.10.192, 192.168.10.224. 4. What is the broadcast address of each subnet? The broadcast address of each subnet network is always the number before the next subnet, namely, 31, 63, 95, 127, 159, 191, 223. 192.168.10.31, 192.168.10.63, 192.168.10.95, 192.168.10.127, 192.168.10.159, 192.168.10.191, 192.168.10.223. 5. What are the available addresses for each subnet? Subtracting the subnet address and broadcast address for each subnet leaves the available address. In this example, the available addresses are 1-30, 33-62, 65-94, 129-158, 161-190, and 193-222.

1. How many subnets can be divided into? Since CIDR represents a subnet mask, we first have to figure out how many bits of 1 are used, i.e. 30-24 (since it is a Class C network, the first three bytes are 255, i.e. 8 bits of 1, total 24 bits of 1) =6, i.e. 6 bits of 1. So 2 to the sixth is 64, 64 subnets. 2. How many IP addresses are available for each subnet? Because there are 6 bits of 1 and 2 bits of 0, we get 22 minus 2=2, so there are 2 available IP addresses. 3. What are the subnet networks? Because there are 6 bits of 1, 21+22+23+24+25+26=252, that is, 256=252=4, the block size is 4, and the subnet network is 0, 4, 8, 12, 16… 192.168.10.0, 192.168.10.4, 192.168.10.8…… 4. What is the broadcast address of each subnet network? Number before the next subnet: 192.168.10.3, 192.168.10.7, 192.168.10.11… 192.168.10.247, 192.168.10.251, did you calculate correctly? 5. What are the available addresses for each subnet? Excluding the subnet address and broadcast address, the available address is 1,2, 5,6… , 249250. For class A, CLASS B, and Class C networks, each subnet contains only two host addresses when the subnet mask /30 is used. This subnet mask is only suitable for point-to-point links.

7, Class B network subnet division From the previous knowledge, we know that in class B address, there are 16 bits of host address available, which means that we can use 14 of them for subnet division, because at least 2 bits should be reserved for host addressing. For example, 172.17.0.0 255.255.128.0 1. How many subnets can be divided into? Firstly, 128 is converted into binary bit 10000000. Since this example belongs to class B network, at least 16-bit mask bit (16-bit 1) needs to be reserved, so x=1 here, and 21=2 is obtained. The answer is two subnets. 2. How many IP addresses are available for each subnet? Here 0 bits account for 15 bits in total, 215-2=32766. 172.17.0.0, 172.17.128.0 4. What is the broadcast address of each subnet network? 172.17.127.255, 172.17.255.255. 5. What are the available IP addresses for each subnet? Subnet 0.0 The first available IP address is 172.17.0.1 and the last available IP address is 172.17.127.254. On subnet 128.0, the first available IP address is 172.17.128.1 and the last available IP address is 172.17.255.254.

172.17.0.0/20 1. How many subnets can be divided into? Because this example belongs to class B network, at least 16 mask bits (16 bits 1) need to be reserved, so x=4 here, 24=16. The answer is 16 subnets. 2. How many IP addresses are available for each subnet? Here, 1 bit takes up 4 bits, so 0 bits take up 12 bits in total, 212-2=4094. Because we have 4 bits in 1 place, we get 24+25+26+27=240. 256-240=16, i.e. 0.0, 16.0…… 172.17.0.0, 172.17.16.0…… And 172.17.240.0. 4. What is the broadcast address of each subnet? Number before the next subnet, 172.17.15.255,…… 172.17.223.255. What are the available IP addresses for each subnet? Subnet 0.0 The first available IP address is 172.17.0.1, and the last available IP address is 172.17.15.254. … . Figure out how many subnets 172.16.0.0/24 can be divided into. What is the number of available addresses per subnet? The correct answer we can search QQ authentication network engineer into the group discussion.

Class A subnets are similar to class B and C subnets.

If the above still do not understand it does not matter: there are more detailed examples of god:

How to divide subnets superclassical analysis