Article content overview
As introduced in the previous article
- The length of the IP address is 32 bits, often divided into 4 8 bits
- IP addresses are usually expressed in dotted decimal notation (0 255.0 255.0 255.0 255)
- A 32-bit IP address can represent a total of 4.2 billion IPs. If there is no reasonable way to allocate IPs, the entire allocation is very troublesome. Therefore, a reasonable planning and allocation of IP addresses is required
Classified IP address
Divide an IP address into two parts, namely the network number and the host number . The two parts add up to 32 bits. According to the length of the network number and host number, IP addresses can be divided into the following categories:
After being divided into three categories: A, B, and C, the 4.2 billion IP addresses can be better allocated
- The network number of class A address is 8 digits, and the first digit is 0
- The network number of the class B address is 16 digits, and the first two digits are 10
- The network number of the C address is 24 digits, and the first three digits are 110
Knowing the digits of each type of IP address network number and host number, you can calculate the smallest network number, the largest network number, and the smallest host number and the largest host number. But there are some special host numbers that need to be excluded
Special host number
- The host number is all 0 , which means the current network segment and cannot be assigned as a specific host (such as 1.0.0.0)
- The host number is all 1 , which means the broadcast address, which sends a message to all hosts in the current network segment, and cannot be assigned to a specific host (such as: 1.255.255.255)
Special network number
- Class A address network segment is all 0 (0000000) to indicate a special network, this network segment cannot be used directly
- The last 7 bits of the network segment of the class A address are all 1s (01111111) indicating the loopback address and cannot be used directly
- Class B address network segment is all 0 (10000000.0000000:128.0) is not available
- Class C address network segment is all 0 (192.0.0) is not available
After knowing the special host number and special network number, you can describe the above table more accurately
Through this, you can simply judge which type of address an IP address is
125.125.3.60 转化为2进制是 01111101 因为首位是0,所以是A类IP地址
163.70.31.23 转化为2进制是 10100011 前两位是10,所以是B类IP地址
210.36.127.11 转化为2进制是 11010010 前三位是110,所以是C类IP地址
Loopback address
127.0.0.1, usually called the local loopback address (Loopback Address), does not belong to any classified address. It represents the local virtual interface of the device, so by default it is regarded as an interface that will never go down. There is a similar definition in the Windows operating system, so you can usually ping the local loopback address before installing the network card. Generally used to check whether the local network protocol, basic data interface, etc. are normal
There are actually two classified IP addresses below, Class D and Class E, because they are generally used for special purposes, so I don’t know more about them.
Subnet
Before understanding the division of subnets, let’s look at a question: a company has 100 employees and each is equipped with a computer. Which network segment should the company apply for?
Take a look at the table of IP address classification above
It can be seen that applying for class C is the most economical IP address, because class C has up to 254 host numbers, so you should apply for class C
So at this time, suppose the company has 256 employees, each equipped with a computer, what kind of network segment should the company apply for?
At this time, it was discovered that applying for a Class C address was not enough. Therefore, at least a Class B address should be applied to meet the needs of the company. But B can have up to 2 to the 16th power minus 2 host numbers, and only 256 are used here, which causes a lot of waste of address space . Because there are a total of 4.2 billion IP addresses, if every company wastes this way, then IP will not be enough. Therefore, on the basis of IP classification, the concept of subnet division is proposed
As mentioned earlier, an IP consists of two parts: network number and host number. In the subnet division, an IP will be divided into three parts, namely network number, subnet number, and host number
How does the subnet number work
Assume that in the above example, a class C address of 193.10.10.0 is assigned, and there are 254 host numbers for this class C address. If subnetting this class C address, the 25th bit can be regarded as the subnet number (11000001.00001010.00001010. 0 0000000), then it can be divided into two subnet numbers, 1 and 0. Then the subnet number 0 can represent: the network segment 193.10.10.0 ~ 193.10.10.127. 1 This subnet can represent: 193.10.10.128 ~ 193.10.10.255 this network segment, so that the original Class C address is divided into two subnets
If the addresses of class A, B, and C are divided into many subnets, there will be a lot of subnets. How to quickly determine which network number a certain IP belongs to? At this time, a new concept was proposed: subnet mask
Subnet mask
- The subnet mask is the same as the IP address, both are 32 bits
- The subnet mask is composed of consecutive 0s and consecutive 1s
- The subnet mask of a certain subnet, with consecutive 1
For example, for a class A address, its network number has 8 bits and the host number has 24 bits. For a class A address, its subnet mask is composed of 8 1s and 24 0s, which is 255.0.0.0 . Similarly, the subnet mask of a class B address is composed of 16 1s and 16 0s, which is 255.255.0.0
The above class C address is divided into subnets and divided into two subnets of 0 and 1. Then for this subnet, its subnet mask is composed of 25 1s and 7 0s, then The dotted decimal system of this subnet mask is 255.255.255.128
How does the subnet mask make a quick subnet judgment
Assuming that there is an IP of 193.10.10.6, you can first know that its subnet mask is 255.255.255.128, and then express their binary values, and perform an AND operation on each of them, and you will get the following result
As you can see, the calculated result is 193.10.10.0, which is the subnet number of the IP
Assume that there is an IP of 193.10.10.129, and its subnet mask is 255.255.255.128, and then all of them are expressed in binary, and each bit of them is ANDed, and the following result will be obtained
As you can see, the calculated result is 193.10.10.128, which is the subnet number of the IP
Therefore, by ANDing the subnet mask and IP, you can quickly get the subnet number to which the IP belongs
Unclassified addressing CIDR
Since the division of subnets is still relatively complicated, you must first know the network number, and then divide the subnet number. We hope to have a better and simpler division to use IP addresses, so we propose CIDR without classification
- There is no concept of A, B, C network numbers and subnet division in CIDR
- CIDR refers to IP addresses with the same network prefix as a " CIDR address block "
Therefore, for CIDR, its IP address is divided into two parts: network prefix and host number . The network prefix is not the same as the previous network number. The biggest difference is that the number of digits in the network prefix is arbitrary
Slash notation
When CIDR records, it usually uses slash notation to record related IP addresses, such as:
192.10.10.129/25 means that its network prefix has 25 digits, then the host number is seven digits ( 11000001.00001010.00001010.1 0000001). In addition to 25, there are many
Or the top example: a company has 100 employees, each equipped with a computer, which network segment should the company apply for?
If you use the CIDR notation for distribution, you only need to assign it an IP network number with a network prefix of 25 (/25)
Suppose the company adds 100 employees and splits it into two departments. How to plan IP at this time?
At this time, you can actually assign them a 24-bit IP address with a network prefix, and then assign a 25-bit IP address with a network prefix to each department. Here is the concept of a small network and a large network. In CIDR, a small network is usually called a subnet . For a network prefix of 24 bits, it is called a supernet in CIRDR.
If you expand this example, expand it to a certain city. If you use CIDR for network planning for a city, you may assign a network address with a network prefix of 18 to the city, and assign a network address with a network prefix of 20 to companies in the city. For a company department, assign a network prefix of 24. website address
It is the core competitiveness of a technical person to find the constant in the rapidly changing technology. Unity of knowledge and action, combining theory with practice